-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathwebpack.config.js
66 lines (63 loc) · 1.6 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
const webpack = require('webpack');
const path = require('path');
const nodeExternals = require('webpack-node-externals');
const { type } = require('os');
const env = process.env.NODE_ENV || 'development';
let plugins;
// We want to manually specify these plugins, because using mode: production
// includes uglify which we don't want. https://webpack.js.org/concepts/mode/#mode-production
if (env === 'production') {
plugins = [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
}),
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
];
} else {
plugins = [
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development'),
}),
];
}
module.exports = {
target: 'web',
mode: 'none', // We don't want this feature. See above.
entry: {
library: './source/index.js',
},
output: {
path: path.resolve(__dirname, 'build'),
filename: '[name].js',
library: {
name: 'react-components',
type: 'umd',
},
clean: true,
},
externals: [
nodeExternals({
modulesDir: path.resolve(__dirname, '../../node_modules'),
}),
nodeExternals({ modulesDir: path.resolve(__dirname, 'node_modules') }),
],
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: 'babel-loader',
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
type: 'asset/resource',
generator: {
filename: 'assets/[name].[hash][ext]',
},
},
],
},
plugins,
};