-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.common.js
executable file
·106 lines (102 loc) · 2.52 KB
/
webpack.common.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
//path モジュールの読み込み
const path = require('path');
const sass = require('sass');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ImageMinimizerPlugin = require('image-minimizer-webpack-plugin');
module.exports = {
//エントリポイント(デフォルトと同じなので省略可)
entry: './src/index.js',
//出力先
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist'),
//Asset Modules の出力先の指定
assetModuleFilename: 'images/[name][ext]',
publicPath: 'auto'
},
module: {
rules: [
{
test: /\.(js|ts|tsx)$/,
include: /src\/js/,
use: {
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env', { targets: "defaults" }]
]
}
}
},
{
test: /\.(scss|css)$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
},
{
loader: 'css-loader',
options: {
url: true,
// 0 => no loaders (default);
// 1 => postcss-loader;
// 2 => postcss-loader, sass-loader
importLoaders: 2,
sourceMap: true,
},
},
{
loader: 'sass-loader',
options: {
implementation: sass,
sourceMap: true,
sassOptions: {
outputStyle: 'compressed',
},
},
},
],
},
{
test: /\.(jpg|png|svg|woff|woff2|eot|ttf)(\?.*$|$)/,
type: 'asset',
parser: {
dataUrlCondition: {
maxSize: 4 * 1024, // <--- 4kb
},
},
},
],
},
//プラグインの設定
plugins: [
new MiniCssExtractPlugin({
// 抽出する CSS のファイル名
filename: 'site.css',
}),
new CopyWebpackPlugin({
patterns: [{
from: path.resolve(__dirname, 'src/images'),
to: path.resolve(__dirname, 'dist/images')
}]
}),
new ImageMinimizerPlugin({
test: /\.(png|jpe?g)$/i,
minimizer: {
implementation: ImageMinimizerPlugin.squooshMinify,
options: {
encodeOptions: {
mozjpeg: {
quality: 85,
},
oxipng: {
level: 3,
interlace: false,
}
},
},
},
})
]
};