-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.ts
109 lines (102 loc) · 2.37 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
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 CopyWebpackPlugin from 'copy-webpack-plugin';
interface Configuration extends webpack.Configuration {
devServer?: webpackDevServer.Configuration;
}
const isProduction = process.env.NODE_ENV === 'production';
const commonConfig: Partial<Configuration> = {
mode: isProduction ? 'production' : 'development',
devtool: isProduction ? 'source-map' : 'cheap-source-map',
resolve: {
extensions: ['.js', '.ts', '.tsx'],
},
};
// webpack-dev-serverの設定
const devServerConfig: webpackDevServer.Configuration = {
contentBase: 'docs',
host: 'localhost',
open: true,
hot: true,
};
const config: Configuration = {
...commonConfig,
devServer: devServerConfig,
entry: path.resolve('./js/index.tsx'),
output: {
path: path.resolve(`docs/`),
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'],
},
],
},
node: {
fs: 'empty',
},
optimization: {
minimizer: [
new TerserPlugin({
terserOptions: {
ecma: 6,
warnings: false,
parse: {},
compress: {},
mangle: true, // Note `mangle.properties` is `false` by default.
module: false,
// output: null,
toplevel: false,
// nameCache: null,
ie8: false,
keep_classnames: undefined,
keep_fnames: false,
safari10: true,
},
}),
],
},
plugins: [
new ForkTsCheckerWebpackPlugin({
useTypescriptIncrementalApi: true,
tsconfig: './tsconfig.json',
checkSyntacticErrors: true,
reportFiles: ['src/**'],
}),
new CopyWebpackPlugin([
{
from: './static',
to: '',
},
]) as any,
],
};
export default [config];