Skip to content

Commit 3215900

Browse files
committed
Fix webpack build
1 parent b62da76 commit 3215900

File tree

2 files changed

+88
-82
lines changed

2 files changed

+88
-82
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"test": "webpack && mocha test/unit",
88
"e2e": "nightwatch test/e2e/e2e-launcher.js -e local --config nightwatch.js ",
99
"e2e-sc": "nightwatch test/e2e/e2e-launcher.js -e saucelabs --config nightwatch.js ",
10-
"build": "webpack && webpack -p && webpack -b && webpack -p -b",
10+
"build": "webpack && webpack --env.p && webpack --env.b && webpack --env.p --env.b",
1111
"demo": "cd demo && webpack && sh generate-contents.sh && ../node_modules/.bin/webpack-dev-server --content-base dist/",
1212
"prepublish": "npm run build && npm run copy-bundles",
1313
"copy-bundles": "sh ./src/copy-bundles.sh",

webpack.config.js

Lines changed: 87 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,101 @@
11
const path = require('path');
22

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' : '';
93

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 || {};
166

177

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' : '';
3814

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+
};
5358

54-
const externals = [reactExternals];
59+
const externals = [reactExternals];
5560

56-
externals.push(highchartsExternals);
61+
externals.push(highchartsExternals);
5762

5863

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+
}],
7984

8085

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+
}
94100
}
95101
};

0 commit comments

Comments
 (0)