-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
118 lines (117 loc) · 3.88 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
const path = require('path'); //node.jsにデフォルトで入っているpathモジュールを使用
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
module.exports = {
mode: 'development', //デフォルト: production, 開発環境ではdevelopment
devtool: 'source-map', //jsソースマップの出力
entry: './src/scripts/main.js',
output: {
path: path.resolve(__dirname, './dist'), //path.resolveで絶対パスを取得、第一引数(__dirname)が現在の階層を表す
filename: 'scripts/[name]-[hash].js', // 出力されるファイル名
},
module: {
rules: [
{
test: /\.(ts|tsx)/,
exclude: /node_modules/,
use: [
{
loader: 'ts-loader', //typescriptの読み込み
},
],
},
{
test: /\.js/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env', {'targets': '> 0.25%, not dead'}], //公式のサポートが終了しておらず、0.25%以上のシェアがあるブラウザを対象とする。
'@babel/preset-react',
],
},
},
],
},
{
test: /\.(css|scss|sass)$/, //.cssを検知する
use: [
{
loader: MiniCssExtractPlugin.loader, //loaderは下から上に適用されるので、css-loader, MiniCssExtractPlugin.loaderの順になる。
},
{
loader: 'css-loader', //.cssが見つかれば、このルールを適用する。
options: {
sourceMap: true,
}
},
{
loader: 'sass-loader',
options: {
sassOptions: {
outputStyle: 'expanded',
},
},
},
],
},
{
test: /\.(png|jpg|jpeg)/,
use: [
{
loader: 'file-loader',
options: {
esModule: false,
name: 'images/[name]-[hash].[ext]', //[name].[ext]で元のファイル名と拡張子のまま出力する
publicPath: '/',
}
},
{
loader: 'image-webpack-loader',
options: {
mozjpeg: {
progressive: true,
quality: 65,
}
}
},
],
},
{
test: /\.pug/,
use: [
{
loader: 'html-loader',
},
{
loader: 'pug-html-loader',
options: {
pretty: true,
}
},
]
},
],
},
plugins: [
new MiniCssExtractPlugin({
filename: './styles/[name]-[hash].css', //出力後のcssファイル名を指定
}),
new HtmlWebpackPlugin({
template: './src/templates/index.pug',
filename: 'index.html',
}),
new HtmlWebpackPlugin({
template: './src/templates/access.pug', //htmlをビルドする場合はindex.html
filename: 'access.html',
}),
new HtmlWebpackPlugin({
template: './src/templates/members/taro.pug', //htmlをビルドする場合はindex.html
filename: 'members/taro.html',
}),
new CleanWebpackPlugin(),
],
}