Taro3 vue 解决 process is not defined

611 阅读1分钟

一、安装 cross-env

yarn add cross-env

二、配置 vue.config.js

// vue.config.js
module.exports = {
  configureWebpack: {
    plugins: [
      // DefinePlugin 用于设置环境变量
      new webpack.DefinePlugin({
        "process.env": {
          NODE_ENV: JSON.stringify(process.env.NODE_ENV),
        },
      }),
    ],
  },
};

三、配置 package.json 命令

...
"scripts": {
    ...
    "build:weapp": "cross-env NODE_ENV=production taro build --type weapp",
    "dev:weapp": "cross-env NODE_ENV=development taro build --type weapp --watch",
    ...
}