瀏覽代碼

Optimize React in production

j8
Ilya Daynatovich 8 年之前
父節點
當前提交
06d2fb0aca
共有 1 個文件被更改,包括 16 次插入3 次删除
  1. 16
    3
      webpack.config.js

+ 16
- 3
webpack.config.js 查看文件

@@ -4,13 +4,28 @@ require('babel-polyfill'); // Define Object.assign() from ES6 in ES5.
4 4
 
5 5
 var HasteResolverPlugin = require('haste-resolver-webpack-plugin');
6 6
 var process = require('process');
7
+var webpack = require('webpack');
7 8
 
8 9
 var aui_css = __dirname + '/node_modules/@atlassian/aui/dist/aui/css/';
9 10
 var minimize
10 11
     = process.argv.indexOf('-p') != -1
11 12
         || process.argv.indexOf('--optimize-minimize') != -1;
13
+var plugins = [
14
+    new HasteResolverPlugin()
15
+];
12 16
 var strophe = /\/node_modules\/strophe(js-plugins)?\/.*\.js$/;
13 17
 
18
+if (minimize) {
19
+    // XXX Webpack's command line argument -p is not enough. Further
20
+    // optimizations are made possible by the use of DefinePlugin and NODE_ENV
21
+    // with value 'production'. For example, React takes advantage of these.
22
+    plugins.push(new webpack.DefinePlugin({
23
+        'process.env': {
24
+            NODE_ENV: JSON.stringify('production')
25
+        }
26
+    }));
27
+}
28
+
14 29
 // The base Webpack configuration to bundle the JavaScript artifacts of
15 30
 // jitsi-meet such as app.bundle.js and external_api.js.
16 31
 var config = {
@@ -87,9 +102,7 @@ var config = {
87 102
         path: __dirname + '/build',
88 103
         sourceMapFilename: '[name].' + (minimize ? 'min' : 'js') + '.map'
89 104
     },
90
-    plugins: [
91
-        new HasteResolverPlugin()
92
-    ],
105
+    plugins: plugins,
93 106
     resolve: {
94 107
         alias: {
95 108
             aui:

Loading…
取消
儲存