import { chalk } from '@tarojs/helper' ; import { modifyMiniWebpackChain } from './webpack.mini' ; import { modifyH5WebpackChain } from './webpack.h5' ; import type { IPluginContext } from '@tarojs/service' ; export interface IConfig { mini ? : { compilerOptions : { isCustomElement : ( tag : string ) => boolean ; whitespace : 'condense' | 'preserve' ; delimiters : string [ ] ; comments : boolean ; nodeTransforms : ( ( ... args : any ) => void ) [ ] ; } ; } ; } export default ( ctx , config = { } ) => { const { framework } = ctx . initialConfig ; if ( framework !== 'vue3' ) return ; ctx . modifyWebpackChain ( ( { chain , webpack , data } ) => { setDefinePlugin ( chain , webpack ) ; if ( process . env . TARO_ENV === 'h5' ) { modifyH5WebpackChain ( ctx , chain ) ; } else { modifyMiniWebpackChain ( ctx , chain , data , config . mini ) ; } } ) ; } ; function setDefinePlugin ( chain , webpack ) { chain . plugin ( 'defined' ) . use ( webpack . DefinePlugin , [ { __VUE_OPTIONS_API__ : JSON . stringify ( true ) , __VUE_PROD_DEVTOOLS__ : JSON . stringify ( false ) } ] ) ; } export function getVueLoaderPath ( ) { try { return require . resolve ( 'vue-loader' , { paths : [ process . cwd ( ) ] } ) ; } catch ( error ) { console . log ( chalk . yellow ( '找不到 vue-loader，请先安装。' ) ) ; process . exit ( 1 ) ; } }