-
Notifications
You must be signed in to change notification settings - Fork 6
/
webpack.dev.js
113 lines (110 loc) · 2.95 KB
/
webpack.dev.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 HtmlWebpackPlugin = require('html-webpack-plugin');
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin')
const path = require('path');
module.exports = {
mode: 'development',
entry: {
app: path.resolve(__dirname, 'harness/index.tsx'),
childApp: path.resolve(__dirname, 'src/index.tsx')
},
output: {
path: path.resolve(__dirname, 'dist')
},
devServer: {
hot: true,
port: 8080
},
devtool: 'inline-source-map',
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.css', '.json'],
},
optimization: {
runtimeChunk: 'single'
},
plugins: [
new HtmlWebpackPlugin({
template: './harness/index.html',
filename: './index.html',
chunks: ['app'],
minify: {
html5: true,
collapseWhitespace: true,
removeComments: true,
removeEmptyAttributes: true
}
}),
new HtmlWebpackPlugin({
template: './src/index.html',
filename: './childApp.html',
chunks: ['childApp'],
minify: {
html5: true,
collapseWhitespace: true,
removeComments: true,
removeEmptyAttributes: true
}
}),
new CleanWebpackPlugin(),
// ensure paths are cased correctly even on windows machines
new CaseSensitivePathsPlugin(),
// create css files for build (different loaders in webpack.dev.js and webpack.prod.js)
new MiniCssExtractPlugin({
filename: '[name].[hash].css',
chunkFilename: '[id].[hash].css'
}),
// run ts type checker in a separate process for faster builds
new ForkTsCheckerWebpackPlugin(),
// compression output bundles for file size
new CompressionPlugin()
],
module: {
rules: [
// transpile js and jsx to es5
{
test: [/\.jsx?$/],
exclude: /node_modules/,
resolve: {
extensions: ['.js', 'jsx']
},
use: {
loader: 'babel-loader',
}
},
// transpile ts and tsx to esnext then to es5 with babel
{
test: /\.tsx?$/,
use: [
{
loader: 'babel-loader',
options: {
cacheDirectory: true
}
},
{
loader: 'ts-loader',
options: {
transpileOnly: true
},
}
],
exclude: /node_modules/,
},
// handle images
{
test: /\.(png|svg|jpg|gif)$/,
// exclude: /(?!node_modules\/@ayx)(node_modules)/,
use: ['file-loader']
},
// handle fonts
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
// exclude: /(?!node_modules\/@ayx)(node_modules)/,
use: ['file-loader']
}
]
},
};