-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.ts
122 lines (111 loc) · 2.82 KB
/
webpack.config.ts
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
114
115
116
117
118
119
120
121
122
import webpack from 'webpack';
import webpackDevServer from 'webpack-dev-server';
import TerserPlugin from 'terser-webpack-plugin';
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import path from 'path';
import CopyPlugin from 'copy-webpack-plugin';
import WorkboxWebpackPlugin from 'workbox-webpack-plugin';
interface Configuration extends webpack.Configuration {
devServer?: webpackDevServer.Configuration;
}
const config = (env: Object, argv: {mode: string}): Configuration => {
const isProduction = argv.mode === 'production';
console.log(`mode = ${argv.mode}`);
// webpack-dev-serverの設定
const devServerConfig: webpackDevServer.Configuration = {
// host: 'localhost', // macだとこれ指定すると繋がらなくなる
open: true,
hot: true,
static: {
directory: path.join(__dirname, 'build'),
},
};
const config: Configuration = {
mode: isProduction ? 'production' : 'development',
devtool: isProduction ? false : 'source-map',
resolve: {
extensions: ['.js', '.ts', '.tsx'],
},
devServer: devServerConfig,
watchOptions: {
aggregateTimeout: 200,
poll: 1000
},
entry: path.resolve('./js/index.tsx'),
output: {
path: path.resolve(`./build/`),
filename: 'main.js',
},
module: {
rules: [
// TypeScript
{
test: /\.tsx?$/,
loader: 'ts-loader',
options: {
transpileOnly: true,
},
},
// CSS
{
test: /\.css/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
url: false,
},
},
],
},
// 画像ファイル
{
test: /\.png/,
use: ['url-loader'],
},
],
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
// ecma: 6,
// warnings: false,
parse: {},
compress: {},
mangle: true,
module: false,
// output: null,
toplevel: false,
// nameCache: null,
ie8: false,
keep_classnames: undefined,
keep_fnames: true,
}
})
],
},
plugins: [
new ForkTsCheckerWebpackPlugin(),
new CopyPlugin({
patterns: [
{
from: './static',
to: '',
},
]
}),
],
}
const workbox = new WorkboxWebpackPlugin.GenerateSW({
maximumFileSizeToCacheInBytes: 500 * 1024 * 1024,
runtimeCaching: [],
});
if(isProduction) {
config.plugins?.push(workbox);
}
return config;
};
export default (env: any, argv: any) => config(env, argv);