-
Notifications
You must be signed in to change notification settings - Fork 44
/
webpack.config.js
138 lines (124 loc) · 3.02 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
const fs = require("fs");
const path = require("path");
const glob = require("glob");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const wpPot = require("wp-pot");
const { Z_FIXED } = require("zlib");
const outputEntry = () => {
let paths = {};
glob.sync("./src/js/view/*").reduce((acc, file) => {
let fileName = path.parse(file).name;
if (fileName.charAt(0) !== "_") {
paths[path.join("js", "view", fileName)] = file;
}
}, {});
glob.sync("./src/js/edit/*").reduce((acc, file) => {
let fileName = path.parse(file).name;
if (fileName.charAt(0) !== "_") {
paths[path.join("js", "edit", fileName)] = file;
}
}, {});
glob.sync("./src/css/view/*").reduce((acc, file) => {
let fileName = path.parse(file).name;
if (fileName.charAt(0) !== "_") {
paths[path.join("css", "view", fileName)] = file;
}
}, {});
return paths;
};
const removeEntry = () => {
entry = [];
glob.sync("./src/css/view/*").reduce((acc, file) => {
let fileName = path.parse(file).name;
if (fileName.charAt(0) !== "_") {
entry.push(path.join("css", "view", fileName.concat(".js")));
entry.push(path.join("css", "view", fileName.concat(".min.js")));
}
}, {});
return entry;
};
module.exports = (env, argv) => {
if (argv.mode === "production") {
// Generate .pot on production build only
wpPot({
destFile: "languages/essential-addons-for-elementor-lite.pot",
domain: "essential-addons-for-elementor-lite",
package: "Essential Addons For Elementor Lite",
includePOTCreationDate: false,
src: "**/*.php",
});
}
return {
stats: "minimal",
entry: outputEntry(),
output: {
path: path.resolve(__dirname, "assets/front-end/"),
filename:
argv.mode === "production" ? "[name].min.js" : "[name].js",
},
plugins: [
new MiniCssExtractPlugin({
filename:
argv.mode === "production"
? "[name].min.css"
: "[name].css",
}),
{
apply(compiler) {
compiler.hooks.shouldEmit.tap(
"removeStylesFromOutput",
(compilation) => {
removeEntry(argv).forEach((entry) => {
delete compilation.assets[entry];
});
return true;
}
);
},
},
{
apply: (compiler) => {
compiler.hooks.afterEmit.tap("postBuild", (compilation) => {
const dir =
"./../../uploads/essential-addons-elementor";
fs.stat(dir, (err, stats) => {
if (stats?.isDirectory()) {
fs.readdir(dir, (err, files) => {
if (err) throw err;
for (let file of files) {
fs.unlink(
path.join(dir, file),
(err) => {
if (err) throw err;
}
);
}
});
}
});
});
},
},
],
module: {
rules: [
{
test: /\.(js)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
},
},
{
test: /\.(scss)$/,
use: [
MiniCssExtractPlugin.loader,
{ loader: "css-loader", options: { url: false } },
"postcss-loader",
"sass-loader",
],
},
],
},
};
};