-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
113 lines (105 loc) · 2.78 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
103
104
105
106
107
108
109
110
111
112
113
const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const PATHS = {
root: path.resolve(__dirname, './'),
nodeModules: path.resolve(__dirname, './node_modules'),
src: path.resolve(__dirname, './src'),
dist: path.resolve(__dirname, './dist'),
}
module.exports = (env = {}) => {
console.log({ env });
const isBuild = !!env.build
const isDev = !env.build
const isSourceMap = !!env.sourceMap || isDev
const DEV_SERVER = {
hot: isDev,
hotOnly: isDev,
historyApiFallback: true,
overlay: true,
// stats: 'verbose',
// proxy: {
// '/api': 'http://localhost:3000'
// },
port: 8070
}
return {
cache: true,
devtool: isDev ? 'eval-source-map' : false,
devServer: DEV_SERVER,
context: PATHS.root,
entry: './src/App.tsx',
output: {
path: PATHS.dist,
publicPath: '/',
filename: '[name].[hash].js',
chunkFilename: '[name].[hash].js'
},
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
// Currently we need to add '.ts' to the resolve.extensions array.
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
modules: ['src', 'node_modules'],
},
// Add the loader for .ts files.
module: {
rules: [
{
test: /\.tsx?$/,
include: PATHS.src,
use: [
{
loader: 'ts-loader',
options: {
transpileOnly: true,
compilerOptions: {
'sourceMap': isSourceMap,
'target': isDev ? 'es2015' : 'es5',
'isolatedModules': true,
'noEmitOnError': false,
'removeComments': false
},
},
},
]
}
]
},
optimization: {
// splitChunks: {
// cacheGroups: {
// vendors: {
// test: /[\\/]node_modules[\\/]/,
// name: "vendors",
// chunks: "all",
// },
// }
// },
namedModules: true,
minimize: isBuild
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(isDev ? 'development' : 'production'),
},
}),
new CleanWebpackPlugin(['dist']),
new HtmlWebpackPlugin({
template: './src/index.html'
}),
...(isDev ? [
new webpack.HotModuleReplacementPlugin({
// multiStep: true, // better performance with many files
}),
] : []),
...(isBuild ? [
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
}),
] : []),
]
}
}