-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.build.js
81 lines (76 loc) · 1.78 KB
/
webpack.build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
'use strict';
const path = require('path');
const webpack = require('webpack');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
let COMPONENT_FILE = 'react-tabs';
const plugins = [];
const babelOptions = {};
if (process.env.MINIFY) {
plugins.push(new UglifyJsPlugin({ sourceMap: true }));
plugins.push(new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
}));
COMPONENT_FILE += '.min';
babelOptions.plugins = [
function(babel) {
return {
visitor: {
ImportDeclaration(path) {
// Remove all propType imports in min bundle
if (
path.node.source.value.indexOf('helpers/propTypes') > -1 ||
path.node.source.value === 'prop-types'
) {
path.remove();
}
}
}
};
}
];
} else {
plugins.push(new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development')
}));
}
module.exports = {
entry: path.join(__dirname, 'src/index.js'),
output: {
filename: COMPONENT_FILE + '.js',
path: path.join(__dirname, 'dist'),
library: 'ReactTabs',
libraryTarget: 'umd',
},
externals: {
'react': {
root: 'React',
commonjs2: 'react',
commonjs: 'react',
amd: 'react',
},
'prop-types': {
root: 'PropTypes',
commonjs2: 'prop-types',
commonjs: 'prop-types',
amd: 'prop-types',
},
'classnames': {
root: 'classNames',
commonjs2: 'classnames',
commonjs: 'classnames',
amd: 'classnames',
},
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: babelOptions,
},
],
},
plugins: plugins,
devtool: 'source-map',
};