F-loat / mpvue-entry

⛓️ 集中式页面配置,统一构建入口,支持新增页面热更新
MIT License
353 stars 56 forks source link

main.js里的app config无法使用process.env.NODE_ENV? #49

Closed maimake closed 5 years ago

maimake commented 6 years ago

我想根据NODE_ENV配置app.json:

const app = new Vue(App)
app.$mount()

export default {
  // 这个字段走 app.json
  config: {
    pages: [],
    window: {
      backgroundTextStyle: 'light',
    },
    debug: process.env.NODE_ENV !== 'production',
  },
}

然后热更新报错

 ERROR  Failed to compile with 1 errors                                                                                     11:30:43

 error  in ./src/main.js

Module build failed: ReferenceError: unknown: process is not defined
    at evalmachine.<anonymous>:12:10
    at ContextifyScript.Script.runInContext (vm.js:35:29)
    at /Users/mai/tmp/up-activities/node_modules/babelon/index.js:32:12
    at Object.babelon.eval (/Users/mai/tmp/up-activities/node_modules/babelon/index.js:43:31)
    at Property (/Users/mai/tmp/up-activities/node_modules/@f-loat/mpvue-loader/lib/mp-compiler/parse.js:34:69)
    at NodePath._call (/Users/mai/tmp/up-activities/node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (/Users/mai/tmp/up-activities/node_modules/babel-traverse/lib/path/context.js:48:17)
    at NodePath.visit (/Users/mai/tmp/up-activities/node_modules/babel-traverse/lib/path/context.js:105:12)
    at TraversalContext.visitQueue (/Users/mai/tmp/up-activities/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitMultiple (/Users/mai/tmp/up-activities/node_modules/babel-traverse/lib/context.js:103:17)
    at TraversalContext.visit (/Users/mai/tmp/up-activities/node_modules/babel-traverse/lib/context.js:190:19)
    at Function.traverse.node (/Users/mai/tmp/up-activities/node_modules/babel-traverse/lib/index.js:114:17)

如果重新编译的话,终端停住,一直等都没有出结果

F-loat commented 6 years ago

这个目前是 mpvue-loader 的问题,解析这块的时候没有注入这个变量

F-loat commented 5 years ago

这部分是纯 json,即使注入了变量,在开发模式下不启用压缩生成的代码依然是不正确的,建议在其他地方进行此类配置,例如 vue 原型什么的