-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
100 lines (94 loc) · 3.25 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
'use strict';
const path = require('path');
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const {WebpackManifestPlugin} = require('webpack-manifest-plugin');
module.exports = (env, argv) => {
const devMode = argv.mode === 'development';
return {
// JavaScript
entry: {
'app': './assets/js/app.js'
},
output: {
filename: '[name].js',
// filename: '[name].[contenthash].js',
// chunkFilename: '[name].[contenthash].js',
path: path.resolve(__dirname, 'public/build'),
publicPath: 'app://build/'
},
// Sass
module: {
rules: [
// Website
{
test: /\.s[ac]ss$/i,
use: [
MiniCssExtractPlugin.loader, // instead of style-loader
'css-loader', // Translates CSS into CommonJS
// 'sass-loader' // Compiles Sass to CSS
{
loader: 'sass-loader',
options: {
implementation: require('sass'), // Prefer: dart-sass
sassOptions: {
fiber: false,
}
}
}
]
}, {
test: /\.(ttf|eot|woff|woff2)$/i,
type: 'asset/resource',
generator: {
filename: 'fonts/' + (devMode ? '[name]_' : '') + '[hash][ext][query]'
}
}, {
test: /\.(gif|png|jpe?g|svg)$/i,
type: 'asset/resource',
generator: {
filename: 'images/' + (devMode ? '[name]_' : '') + '[hash][ext][query]'
}
}
],
},
externals: [
function ({ context, request }, callback) {
let IGNORES = [
'electron', 'electron-store', 'fs'
];
if (IGNORES.indexOf(request) >= 0) {
return callback(null, "require('" + request + "')");
}
callback();
},
],
plugins: [
new webpack.DefinePlugin({
PRODUCTION: (argv.mode === 'production')
}),
new WebpackManifestPlugin(),
new CleanWebpackPlugin({
verbose: false,
cleanOnceBeforeBuildPatterns: ['**/*', '!manifest.json'],
}),
new MiniCssExtractPlugin({
filename: '[name].css',
// filename: '[name].[contenthash].css',
// chunkFilename: '[name].[contenthash].css'
})
],
optimization: {
splitChunks: {
automaticNameDelimiter: '_',
}
},
performance: {
hints: false
},
mode: 'production',
stats: 'errors-warnings',
devtool: 'source-map'
}
};