-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathwebpack.config.js
executable file
·94 lines (79 loc) · 2.06 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
const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const PORT = process.env['PORT'] || '5001'
const OUTPUT = process.env['OUTPUT'] || 'dist'
const PUBLIC_PATH = process.env['PUBLIC_PATH'] || '/'
const isBuild = process.env['BUILD'] === 'true'
const isDev = !isBuild
const cfg = {}
cfg.mode = isBuild ? 'production' : 'development'
cfg.devtool = isBuild ? 'source-map' : undefined
cfg.entry = {
main: root('src', 'app', 'index.tsx')
}
cfg.output = {
path: root(OUTPUT),
publicPath: PUBLIC_PATH,
filename: isBuild ? 'js/[name].[hash].js' : 'js/[name].js',
chunkFilename: isBuild ? '[id].[hash].chunk.js' : '[id].chunk.js',
}
cfg.target = 'web'
cfg.resolve = {
extensions: ['.ts', '.js', '.jsx', '.tsx']
}
cfg.module = {
rules: [
{
test: /\.tsx?$/,
include: root('src', 'app'),
use: {
loader: 'awesome-typescript-loader',
options: {
useCache: true,
useBabel: true,
babelOptions: {
babelrc: false,
plugins: [
['emotion', {
'hoist': true,
'sourceMap': !isBuild,
'autoLabel': !isBuild,
}],
]
},
}
},
},
]
}
cfg.plugins = [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify(isBuild ? 'production' : 'dev'), // To enable React's optimizations
'DEV': JSON.stringify(isDev), // For distinguishing between dev and non-dev mode
}
}),
new HtmlWebpackPlugin({
template: root('src', 'public', 'template.html'),
inject: 'body',
}),
new CopyWebpackPlugin([{
from: root('src', 'public')
}]),
]
cfg.devServer = {
port: PORT,
contentBase: root('src', 'public'),
hot: false,
historyApiFallback: true,
stats: {
warnings: true,
},
}
module.exports = cfg
function root(args) {
args = Array.prototype.slice.call(arguments, 0)
return path.join.apply(path, [__dirname].concat(args))
}