|
1 | 1 | const webpack = require('webpack');
|
| 2 | +const R = require('ramda'); |
2 | 3 | const path = require('path');
|
3 | 4 | const packagejson = require('./package.json');
|
4 |
| - |
5 | 5 | const dashLibraryName = packagejson.name.replace(/-/g, '_');
|
6 | 6 |
|
7 |
| -module.exports = (env, argv) => { |
8 |
| - let mode; |
9 |
| - |
10 |
| - // if user specified mode flag take that value |
11 |
| - if (argv && argv.mode) { |
12 |
| - mode = argv.mode; |
13 |
| - } |
14 |
| - |
15 |
| - // else if configuration object is already set (module.exports) use that value |
16 |
| - else if (module.exports && module.exports.mode) { |
17 |
| - mode = module.exports = mode; |
18 |
| - } |
19 |
| - |
20 |
| - // else take webpack default |
21 |
| - else { |
22 |
| - mode = 'production'; |
23 |
| - } |
24 |
| - return { |
25 |
| - entry: {main: ['@babel/polyfill', 'whatwg-fetch', './src/index.js']}, |
26 |
| - output: { |
27 |
| - path: path.resolve(__dirname, dashLibraryName), |
28 |
| - filename: |
29 |
| - mode === 'development' |
30 |
| - ? `${dashLibraryName}.dev.js` |
31 |
| - : `${dashLibraryName}.min.js`, |
32 |
| - library: dashLibraryName, |
33 |
| - libraryTarget: 'window', |
34 |
| - }, |
35 |
| - devtool: 'source-map', |
36 |
| - externals: { |
37 |
| - react: 'React', |
38 |
| - 'react-dom': 'ReactDOM', |
39 |
| - 'plotly.js': 'Plotly', |
40 |
| - 'prop-types': 'PropTypes' |
41 |
| - }, |
42 |
| - module: { |
43 |
| - rules: [ |
44 |
| - { |
45 |
| - test: /\.js$/, |
46 |
| - exclude: /node_modules/, |
47 |
| - use: { |
48 |
| - loader: 'babel-loader', |
49 |
| - }, |
50 |
| - }, |
51 |
| - { |
52 |
| - test: /\.css$/, |
53 |
| - use: [ |
54 |
| - { |
55 |
| - loader: 'style-loader', |
56 |
| - }, |
57 |
| - { |
58 |
| - loader: 'css-loader', |
59 |
| - }, |
60 |
| - ], |
| 7 | +const defaultOptions = { |
| 8 | + mode: 'development', |
| 9 | + devtool: 'none', |
| 10 | + entry: { |
| 11 | + main: ['@babel/polyfill', 'whatwg-fetch', './src/index.js'], |
| 12 | + }, |
| 13 | + output: { |
| 14 | + path: path.resolve(__dirname, dashLibraryName), |
| 15 | + filename: `${dashLibraryName}.dev.js`, |
| 16 | + library: dashLibraryName, |
| 17 | + libraryTarget: 'window', |
| 18 | + }, |
| 19 | + externals: { |
| 20 | + react: 'React', |
| 21 | + 'react-dom': 'ReactDOM', |
| 22 | + 'plotly.js': 'Plotly', |
| 23 | + 'prop-types': 'PropTypes', |
| 24 | + }, |
| 25 | + plugins: [], |
| 26 | + module: { |
| 27 | + rules: [ |
| 28 | + { |
| 29 | + test: /\.js$/, |
| 30 | + exclude: /node_modules/, |
| 31 | + use: { |
| 32 | + loader: 'babel-loader', |
61 | 33 | },
|
62 |
| - { |
63 |
| - test: /\.svg$/, |
64 |
| - use: ['@svgr/webpack'] |
65 |
| - }, |
66 |
| - { |
67 |
| - test: /\.txt$/i, |
68 |
| - use: 'raw-loader', |
| 34 | + }, |
| 35 | + { |
| 36 | + test: /\.css$/, |
| 37 | + use: [ |
| 38 | + { |
| 39 | + loader: 'style-loader', |
| 40 | + }, |
| 41 | + { |
| 42 | + loader: 'css-loader', |
| 43 | + }, |
| 44 | + ], |
| 45 | + }, |
| 46 | + { |
| 47 | + test: /\.svg$/, |
| 48 | + use: ['@svgr/webpack'], |
| 49 | + }, |
| 50 | + { |
| 51 | + test: /\.txt$/i, |
| 52 | + use: 'raw-loader', |
| 53 | + }, |
| 54 | + ], |
| 55 | + }, |
| 56 | +}; |
69 | 57 |
|
| 58 | +module.exports = (_, argv) => { |
| 59 | + const devtool = argv.build === 'local' ? 'source-map' : 'none'; |
| 60 | + return [ |
| 61 | + R.mergeDeepLeft({devtool}, defaultOptions), |
| 62 | + R.mergeDeepLeft( |
| 63 | + { |
| 64 | + devtool: devtool, |
| 65 | + mode: 'production', |
| 66 | + output: { |
| 67 | + filename: `${dashLibraryName}.min.js`, |
70 | 68 | },
|
71 |
| - ], |
72 |
| - }, |
73 |
| - plugins: [ |
74 |
| - new webpack.NormalModuleReplacementPlugin( |
75 |
| - /(.*)GlobalErrorContainer.react(\.*)/, |
76 |
| - function(resource) { |
77 |
| - if (mode === 'production') { |
78 |
| - resource.request = resource.request.replace( |
79 |
| - /GlobalErrorContainer.react/, |
80 |
| - 'GlobalErrorContainerPassthrough.react' |
81 |
| - ); |
82 |
| - } |
83 |
| - } |
84 |
| - ), |
85 |
| - ], |
86 |
| - }; |
| 69 | + plugins: [ |
| 70 | + new webpack.NormalModuleReplacementPlugin( |
| 71 | + /(.*)GlobalErrorContainer.react(\.*)/, |
| 72 | + function(resource) { |
| 73 | + resource.request = resource.request.replace( |
| 74 | + /GlobalErrorContainer.react/, |
| 75 | + 'GlobalErrorContainerPassthrough.react' |
| 76 | + ); |
| 77 | + } |
| 78 | + ), |
| 79 | + ], |
| 80 | + }, |
| 81 | + defaultOptions |
| 82 | + ), |
| 83 | + ]; |
87 | 84 | };
|
0 commit comments