-
Notifications
You must be signed in to change notification settings - Fork 67
/
webpack.config.js
95 lines (89 loc) · 2.93 KB
/
webpack.config.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
84
85
86
87
88
89
90
91
92
93
94
95
const webpack = require('webpack');
const path = require('path');
const outputPath = path.resolve(__dirname, 'lib/');
const inputPath = path.resolve(__dirname, 'js_src/');
var babelRules = [
{
test: /\.js?$/,
use: {
loader: 'babel-loader',
options: {
exclude: [/node_modules/],
presets: [
[
'@babel/preset-env',
{
corejs: 3,
useBuiltIns: 'usage',
targets: {
browsers: 'last 2 chrome versions, last 2 edge versions, ie 11',
},
},
],
],
},
},
},
];
/// Helper function that generates the webpack export objects array
///
/// Usage:
/// createExports([
/// [entryFilename, outputFilename, [isProduction]],
/// {
/// ...NORMAL WEBPACK CONFIG OBJECT...
/// },
/// ...
/// ]);
///
function createExports(exportMappings) {
exportObjects = [];
exportMappings.forEach(function(mapping) {
if (Array.isArray(mapping)) {
entryFilename = mapping[0];
outputFilename = mapping[1] || mapping[0];
isProduction = mapping[2] || outputFilename.includes('_prod');
includeReact = entryFilename === 'react.js' || entryFilename.includes('react_with');
exportObject = {
output: {
path: outputPath,
filename: outputFilename,
},
module: {
rules: babelRules,
},
entry: path.resolve(inputPath, entryFilename),
mode: isProduction ? 'production' : 'development',
externals: [{ window: 'window' }],
devtool: 'source-map',
};
// `react-redux` requires `redux` but we do not utilize the one section that it is used.
// For reference, react-redux.js uses `redux` only one time ever, in [whenMapDispatchToPropsIsObject]
// and it calls `redux.bindActionCreators`.
//
// This line fakes any `require('redux')` calls, so that webpack will not include all of the `redux` code.
exportObject.externals[0].redux = 'window.Object';
if (!includeReact) {
// This forces any packages that require react as a dependacy to have the same instance of react that
// is provided by our react js bundles.
exportObject.externals[0].react = 'window.React';
// Re-uses React.PropTypes setup in react.js instead of including the entire lib again.
exportObject.externals[0]['prop-types'] = 'window.React.PropTypes';
}
exportObjects.push(exportObject);
} else {
exportObjects.push(mapping);
}
});
return exportObjects;
}
module.exports = createExports([
['react.js', 'react_with_addons.js'],
['react.js', 'react.js'],
['react_dom.js', 'react_dom.js'],
['react_dom_server.js', 'react_dom_server.js'],
['react.js', 'react_prod.js'],
['react_dom.js', 'react_dom_prod.js'],
['react_dom_server.js', 'react_dom_server_prod.js'],
['react_with_react_dom.js', 'react_with_react_dom_prod.js'],
]);