0

webpack.config.js

  devtool: false,
  entry: ['babel-polyfill', './src/index.js'],
  output: {
    path: join(__dirname, 'lib'),
    filename: '[name].js',
    library: 'mylib',
    libraryTarget: 'umd',
    umdNamedDefine: true,
    sourceMapFilename: `[name].js.map`,
  },
  ...
  new webpack.EnvironmentPlugin({
    NODE_ENV: 'development',
    POUCHDB_NAME: 'dbname'
  }),

当我尝试在浏览器中打开 ( index.html) ...

未捕获的 ReferenceError:进程未在 Object 中定义。(db.js:8) 在 Object.defineProperty.value (main.js:12716) 在 Object.crypto (main.js:12727) 在webpack_require (bootstrap 2becb557cb7088856bca:19) 在 Object.defineProperty.value (main.js: 18506)在对象。(main.js:18519) 在webpack_require (bootstrap 2becb557cb7088856bca:19) 在 Object.defineProperty.value (_replacer.js:8) 在 Object. (_replacer.js:8) 在webpack_require (bootstrap 2becb557cb7088856bca:19)

db.js我有..

const { POUCHDB_NAME = 'mydb' } = process.env;
4

1 回答 1

0

尝试DefinePlugin代替EnvironmentPlugin

new webpack.DefinePlugin({
            'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
            'process.env.POUCHDB_NAME': JSON.stringify(process.env.POUCHDB_NAME || 'mydb'),
        })
于 2018-07-03T22:49:48.257 回答