-
Notifications
You must be signed in to change notification settings - Fork 4
/
webpack.common.js
125 lines (117 loc) · 2.92 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
'use strict';
const path = require('path');
// Process script files
const ESLintPlugin = require('eslint-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const RemoveEmptyScriptsPlugin = require('webpack-remove-empty-scripts');
// Extract and process CSS chunks
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const postcssPresetEnv = require('postcss-preset-env');
// Process CSS files
const StylelintPlugin = require('stylelint-webpack-plugin');
// Process HTML templates
const HtmlWebpackPlugin = require('html-webpack-plugin');
// Process SVG files
const SpriteLoaderPlugin = require('svg-sprite-loader/plugin');
// Default configuration
const config = {
mode: process.env.NODE_ENV,
context: path.resolve(__dirname, 'src'),
entry: {
vanda: './assets-vanda.js',
fractal: './assets/styles/fractal-preview.scss'
},
output: {
clean: true,
filename: process.env.NODE_ENV === 'production' ? 'scripts/[name].[contenthash].js' : 'scripts/[name].js',
path: path.resolve(__dirname, 'build')
},
optimization: {
minimizer: [
new TerserPlugin({
terserOptions: {
format: {
comments: false,
}
},
extractComments: false,
}),
],
},
module: {
rules: [
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader'
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
postcssPresetEnv()
]
}
}
},
{
loader: 'sass-loader'
}
]
},
{
test: /\.html$/i,
use: [
{
loader: 'html-loader'
}
]
},
{
test: /\.(woff|woff2)$/i,
type: 'asset/resource',
generator: {
filename: 'fonts/[name][ext]'
}
},
{
test: /\.svg$/,
use: [
{
loader: 'svg-sprite-loader',
options: {
extract: true,
spriteFilename: 'svg/vam-sprite.svg',
esModule: false
}
},
{
loader: 'svgo-loader'
}
]
}
]
},
plugins: [
new RemoveEmptyScriptsPlugin(),
new ESLintPlugin(),
new MiniCssExtractPlugin({
filename: process.env.NODE_ENV === 'production' ? 'styles/[name].[contenthash].css' : 'styles/[name].css'
}),
new StylelintPlugin(),
new HtmlWebpackPlugin({
template: 'components/_preview-layouts/_preview-template.html',
filename: path.resolve(__dirname, 'src') + '/components/_preview-layouts/_preview.html'
}),
new SpriteLoaderPlugin({
plainSprite: true,
spriteAttrs: {
class: 's-svg-icon'
}
})
]
};
module.exports = config;