|
1 | 1 | const path = require('path') |
2 | 2 | const HtmlWebpackPlugin = require('html-webpack-plugin') |
3 | 3 | const LodashModuleReplacementPlugin = require('lodash-webpack-plugin') |
4 | | -const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin |
| 4 | +const BundleAnalyzerPlugin = require('webpack-bundle-analyzer') |
| 5 | + .BundleAnalyzerPlugin |
5 | 6 | const webpack = require('webpack') |
6 | 7 |
|
7 | 8 | module.exports = mode => { |
8 | | - return { |
9 | | - mode, |
10 | | - entry: 'index.js', |
11 | | - output: { filename: 'bundle.js', path: path.resolve('./dist') }, |
12 | | - module: { |
13 | | - rules: [ |
14 | | - { test: /\.css$/, use: ['style-loader', 'css-loader'] }, |
15 | | - { |
16 | | - test: /\.jsx?$/, |
17 | | - sideEffects: false, |
18 | | - exclude: /node_modules/, |
19 | | - use: { |
20 | | - loader: 'babel-loader', |
21 | | - options: { |
22 | | - babelrc: false, |
23 | | - presets: [ |
24 | | - [ |
25 | | - '@babel/preset-env', |
26 | | - { |
27 | | - modules: false, |
28 | | - loose: true, |
29 | | - ...(mode.production |
30 | | - ? { useBuiltIns: 'usage', targets: { chrome: 61 } } |
31 | | - : { useBuiltIns: false, targets: { browsers: 'last 2 Chrome versions' } }), |
32 | | - }, |
33 | | - ], |
34 | | - '@babel/preset-stage-0', |
35 | | - '@babel/preset-react', |
36 | | - ], |
37 | | - plugins: mode.production |
38 | | - ? [ |
39 | | - [ |
40 | | - '@babel/transform-runtime', |
41 | | - { helpers: true, polyfill: false, regenerator: false, moduleName: '@babel/runtime' }, |
42 | | - ], |
43 | | - 'babel-plugin-lodash', |
44 | | - ] |
45 | | - : [], |
46 | | - }, |
47 | | - }, |
48 | | - }, |
49 | | - ], |
50 | | - }, |
51 | | - resolve: { |
52 | | - modules: [path.resolve('./'), 'node_modules'], |
53 | | - extensions: ['.js', '.jsx'], |
54 | | - alias: { |
55 | | - 'react': path.resolve('node_modules/react'), |
56 | | - 'react-spring': path.resolve('../src'), |
57 | | - lodash: path.resolve(__dirname, 'node_modules/lodash-es'), |
| 9 | + return { |
| 10 | + mode, |
| 11 | + entry: 'index.js', |
| 12 | + output: { filename: 'bundle.js', path: path.resolve('./dist') }, |
| 13 | + module: { |
| 14 | + rules: [ |
| 15 | + { test: /\.css$/, use: ['style-loader', 'css-loader'] }, |
| 16 | + { |
| 17 | + test: /\.jsx?$/, |
| 18 | + sideEffects: false, |
| 19 | + exclude: /node_modules/, |
| 20 | + use: { |
| 21 | + loader: 'babel-loader', |
| 22 | + options: { |
| 23 | + babelrc: false, |
| 24 | + presets: [ |
| 25 | + [ |
| 26 | + '@babel/preset-env', |
| 27 | + { |
| 28 | + modules: false, |
| 29 | + loose: true, |
| 30 | + ...(mode.production |
| 31 | + ? { useBuiltIns: 'usage', targets: { chrome: 61 } } |
| 32 | + : { |
| 33 | + useBuiltIns: false, |
| 34 | + targets: { browsers: 'last 2 Chrome versions' }, |
| 35 | + }), |
| 36 | + }, |
| 37 | + ], |
| 38 | + '@babel/preset-stage-0', |
| 39 | + '@babel/preset-react', |
| 40 | + ], |
| 41 | + plugins: mode.production |
| 42 | + ? [ |
| 43 | + [ |
| 44 | + '@babel/transform-runtime', |
| 45 | + { |
| 46 | + helpers: true, |
| 47 | + polyfill: false, |
| 48 | + regenerator: false, |
| 49 | + moduleName: '@babel/runtime', |
| 50 | + }, |
| 51 | + ], |
| 52 | + 'babel-plugin-lodash', |
| 53 | + ] |
| 54 | + : [], |
58 | 55 | }, |
| 56 | + }, |
59 | 57 | }, |
60 | | - plugins: [ |
61 | | - new HtmlWebpackPlugin({ template: 'template.html' }), |
62 | | - new LodashModuleReplacementPlugin(), |
63 | | - new webpack.LoaderOptionsPlugin({ minimize: true, debug: false }), |
64 | | - new BundleAnalyzerPlugin({ openAnalyzer: false, analyzerMode: 'static', defaultSizes: 'gzip' }), |
65 | | - ], |
66 | | - devServer: { hot: false, contentBase: path.resolve('./'), stats: 'errors-only' }, |
67 | | - devtool: undefined, |
68 | | - optimization: { |
69 | | - runtimeChunk: true, |
70 | | - splitChunks: { |
71 | | - chunks: 'all', |
72 | | - minSize: 20000, |
73 | | - minChunks: 1, |
74 | | - maxAsyncRequests: 10, |
75 | | - maxInitialRequests: 10, |
76 | | - automaticNameDelimiter: '~', |
77 | | - name: true, |
78 | | - cacheGroups: { |
79 | | - default: { |
80 | | - minChunks: 1, |
81 | | - priority: -20, |
82 | | - reuseExistingChunk: true, |
83 | | - }, |
84 | | - vendors: { |
85 | | - test: /[\\/]node_modules[\\/]/, |
86 | | - priority: -5, |
87 | | - }, |
88 | | - }, |
89 | | - }, |
| 58 | + ], |
| 59 | + }, |
| 60 | + resolve: { |
| 61 | + modules: [path.resolve('./'), 'node_modules'], |
| 62 | + extensions: ['.js', '.jsx'], |
| 63 | + alias: { |
| 64 | + react: path.resolve('node_modules/react'), |
| 65 | + 'react-dom': path.resolve('node_modules/react-dom'), |
| 66 | + 'prop-types': path.resolve('node_modules/prop-types'), |
| 67 | + 'react-spring': path.resolve('../src'), |
| 68 | + lodash: path.resolve(__dirname, 'node_modules/lodash-es'), |
| 69 | + }, |
| 70 | + }, |
| 71 | + plugins: [ |
| 72 | + new HtmlWebpackPlugin({ template: 'template.html' }), |
| 73 | + new LodashModuleReplacementPlugin(), |
| 74 | + new webpack.LoaderOptionsPlugin({ minimize: true, debug: false }), |
| 75 | + new BundleAnalyzerPlugin({ |
| 76 | + openAnalyzer: false, |
| 77 | + analyzerMode: 'static', |
| 78 | + defaultSizes: 'gzip', |
| 79 | + }), |
| 80 | + ], |
| 81 | + devServer: { |
| 82 | + hot: false, |
| 83 | + contentBase: path.resolve('./'), |
| 84 | + stats: 'errors-only', |
| 85 | + }, |
| 86 | + devtool: undefined, |
| 87 | + optimization: { |
| 88 | + runtimeChunk: true, |
| 89 | + splitChunks: { |
| 90 | + chunks: 'all', |
| 91 | + minSize: 20000, |
| 92 | + minChunks: 1, |
| 93 | + maxAsyncRequests: 10, |
| 94 | + maxInitialRequests: 10, |
| 95 | + automaticNameDelimiter: '~', |
| 96 | + name: true, |
| 97 | + cacheGroups: { |
| 98 | + default: { |
| 99 | + minChunks: 1, |
| 100 | + priority: -20, |
| 101 | + reuseExistingChunk: true, |
| 102 | + }, |
| 103 | + vendors: { |
| 104 | + test: /[\\/]node_modules[\\/]/, |
| 105 | + priority: -5, |
| 106 | + }, |
90 | 107 | }, |
91 | | - performance: { hints: false }, |
92 | | - } |
| 108 | + }, |
| 109 | + }, |
| 110 | + performance: { hints: false }, |
| 111 | + } |
93 | 112 | } |
0 commit comments