|
1 | 1 | const path = require('path'); |
2 | 2 | const glob = require('glob-all'); |
3 | | -const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin'); |
4 | 3 | const webpack = require('webpack'); |
5 | 4 |
|
6 | 5 | module.exports = { |
@@ -54,79 +53,7 @@ module.exports = { |
54 | 53 |
|
55 | 54 | webpack: (config, { dev }) => { |
56 | 55 | if (!dev) { |
57 | | - // const oldEntry = config.entry; |
58 | | - // config.entry = () => oldEntry().then((entry) => { |
59 | | - // entry['main.js'].push(path.resolve('./offline')); |
60 | | - // return entry; |
61 | | - // }); |
62 | | - |
63 | | - config.plugins.push(new SWPrecacheWebpackPlugin({ |
64 | | - cacheId: 'VergePWA', |
65 | | - filepath: path.resolve('./static/sw.js'), |
66 | | - staticFileGlobs: [ |
67 | | - 'static/**/ *', |
68 | | - ], |
69 | | - minify: true, |
70 | | - staticFileGlobsIgnorePatterns: [/\.next\//], |
71 | | - runtimeCaching: [{ |
72 | | - handler: 'fastest', |
73 | | - urlPattern: /[.](png|jpg|css)/, |
74 | | - }, { |
75 | | - handler: 'networkFirst', |
76 | | - urlPattern: /^http.*/, |
77 | | - }], |
78 | | - })); |
79 | | - config.plugins = config.plugins.filter(plugin => (plugin.constructor.name !== 'UglifyJsPlugin')); |
80 | | - config.plugins.push(new webpack.optimize.UglifyJsPlugin({ |
81 | | - uglifyOptions: { |
82 | | - output: { |
83 | | - comments: false, |
84 | | - }, |
85 | | - exclude: [/\.min\.js$/gi], // skip pre-minified libs |
86 | | - compress: { |
87 | | - arrows: false, |
88 | | - booleans: false, |
89 | | - cascade: false, |
90 | | - collapse_vars: false, |
91 | | - comparisons: false, |
92 | | - computed_props: false, |
93 | | - hoist_funs: false, |
94 | | - hoist_props: false, |
95 | | - hoist_vars: false, |
96 | | - if_return: false, |
97 | | - inline: false, |
98 | | - join_vars: false, |
99 | | - keep_infinity: true, |
100 | | - loops: false, |
101 | | - negate_iife: false, |
102 | | - properties: false, |
103 | | - reduce_funcs: false, |
104 | | - reduce_vars: false, |
105 | | - sequences: false, |
106 | | - side_effects: false, |
107 | | - switches: false, |
108 | | - top_retain: false, |
109 | | - toplevel: false, |
110 | | - typeofs: false, |
111 | | - unused: false, |
112 | | - warnings: false, // Suppress uglification warnings |
113 | | - pure_getters: true, |
114 | | - unsafe: true, |
115 | | - unsafe_comps: true, |
116 | | - screw_ie8: true, |
117 | | - |
118 | | - // Switch off all types of compression except those needed to convince |
119 | | - // react-devtools that we're using a production build |
120 | | - conditionals: true, |
121 | | - dead_code: true, |
122 | | - evaluate: true, |
123 | | - }, |
124 | | - mangle: true, |
125 | | - }, |
126 | | - })); |
127 | | - // config.plugins.push(new BundleAnalyzerPlugin()); <-- use to analyze the bundle size |
128 | 56 | config.plugins.push(new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)); |
129 | | - config.plugins.push(new webpack.optimize.AggressiveMergingPlugin()); |
130 | 57 | } |
131 | 58 | config.module.rules.push( |
132 | 59 | { |
@@ -163,62 +90,9 @@ module.exports = { |
163 | 90 | }, |
164 | 91 | }, |
165 | 92 | ); |
166 | | - config.plugins.push(new webpack.DefinePlugin({ |
167 | | - 'process.env': { |
168 | | - NODE_ENV: JSON.stringify('production'), |
169 | | - }, |
170 | | - })); |
171 | | - config.plugins = config.plugins.filter(plugin => (plugin.constructor.name !== 'UglifyJsPlugin')); |
172 | | - config.plugins.push(new webpack.optimize.UglifyJsPlugin({ |
173 | | - uglifyOptions: { |
174 | | - output: { |
175 | | - comments: false, |
176 | | - }, |
177 | | - exclude: [/\.min\.js$/gi], // skip pre-minified libs |
178 | | - compress: { |
179 | | - arrows: false, |
180 | | - booleans: false, |
181 | | - cascade: false, |
182 | | - collapse_vars: false, |
183 | | - comparisons: false, |
184 | | - computed_props: false, |
185 | | - hoist_funs: false, |
186 | | - hoist_props: false, |
187 | | - hoist_vars: false, |
188 | | - if_return: false, |
189 | | - inline: false, |
190 | | - join_vars: false, |
191 | | - keep_infinity: true, |
192 | | - loops: false, |
193 | | - negate_iife: false, |
194 | | - properties: false, |
195 | | - reduce_funcs: false, |
196 | | - reduce_vars: false, |
197 | | - sequences: false, |
198 | | - side_effects: false, |
199 | | - switches: false, |
200 | | - top_retain: false, |
201 | | - toplevel: false, |
202 | | - typeofs: false, |
203 | | - unused: false, |
204 | | - warnings: false, // Suppress uglification warnings |
205 | | - pure_getters: true, |
206 | | - unsafe: true, |
207 | | - unsafe_comps: true, |
208 | | - screw_ie8: true, |
209 | | - |
210 | | - // Switch off all types of compression except those needed to convince |
211 | | - // react-devtools that we're using a production build |
212 | | - conditionals: true, |
213 | | - dead_code: true, |
214 | | - evaluate: true, |
215 | | - }, |
216 | | - mangle: true, |
217 | | - }, |
218 | | - })); |
219 | | - // config.plugins.push(new BundleAnalyzerPlugin()); |
220 | | - config.plugins.push(new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)); |
221 | | - config.plugins.push(new webpack.optimize.AggressiveMergingPlugin()); |
| 93 | + if (dev) { |
| 94 | + config.plugins.push(new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)); |
| 95 | + } |
222 | 96 |
|
223 | 97 | return config; |
224 | 98 | }, |
|
0 commit comments