-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
107 lines (101 loc) · 2.78 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
const path = require('path');
const glob = require("glob");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const RemoveEmptyScriptsPlugin = require('webpack-remove-empty-scripts');
const ImageminPlugin = require('imagemin-webpack-plugin').default
module.exports = (env) => {
let entryJsAdmin, entryJsPublic;
if ( env.bundlejs === 'true' ) {
entryJsAdmin = {
'public/js/bundle': glob.sync(path.resolve(__dirname, './assets/src/public/js/**/*.js'))
};
entryJsPublic = {
'admin/js/admin-bundle': glob.sync(path.resolve(__dirname, './assets/src/admin/js/**/*.js'))
};
} else {
entryJsAdmin = glob
.sync(path.resolve(__dirname, 'assets/src/admin/**/*.js'))
.reduce((x, y) => Object.assign(x, {
['admin/js/' + path.basename(y, ".js")]: y,
}), {});
entryJsPublic = glob
.sync(path.resolve(__dirname, 'assets/src/public/**/*.js'))
.reduce((x, y) => Object.assign(x, {
['public/js/' + path.basename(y, ".js")]: y,
}), {});
}
return {
entry: {
...entryJsAdmin,
...entryJsPublic,
'public/css/master': glob.sync(path.resolve(__dirname, './assets/src/public/sass/*')),
'admin/css/admin-master': glob.sync(path.resolve(__dirname, './assets/src/admin/sass/*')),
},
output: {
path: path.join(__dirname, './assets/dist'),
filename: '[name].min.js'
},
plugins: [
new RemoveEmptyScriptsPlugin(),
new MiniCssExtractPlugin({
filename: '[name].css'
}),
// new ImageminPlugin({
// pngquant: {
// quality: '80'
// },
// externalImages: {
// context: '.', // Important! This tells the plugin where to "base" the paths at
// sources: glob.sync(path.resolve(__dirname, './assets/src/images/*')),
// destination: path.resolve(__dirname,'./assets/dist/images' ),
// fileName: '[name].[ext]' // (filePath) => filePath.replace('jpg', 'webp') is also possible
// }
// }),
],
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
},
{
test: /\.s?[c]ss$/i,
exclude: /(node_modules|bower_components)/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader'
]
},
{
test: /\.sass$/i,
exclude: /(node_modules|bower_components)/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'sass-loader',
options: {
sassOptions: { indentedSyntax: true }
}
}
]
},
]
},
optimization: {
minimizer: [
// For webpack@5 you can use the `...` syntax to extend existing minimizers (i.e. `terser-webpack-plugin`), uncomment the next line
`...`,
new CssMinimizerPlugin(),
],
},
}
};