瀏覽代碼

Optimize React in production

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

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

4
 
4
 
5
 var HasteResolverPlugin = require('haste-resolver-webpack-plugin');
5
 var HasteResolverPlugin = require('haste-resolver-webpack-plugin');
6
 var process = require('process');
6
 var process = require('process');
7
+var webpack = require('webpack');
7
 
8
 
8
 var aui_css = __dirname + '/node_modules/@atlassian/aui/dist/aui/css/';
9
 var aui_css = __dirname + '/node_modules/@atlassian/aui/dist/aui/css/';
9
 var minimize
10
 var minimize
10
     = process.argv.indexOf('-p') != -1
11
     = process.argv.indexOf('-p') != -1
11
         || process.argv.indexOf('--optimize-minimize') != -1;
12
         || process.argv.indexOf('--optimize-minimize') != -1;
13
+var plugins = [
14
+    new HasteResolverPlugin()
15
+];
12
 var strophe = /\/node_modules\/strophe(js-plugins)?\/.*\.js$/;
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
 // The base Webpack configuration to bundle the JavaScript artifacts of
29
 // The base Webpack configuration to bundle the JavaScript artifacts of
15
 // jitsi-meet such as app.bundle.js and external_api.js.
30
 // jitsi-meet such as app.bundle.js and external_api.js.
16
 var config = {
31
 var config = {
87
         path: __dirname + '/build',
102
         path: __dirname + '/build',
88
         sourceMapFilename: '[name].' + (minimize ? 'min' : 'js') + '.map'
103
         sourceMapFilename: '[name].' + (minimize ? 'min' : 'js') + '.map'
89
     },
104
     },
90
-    plugins: [
91
-        new HasteResolverPlugin()
92
-    ],
105
+    plugins: plugins,
93
     resolve: {
106
     resolve: {
94
         alias: {
107
         alias: {
95
             aui:
108
             aui:

Loading…
取消
儲存