-
Notifications
You must be signed in to change notification settings - Fork 20
/
webpack.config.js
123 lines (117 loc) · 2.45 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
119
120
121
122
123
/*
* Output configuration:
*
* JavaScript files in src/scripts will be compiled to the following directory:
* javascripts/theme.js
*
* CSS files in src/styles will be compiled to the following directory:
* stylesheets/theme.css
*
* Webfonts from node_modules will be copied to the following directory:
* stylesheets/webfonts
*
* Images from src/images will be copied to the following directory:
* stylesheets/images
*
* SVG images from src/images will be embedded in the CSS file if they are less 10 KB.
*/
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
// Define rules for compiling JavaScript
const jsRule = {
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
};
// Define rules for compiling SCSS
const scssRule = {
test: [/\.scss$/],
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
sourceMap: true,
url: true
},
},
{
loader: "postcss-loader",
options: {
postcssOptions: {
plugins: [
["autoprefixer", { grid: true }],
],
},
}
},
{
loader: 'sass-loader',
options: {
sourceMap: true
},
},
],
};
// Define rules for handling images
const imageRule = {
test: /\.(png|jpe?g|gif)$/i, // Exclude svg from this rule
type: 'asset/resource',
generator: {
filename: 'images/[name][ext]',
},
};
// Define rules for embedding SVG images (< 10 KB)
const svgRule = {
test: /\.svg$/i,
type: 'asset',
parser: {
dataUrlCondition: {
maxSize: 10 * 1024, // 10 KB
},
},
generator: {
filename: 'images/[name][ext]',
},
};
module.exports = {
target: ['web', 'es5'],
entry: './src/index.js',
devtool: 'source-map',
output: {
path: path.resolve(__dirname, './stylesheets'),
filename: '../javascripts/theme.js',
publicPath: '',
},
module: {
rules: [
jsRule,
scssRule,
imageRule,
svgRule,
],
},
plugins:[
new MiniCssExtractPlugin({
filename: `theme.css`,
}),
],
optimization: {
minimizer: [new CssMinimizerPlugin({
minimizerOptions: {
preset: [
"default",
{
colormin: { exclude: true },
},
],
},
})],
}
}