-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
68 lines (62 loc) · 1.66 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
const path = require('path')
const _ = require('lodash')
const isProduction = process.env.NODE_ENV === 'production'
const baseConfig = {
context: __dirname,
mode: isProduction ? 'production' : 'development',
devtool: isProduction ? 'hidden-source-map' : 'cheap-module-source-map',
entry: {
index: './src/index.jsx'
},
output: {
filename: 'cjs.js',
chunkFilename: '[name].js',
path: path.resolve('dist'),
libraryTarget: 'commonjs2',
libraryExport: 'default'
},
resolve: {
extensions: ['.js', '.jsx', '.json'],
},
externals: {
react: 'react',
'react-dom': 'react-dom',
'react-router': 'react-router',
'react-router-dom': 'react-router-dom'
},
module: {
rules: [
{
test: /\.jsx?$/,
...!isProduction && {exclude: /(node_modules|bower_components)/},
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true,
presets: [
require.resolve('@babel/preset-env'),
require.resolve('@babel/preset-react')
],
plugins: [
// require.resolve('babel-plugin-add-module-exports'),
require.resolve('@babel/plugin-proposal-class-properties'),
require.resolve('@babel/plugin-proposal-object-rest-spread'),
]
}
}
}
]
},
optimization: {
minimize: isProduction
}
}
module.exports = !isProduction ? baseConfig : [
baseConfig,
_.merge(_.cloneDeep(baseConfig), {
output: {
filename: 'umd.js',
libraryTarget: 'umd'
}
}),
]