Skip to content

Commit 43911c2

Browse files
committed
fix: Exclude react from UMD build.
1 parent 009306a commit 43911c2

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src --out-dir lib && ./scrips/copy_lib_styles.sh",
1313
"build:es": "cross-env BABEL_ENV=es babel src --out-dir es && ./scrips/copy_es_styles.sh",
1414
"build:umd": "cross-env BABEL_ENV=commonjs NODE_ENV=development webpack --progress --verbose --colors",
15-
"build:umd:min": "cross-env BABEL_ENV=commonjs NODE_ENV=production webpack --progress --verbose --colors",
15+
"build:umd:min": "cross-env BABEL_ENV=commonjs NODE_ENV=production MINIFY=true webpack --progress --verbose --colors",
1616
"build": "npm run build:commonjs && npm run build:es && npm run build:umd && npm run build:umd:min",
1717
"lint": "eslint src/** test/**",
1818
"prepublish": "npm run clean && npm run build",

webpack.config.js

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ var ExtractTextPlugin = require('extract-text-webpack-plugin');
66
var env = process.env.NODE_ENV;
77
var suffix = env === 'production' ? '.min' : '';
88
var filename = `react-mdl-extra${suffix}`;
9+
var minify = process.env.MINIFY;
910

1011
var config = {
1112
entry: [
12-
path.resolve(__dirname, 'src', 'index')
13+
path.resolve(__dirname, 'src', 'index'),
1314
],
1415
output: {
1516
path: path.resolve(__dirname, 'dist'),
@@ -20,23 +21,30 @@ var config = {
2021
resolve: {
2122
extensions: ['', '.js', '.scss', '.css'],
2223
},
24+
externals: {
25+
'react': 'react',
26+
'react-dom' : 'reactDOM',
27+
},
2328
module: {
2429
preLoaders: [{
2530
test: /\.js$/,
2631
loader: 'eslint',
27-
exclude: /node_modules/
32+
exclude: /node_modules/,
2833
}],
2934
loaders: [{
3035
test: /\.js$/,
3136
loader: 'babel',
32-
exclude: /node_modules/
37+
exclude: /node_modules/,
3338
},{
3439
test: /\.(scss|css)$/,
3540
loader: ExtractTextPlugin.extract('css!postcss!sass'),
3641
}]
3742
},
38-
postcss: [ autoprefixer({ browsers: ['last 2 versions'] }) ],
43+
postcss: [
44+
autoprefixer({ browsers: ['last 2 versions'] })
45+
],
3946
plugins: [
47+
new webpack.optimize.DedupePlugin(),
4048
new webpack.optimize.OccurenceOrderPlugin(),
4149
new webpack.DefinePlugin({
4250
'process.env.NODE_ENV': JSON.stringify(env)
@@ -45,4 +53,22 @@ var config = {
4553
],
4654
};
4755

56+
if (minify) {
57+
config.plugins.push(
58+
new webpack.optimize.UglifyJsPlugin({
59+
compress: {
60+
screw_ie8: true,
61+
warnings: false,
62+
},
63+
mangle: {
64+
screw_ie8: true,
65+
},
66+
output: {
67+
comments: false,
68+
screw_ie8: true,
69+
},
70+
})
71+
);
72+
}
73+
4874
module.exports = config

0 commit comments

Comments
 (0)