-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
94 lines (90 loc) · 2.35 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
var webpack = require('webpack')
var path = require('path')
var package = require('./package.json')
var MiniCssExtractPlugin = require('mini-css-extract-plugin')
var { CleanWebpackPlugin } = require('clean-webpack-plugin')
var isProduction = process.argv.indexOf('-p') >= 0 || process.env.NODE_ENV === 'production'
var sourcePath = path.join(__dirname, './src')
var outPath = path.join(__dirname, './dist')
var HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
context: sourcePath,
entry: {
trains: './index.ts',
},
output: {
path: outPath,
publicPath: isProduction ? '/trains/' : '/',
filename: isProduction ? '[contenthash].js' : '[name].js',
},
target: 'web',
resolve: {
extensions: ['.js', '.ts'],
mainFields: ['module', 'browser', 'main'],
alias: {
trains: path.resolve(__dirname, 'src/trains/'),
},
},
module: {
rules: [
{
test: /\.tsx?$/,
use: [
!isProduction && {
loader: 'babel-loader',
},
'ts-loader',
].filter(Boolean),
},
{
test: /\.css$/,
exclude: /\.module.(s(a|c)ss)$/,
loader: [!isProduction ? 'style-loader' : MiniCssExtractPlugin.loader, 'css-loader'],
},
],
},
plugins: [
new webpack.EnvironmentPlugin({
NODE_ENV: 'development',
DEBUG: false,
}),
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: '[hash].css',
disable: !isProduction,
}),
new HtmlWebpackPlugin({
template: 'index.html',
minify: {
minifyJS: true,
minifyCSS: true,
removeComments: true,
useShortDoctype: true,
collapseWhitespace: true,
collapseInlineTagWhitespace: true,
},
append: {
head: `<script src="//cdn.polyfill.io/v3/polyfill.min.js"></script>`,
},
meta: {
title: package.name,
description: package.description,
keywords: Array.isArray(package.keywords) ? package.keywords.join(',') : undefined,
},
}),
],
devServer: {
publicPath: '/',
contentBase: sourcePath,
hot: true,
inline: true,
historyApiFallback: true,
stats: 'minimal',
clientLogLevel: 'warning',
},
devtool: isProduction ? 'hidden-source-map' : 'cheap-module-eval-source-map',
node: {
fs: 'empty',
net: 'empty',
},
}