forked from xaviranik/boostimer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
100 lines (96 loc) · 2.72 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
const fs = require("fs");
const path = require("path");
const defaultConfig = require("@wordpress/scripts/config/webpack.config");
const DependencyExtractionWebpackPlugin = require("@wordpress/dependency-extraction-webpack-plugin");
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const FixStyleOnlyEntriesPlugin = require("webpack-fix-style-only-entries");
const PROD = process.env.NODE_ENV === "production";
const coreModule = {
...defaultConfig,
entry: {
core: "./src/index.js",
},
output: {
path: path.resolve(__dirname, "dist"),
filename: "[name].js",
publicPath: "/wp-content/plugins/boostimer/dist/",
// chunkFilename: 'chunks/[name].js',
},
resolve: {
alias: {
...defaultConfig.resolve.alias,
"@": path.resolve("./src/"),
},
},
plugins: [
// remove the plugin, next insert our own logic
...defaultConfig.plugins.filter(
(plugin) =>
plugin.constructor.name !== "DependencyExtractionWebpackPlugin"
),
new DependencyExtractionWebpackPlugin({
injectPolyfill: true,
requestToExternal(request) {
// remove WordPress externals, except...
// api-fetch, because it sets the API fetching defaults
if (request !== "@wordpress/api-fetch") {
return "";
}
},
}),
],
optimization: {
...defaultConfig.optimization,
minimize: PROD,
minimizer: [new UglifyJsPlugin(), new OptimizeCSSAssetsPlugin()],
splitChunks: {
chunks: "all",
name: "vendors",
cacheGroups: {
...defaultConfig.optimization.splitChunks.cacheGroups,
vendor: {
test: /[\\/]node_modules[\\/]/,
name: "vendors",
chunks: "all",
},
},
},
},
};
const mainModule = {
mode: process.env.NODE_ENV === "production" ? "production" : "development",
entry: {
"js/admin": "./assets/src/js/admin.js",
"js/frontend": "./assets/src/js/frontend.js",
"css/frontend": "./assets/src/scss/frontend.scss",
},
output: {
path: path.resolve(__dirname, "assets"),
filename: PROD ? "[name].min.js" : "[name].js",
},
optimization: {
minimize: PROD,
minimizer: [new UglifyJsPlugin(), new OptimizeCSSAssetsPlugin()],
},
module: {
rules: [
{
test: /\.scss$/,
exclude: /node_modules/,
use: [
{
loader: "file-loader",
options: {
outputPath: "css/",
name: PROD ? "[name].min.css" : "[name].css",
},
},
"sass-loader",
],
},
],
},
plugins: [new FixStyleOnlyEntriesPlugin()],
};
module.exports = [coreModule, mainModule];