-
Notifications
You must be signed in to change notification settings - Fork 14
/
webpack.config.js
84 lines (82 loc) · 2.14 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
const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
module.exports = () => {
const prod = process.env.NODE_ENV === 'production'
const styleLoader = (loaders=[]) => [
prod ? MiniCssExtractPlugin.loader : 'style-loader',
'css-loader',
...loaders
]
return {
mode: prod ? 'production' : 'development',
devtool: prod ? 'source-map' : 'cheap-module-eval-source-map',
entry: './src/App.tsx',
output: {
path: path.resolve('./app'),
filename: prod ? 'js/[name].[contenthash:8].js' : 'js/[name].js',
publicPath: '',
},
module: {
rules: [{
test: /\.(jsx?|tsx?)$/,
exclude: /node_modules/,
use: 'babel-loader'
}, {
test: /\.css$/,
use: styleLoader()
}, {
test: /\.scss$/,
use: styleLoader([{
loader: "sass-loader",
options: {
implementation: require("sass")
}
}])
}, {
test: /\.(jpe?g|png|gif|bmp|svg)$/,
use: {
loader: 'url-loader',
options: {
limit: 8 * 1024,
name: prod ? 'img/[name].[contenthash:8].[ext]' : '[name].[ext]',
},
}
}, {
test: /\.(svg|eot|woff|ttf)$/,
use: {
loader: 'file-loader',
options: {
name: prod ? 'font/[name].[contenthash:8].[ext]' : '[name].[ext]',
}
}
}]
},
resolve: {
modules: ['node_modules', 'src'],
extensions: ['.ts', '.tsx', '.js', '.jsx']
},
devServer: {
contentBase: './app',
disableHostCheck: true,
host: '0.0.0.0',
useLocalIp: true,
open: 'Google Chrome',
hot: true,
publicPath: '/',
historyApiFallback: true
},
plugins: [
new HtmlWebpackPlugin({
template: './src/index.html'
}),
new webpack.EnvironmentPlugin({
...process.env
}),
prod && new MiniCssExtractPlugin({
filename: 'css/[name].[contenthash:8].css'
})
].filter(Boolean)
}
}