-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.mjs
109 lines (107 loc) · 2.55 KB
/
webpack.config.mjs
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
import path from 'path'
import yargs from 'yargs'
import webpack from 'webpack'
import HtmlWebpackPlugin from 'html-webpack-plugin'
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import RemoveEmptyScriptsPlugin from 'webpack-remove-empty-scripts'
import TerserPlugin from 'terser-webpack-plugin'
const __dirname = path.dirname(new URL(import.meta.url).pathname)
const {argv} = yargs(process.argv.slice(2)).options({
'media-query': {
type: 'array',
default: [],
alias: 'mq',
},
'pseudo-element': {
type: 'array',
default: [],
alias: 'pe',
},
'pseudo-class': {
type: 'array',
default: [],
alias: 'pc',
},
'property': {
type: 'array',
default: [],
alias: 'p',
},
'value': {
type: 'array',
default: [],
alias: 'v',
},
'vendor-prefix': {
type: 'array',
default: [],
alias: 'vp',
},
})
export default {
mode: 'development',
entry: {
style: path.join(__dirname, 'src/style.scss'),
script: path.join(__dirname, 'src/script.js'),
},
output: {
filename: '[name].js',
},
module: {
rules: [
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
url: false,
},
},
'sass-loader',
],
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
],
},
optimization: {
minimizer: [
new TerserPlugin({
extractComments: false,
terserOptions: {
output: {
comments: /^!|@preserve|@license|@cc_on|@author/i,
},
},
}),
],
},
plugins: [
new webpack.DefinePlugin({
css: {
mediaQueries: JSON.stringify(argv['media-query']),
pseudoElements: JSON.stringify(argv['pseudo-element']),
pseudoClasses: JSON.stringify(argv['pseudo-class']),
properties: JSON.stringify(argv['property']),
values: JSON.stringify(argv['value']),
vendorPrefixes: JSON.stringify(argv['vendor-prefix']),
},
}),
new HtmlWebpackPlugin({
title: '',
meta: [
{'charset': 'utf-8'},
{'http-equiv': 'X-UA-Compatible', 'content': 'IE=edge'},
{'name': 'viewport', 'content': 'width=device-width, initial-scale=1'},
],
hash: true,
}),
new MiniCssExtractPlugin(),
new RemoveEmptyScriptsPlugin(),
],
}