-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.js
64 lines (56 loc) · 1.46 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
const Path = require('path');
const CompressionPlugin = require('compression-webpack-plugin');
const Package = require('./package.json');
module.exports = env => {
let config = {};
config = generalConfig(config, env);
config = prodConfig(config, env)
config = devConfig(config, env);
return config;
}
function generalConfig(config, env) {
config.mode = env;
config.entry = './src/index.jsx';
config.output = {
path: Path.join(__dirname, 'lib'),
filename: 'react-data.js',
libraryTarget: 'commonjs2'
};
config.module = {
rules: [
{
test: /\.jsx?$/,
exclude: Path.join(__dirname, 'node_modules'),
use: 'babel-loader'
},
]
};
config.externals = {
'react': 'commonjs react'
};
config.resolve = {
modules: [Path.join(__dirname, 'src'), 'node_modules'],
extensions: ['.js', '.jsx', '.ts', '.tsx']
}
return config;
}
function prodConfig(config, env) {
if (env != 'production') { return config }
config.output = {
path: Path.join(__dirname, 'releases'),
filename: 'react-data@' + Package['version'] + '.js',
libraryTarget: 'commonjs2'
};
config.plugins = [
new CompressionPlugin(),
]
return config;
}
function devConfig(config, env) {
if (env != 'development') { return config }
config.devtool = "source-map";
return config;
}
// Webpack devtools
// https://webpack.js.org/configuration/devtool/
// https://webpack.js.org/plugins/eval-source-map-dev-tool-plugin/