-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
106 lines (102 loc) · 3.5 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
// customized from https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/config/webpack.config.js
// TODO: babel polyfills or runtime
// TODO: server setup
const path = require('path')
const webpack = require('webpack')
const dev = process.env.NODE_ENV === 'development'
const buildDir = path.resolve('lib')
const srcDir = path.resolve('src')
function formatWindowsUri(path) {
return path.replace(/\\/g, '/')
}
module.exports = /** @type {import('webpack').Configuration} */ ({
entry: [path.resolve(srcDir, 'index.ts')],
output: {
path: buildDir,
// filename is the template for entry points
// chunk is the template for generated (split) assets from the entry point
// they don't really have any meaningful differences for consumers, as long as their names don't collide
filename: dev ? '[name].js' : '[name].[chunkhash:6].js',
chunkFilename: dev ? '[name].chunk.js' : '[name].[chunkhash:6].chunk.js',
// useful comments in dev mode about where the module was located
pathinfo: dev,
// the template generator for sourcemapped files' paths in browser dev tools
devtoolModuleFilenameTemplate(info) {
return formatWindowsUri(path.relative(srcDir, info.absoluteResourcePath))
},
},
mode: dev ? 'development' : 'production',
resolve: {
mainFields: ['module', 'main'],
extensions: ['.ts', '.js', '.json'],
modules: ['node_modules', srcDir],
},
module: {
// makes missing exports an error instead of warning
strictExportPresence: true,
rules: [
{
oneOf: [
{
test: /\.[tj]s$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
// ignore .babelrc and babel.config.js
babelrc: false,
configFile: false,
// emit source maps
sourceMaps: true,
// creates a cache directory (babel-laoder ONLY)
cacheDirectory: true,
// minify and cache the minification step in PROD
compact: !dev,
cacheCompression: !dev,
presets: [
[
'@babel/preset-env',
{
loose: true,
modules: false,
targets: {
node: 10,
},
},
],
'@babel/preset-typescript',
],
plugins: [
// decorators have to come before class proeprties
[
'@babel/plugin-proposal-decorators',
// @decorate | INSTEAD OF:
// export foo | export @decorate foo
{
decoratorsBeforeExport: true,
},
],
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-throw-expressions',
],
},
},
],
},
],
},
],
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(dev ? 'development' : 'production'),
}),
],
optimization: {
minimize: false,
},
// always use source-map to allow CSS source maps in dev mode
devtool: 'source-map',
performance: false,
})