-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.config.js
102 lines (89 loc) · 2.62 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
96
97
98
99
100
101
102
const webpack = require('webpack');
const path = require('path');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const libraryName = 'react-grand-tour';
module.exports = function (env) {
let dev = false;
let target = 'node';
let filename = '[name].js';
let outputPath = path.resolve(__dirname, 'build');
if (env) {
if (env.dev) {
dev = true;
}
}
let config = {
NODE_ENV: dev ? JSON.stringify('development') : JSON.stringify('production'),
dev: dev,
};
return {
mode: 'production',
target: target,
entry: {
index: ['./src/index'],
},
cache: true,
output: {
path: outputPath,
filename: filename,
library: libraryName,
libraryTarget: 'umd',
umdNamedDefine: true,
},
optimization: {
minimize: true,
runtimeChunk: false,
},
// Enable sourcemaps for debugging webpack's output.
devtool: 'source-map',
externals: [
{
react: {
commonjs: 'react',
commonjs2: 'react',
amd: 'React',
root: 'React',
},
'react-dom': {
commonjs: 'react-dom',
commonjs2: 'react-dom',
amd: 'ReactDOM',
root: 'ReactDOM',
},
},
],
resolve: {
// Add '.ts' and '.tsx' as resolvable extensions.
extensions: ['.webpack.js', '.web.js', '.ts', '.tsx', '.js'],
unsafeCache: true,
plugins: [new TsconfigPathsPlugin()],
},
module: {
rules: [
{
test: /\.js$/,
use: ['source-map-loader'],
enforce: 'pre',
},
{
test: /\.ts$|\.tsx$/,
loader: 'ts-loader',
},
],
},
plugins: [
new webpack.ProgressPlugin(),
new CleanWebpackPlugin(),
new webpack.DefinePlugin({
'process.env': config,
}),
new BundleAnalyzerPlugin({
analyzerMode: 'static',
openAnalyzer: false,
defaultSizes: 'gzip',
}),
],
};
};