|
1 | 1 | const path = require('path'); |
2 | 2 |
|
3 | | -/** |
4 | | - * If -p flag is set, minify the files |
5 | | - * @type {boolean} |
6 | | - */ |
7 | | -const src = (process.argv.indexOf('-p') === -1); |
8 | | -const filenamePostfix = src ? '.src' : ''; |
9 | 3 |
|
10 | | -/** |
11 | | - * If -b flag is set, build bundles, and not exclude highcharts from the build |
12 | | - * @type {boolean} |
13 | | - */ |
14 | | -const bundles = (process.argv.indexOf('-b') !== -1); |
15 | | -const bundlePrefix = (bundles ? 'bundle/' : ''); |
| 4 | +module.exports = function (env) { |
| 5 | + env = env || {}; |
16 | 6 |
|
17 | 7 |
|
18 | | -const highchartsExternals = { |
19 | | - 'highcharts/highmaps': { |
20 | | - root: 'Highcharts', |
21 | | - commonjs2: 'highcharts/highmaps', |
22 | | - commonjs: 'highcharts/highmaps', |
23 | | - amd: 'highcharts/highmaps' |
24 | | - }, |
25 | | - 'highcharts/highstock': { |
26 | | - root: 'Highcharts', |
27 | | - commonjs2: 'highcharts/highstock', |
28 | | - commonjs: 'highcharts/highstock', |
29 | | - amd: 'highcharts/highstock' |
30 | | - }, |
31 | | - 'highcharts': { |
32 | | - root: 'Highcharts', |
33 | | - commonjs2: 'highcharts', |
34 | | - commonjs: 'highcharts', |
35 | | - amd: 'highcharts' |
36 | | - } |
37 | | -}; |
| 8 | + /** |
| 9 | + * If -p flag is set, minify the files |
| 10 | + * @type {boolean} |
| 11 | + */ |
| 12 | + const src = !env.p; |
| 13 | + const filenamePostfix = src ? '.src' : ''; |
38 | 14 |
|
39 | | -const reactExternals = { |
40 | | - react: { |
41 | | - root: 'React', |
42 | | - commonjs2: 'react', |
43 | | - commonjs: 'react', |
44 | | - amd: 'react' |
45 | | - }, |
46 | | - 'react-dom': { |
47 | | - root: 'ReactDOM', |
48 | | - commonjs2: 'react-dom', |
49 | | - commonjs: 'react-dom', |
50 | | - amd: 'react-dom' |
51 | | - } |
52 | | -}; |
| 15 | + /** |
| 16 | + * If -b flag is set, build bundles, and not exclude highcharts from the build |
| 17 | + * @type {boolean} |
| 18 | + */ |
| 19 | + const bundles = env.b; |
| 20 | + const bundlePrefix = (bundles ? 'bundle/' : ''); |
| 21 | + |
| 22 | + |
| 23 | + const highchartsExternals = { |
| 24 | + 'highcharts/highmaps': { |
| 25 | + root: 'Highcharts', |
| 26 | + commonjs2: 'highcharts/highmaps', |
| 27 | + commonjs: 'highcharts/highmaps', |
| 28 | + amd: 'highcharts/highmaps' |
| 29 | + }, |
| 30 | + 'highcharts/highstock': { |
| 31 | + root: 'Highcharts', |
| 32 | + commonjs2: 'highcharts/highstock', |
| 33 | + commonjs: 'highcharts/highstock', |
| 34 | + amd: 'highcharts/highstock' |
| 35 | + }, |
| 36 | + 'highcharts': { |
| 37 | + root: 'Highcharts', |
| 38 | + commonjs2: 'highcharts', |
| 39 | + commonjs: 'highcharts', |
| 40 | + amd: 'highcharts' |
| 41 | + } |
| 42 | + }; |
| 43 | + |
| 44 | + const reactExternals = { |
| 45 | + react: { |
| 46 | + root: 'React', |
| 47 | + commonjs2: 'react', |
| 48 | + commonjs: 'react', |
| 49 | + amd: 'react' |
| 50 | + }, |
| 51 | + 'react-dom': { |
| 52 | + root: 'ReactDOM', |
| 53 | + commonjs2: 'react-dom', |
| 54 | + commonjs: 'react-dom', |
| 55 | + amd: 'react-dom' |
| 56 | + } |
| 57 | + }; |
53 | 58 |
|
54 | | -const externals = [reactExternals]; |
| 59 | + const externals = [reactExternals]; |
55 | 60 |
|
56 | | -externals.push(highchartsExternals); |
| 61 | + externals.push(highchartsExternals); |
57 | 62 |
|
58 | 63 |
|
59 | | -module.exports = { |
60 | | - entry: { |
61 | | - // Array syntax to workaround https://github.com/webpack/webpack/issues/300 |
62 | | - 'index': ['./src/ReactHighcharts.jsx'], |
63 | | - 'ReactHighcharts': ['./src/ReactHighcharts.jsx'], |
64 | | - 'ReactHighstock': ['./src/Highstock.jsx'], |
65 | | - 'ReactHighmaps': ['./src/Highmaps.jsx'], |
66 | | - 'RedrawOnPrint': ['./src/RedrawOnPrint.jsx'] |
67 | | - }, |
68 | | - module: { |
69 | | - rules: [ |
70 | | - { |
71 | | - test: /\.jsx$/, |
72 | | - use: [{ |
73 | | - loader: 'babel-loader', |
74 | | - query: { |
75 | | - cacheDirectory: true, |
76 | | - presets: ['react', 'es2015', 'stage-2'] |
77 | | - } |
78 | | - }], |
| 64 | + return { |
| 65 | + entry: { |
| 66 | + // Array syntax to workaround https://github.com/webpack/webpack/issues/300 |
| 67 | + 'index': ['./src/ReactHighcharts.jsx'], |
| 68 | + 'ReactHighcharts': ['./src/ReactHighcharts.jsx'], |
| 69 | + 'ReactHighstock': ['./src/Highstock.jsx'], |
| 70 | + 'ReactHighmaps': ['./src/Highmaps.jsx'], |
| 71 | + 'RedrawOnPrint': ['./src/RedrawOnPrint.jsx'] |
| 72 | + }, |
| 73 | + module: { |
| 74 | + rules: [ |
| 75 | + { |
| 76 | + test: /\.jsx$/, |
| 77 | + use: [{ |
| 78 | + loader: 'babel-loader', |
| 79 | + query: { |
| 80 | + cacheDirectory: true, |
| 81 | + presets: ['react', 'es2015', 'stage-2'] |
| 82 | + } |
| 83 | + }], |
79 | 84 |
|
80 | 85 |
|
81 | | - } |
82 | | - ] |
83 | | - }, |
84 | | - externals: externals, |
85 | | - resolve: { |
86 | | - modules: [ |
87 | | - "node_modules" |
88 | | - ] |
89 | | - }, |
90 | | - output: { |
91 | | - filename: 'dist/' + bundlePrefix + '[name]' + filenamePostfix + '.js', |
92 | | - libraryTarget: 'umd', |
93 | | - library: '[name]' |
| 86 | + } |
| 87 | + ] |
| 88 | + }, |
| 89 | + externals: externals, |
| 90 | + resolve: { |
| 91 | + modules: [ |
| 92 | + "node_modules" |
| 93 | + ] |
| 94 | + }, |
| 95 | + output: { |
| 96 | + filename: 'dist/' + bundlePrefix + '[name]' + filenamePostfix + '.js', |
| 97 | + libraryTarget: 'umd', |
| 98 | + library: '[name]' |
| 99 | + } |
94 | 100 | } |
95 | 101 | }; |
0 commit comments