-
Notifications
You must be signed in to change notification settings - Fork 13
/
webpack.base.config.js
99 lines (96 loc) · 2.64 KB
/
webpack.base.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
const path = require('path');
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const webpack = require('webpack');
const SRC_DIR = 'src';
const BUILD_DIR = 'dist';
const STATICS_DIR = path.join(BUILD_DIR, 'statics');
module.exports = (debug, local) => ({
context: path.join(process.cwd(), SRC_DIR),
name: 'client',
mode: local ? 'development' : 'production',
output: {
path: path.join(process.cwd(), STATICS_DIR),
publicPath: 'http://localhost:3201/',
pathinfo: debug,
filename: `[name].bundle${debug ? '' : '.min'}.js`,
hotUpdateMainFilename: 'updates/[hash].hot-update.json',
umdNamedDefine: true,
library: 'repluggable',
libraryTarget: 'umd',
globalObject: "(typeof self !== 'undefined' ? self : this)",
},
resolve: {
modules: ['node_modules', path.join(process.cwd(), SRC_DIR)],
extensions: ['.js', '.ts', '.tsx', '.json'],
mainFields: ['browser', 'module', 'main'],
alias: {},
},
resolveLoader: {
modules: ['node_modules'],
},
optimization: {
minimize: !debug,
concatenateModules: !local,
minimizer: [
new TerserPlugin({
parallel: true,
cache: true,
sourceMap: true,
terserOptions: {
output: {
ascii_only: true,
},
keep_fnames: false,
},
}),
],
},
plugins: [
new CaseSensitivePathsPlugin(),
new webpack.LoaderOptionsPlugin({
minimize: !debug,
}),
...(local ? [new webpack.HotModuleReplacementPlugin()] : []),
],
devtool: local ? 'cheap-module-eval-source-map' : false,
module: {
strictExportPresence: true,
rules: [
{
test: /\.(ts|tsx)$/,
use: [
{
loader: 'ts-loader',
options: {
compilerOptions: { module: 'esnext', moduleResolution: 'node', declaration: false, declarationMap: false, },
},
},
],
},
],
},
stats: 'none',
node: { fs: 'empty', net: 'empty', tls: 'empty', __dirname: true },
performance: { hints: false },
target: 'web',
entry: { repluggable: 'index' },
externals: {
react: 'React',
'react-dom': 'ReactDOM',
lodash: '_',
'react-redux': 'ReactRedux',
redux: 'Redux',
},
devServer: {
contentBase: path.join(process.cwd(), STATICS_DIR),
compress: true,
port: 3201,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
'Access-Control-Allow-Headers':
'X-Requested-With, content-type, Authorization',
},
},
});