forked from salesforce/design-system-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.dist.js
83 lines (73 loc) · 2.21 KB
/
webpack.config.dist.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
82
83
/* eslint-env node */
const fs = require('fs');
const webpack = require('webpack');
const packageJson = require('./package.json');
const StringReplacePlugin = require('string-replace-webpack-plugin');
const header = `${packageJson.name}\nv${packageJson.version}\n`;
const license = fs.readFileSync('./LICENSE.txt', 'utf8');
const baseConfig = require('./webpack.config');
// eslint-disable-next-line prefer-object-spread/prefer-object-spread
const config = Object.assign({}, baseConfig, {
externals: {
react: {
amd: 'react',
commonjs: 'react',
commonjs2: 'react',
root: 'React',
},
'react/addons': {
amd: 'react',
commonjs: 'react',
commonjs2: 'react',
root: 'React',
},
'react-dom': {
amd: 'react-dom',
commonjs: 'react-dom',
commonjs2: 'react-dom',
root: 'ReactDOM',
},
},
});
let FILENAME = process.env.INCLUDE_ICONS ? '[name].js' : '[name]-components.js';
if (process.env.MINIFY) {
config.plugins.push(
new webpack.optimize.UglifyJsPlugin({
mangle: {
except: ['$', 'exports', 'require'],
},
})
);
FILENAME = process.env.INCLUDE_ICONS
? '[name].min.js'
: '[name]-components.min.js';
}
config.output.filename = FILENAME;
config.output.library = '[name]';
config.output.libraryTarget = 'umd';
const replacementsArr = [
{
pattern: /__VERSION__/g,
replacement: () => packageJson.version,
},
];
// This string replacement includes icons in the bundle and affects `icons/**/index.js` which are built by `npm run icons`. The default condition is an equality comparison of two constants, `'__EXCLUDE_SLDS_ICONS__' === '__INCLUDE_SLDS_ICONS__'`, which will allow minification to remove the inline icons and save 100KBs in size when bundling for production. The following makes the condition equal.
if (process.env.INCLUDE_ICONS) {
replacementsArr.push({
pattern: /__EXCLUDE_SLDS_ICONS__/g,
replacement: () => '__INCLUDE_SLDS_ICONS__',
});
}
config.module.rules[0].loaders = [
'babel-loader',
StringReplacePlugin.replace({
replacements: replacementsArr,
}),
];
config.plugins.push(new webpack.BannerPlugin(header + license));
config.plugins.push(
new webpack.DefinePlugin({
'process.env': { NODE_ENV: JSON.stringify('production') },
})
);
module.exports = config;