-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.production.config.ts
115 lines (111 loc) · 2.64 KB
/
webpack.production.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
import path from 'path';
import merge from 'webpack-merge';
import commonConfig from './webpack.common.config';
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import TerserPlugin from 'terser-webpack-plugin';
import RemovePlugin from 'remove-files-webpack-plugin';
import sass from 'sass';
const {src, dist} = process.env;
const config = merge(commonConfig, {
cache: {
type: "filesystem",
buildDependencies: {
config: [__filename],
},
},
mode: "production",
optimization: {
chunkIds: "named",
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/].*\.js$/,
name: "my-vendor",
chunks: "all",
},
},
},
minimizer: [
new TerserPlugin({
parallel: true,
terserOptions: {
compress: {
drop_console: true,
},
},
}),
],
},
plugins: [
// new CleanWebpackPlugin(),
new RemovePlugin({
after: {
test: [
{
folder: path.resolve(dist!, "css"),
method: (absoluteItemPath) => {
return new RegExp(/bundle$/, "m").test(absoluteItemPath);
},
recursive: true,
},
{
folder: path.resolve(dist!),
method: (absoluteItemPath) => {
return new RegExp(/\/_.+\.html$/, "m").test(absoluteItemPath);
},
recursive: true,
},
],
},
}),
],
});
config.module!.rules!.push({
test: /\.scss$/,
exclude: /node_modules/,
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
sourceMap: true,
importLoaders: 1,
url: false,
},
},
{
loader: "postcss-loader",
options: {
sourceMap: true,
postcssOptions: {
plugins: [
// ↓ 手動で追加したベンダープレフィックスが削除されるのを防ぐ
require("autoprefixer")({remove:false}),
require("cssnano"),
require("postcss-assets")({
loadPaths: [
path.join(src!, "images"),
path.join(src!, "fonts"),
],
relative: true,
}),
],
},
},
},
{
loader: "sass-loader",
options: {
sourceMap: true,
sassOptions: {
includePaths: [
path.resolve(src!, "styles"),
path.resolve(__dirname, "./node_modules"),
],
},
},
},
],
});
export default config;