2016-08-10 6 views
0

を使用するためにどのように私は私のWebPACKのReact.jsアプリuglifyバージョンのWebPACK React.js uglifyバージョン

webpack.config.js

module.exports = { 
    entry: './_react/index', 
    output: { 
     path: './dist/public/app', 
     filename: 'bundle.min.js' 
    }, 
    devtool: 'source-map', 
    devServer: { 
     contentBase: __dirname 
    }, 
    module: { 
     loaders: [{ 
      test: /\.js?$/, 
      exclude: /(node_modules|bower_components)/, 
      loader: ['babel-loader'], 
      query: { 
       presets: ['es2015', 'react'] 
      } 
     }] 
    } 
} 

を使用したいと思いターミナル

webpack -p 

enter image description here

Webブラウザ上でプレビューした後、私はこのエラー

enter image description here

案内してください

、感謝

あなたが生産にNODE_ENVを設定する必要が

答えて

1

jmargolisvtによると、NODE_ENVを設定する必要があります。

すると、次のあなたのwebpack.config.jsを更新してみてください。

として
plugins: [ 
    new webpack.DefinePlugin({ 
    'process.env': { 
     'NODE_ENV': JSON.stringify('production') 
    } 
    }) 
], 

またはあなたの現在の設定で:

module.exports = { 
    entry: './_react/index', 
    output: { 
     path: './dist/public/app', 
     filename: 'bundle.min.js' 
    }, 
    devtool: 'source-map', 
    devServer: { 
     contentBase: __dirname 
    }, 
    module: { 
     loaders: [{ 
      test: /\.js?$/, 
      exclude: /(node_modules|bower_components)/, 
      loader: ['babel-loader'], 
      query: { 
       presets: ['es2015', 'react'] 
      } 
     }] 
    } 
    plugins: [ 
     new webpack.DefinePlugin({ 
      'process.env': { 
       'NODE_ENV': JSON.stringify('production') 
      } 
     }) 
    ], 
} 

なく文字列変数を挿入するJSON.stringifyを使用してくださいproduction

1

を得ました。 React site

注:Reactはデフォルトで開発モードになります。生産モードでReactを使用するには、環境変数NODE_ENVをproduction(envifyまたはwebpackのDefinePluginを使用)に設定します。

関連する問題