-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
78 lines (67 loc) · 1.93 KB
/
webpack.config.js
File metadata and controls
78 lines (67 loc) · 1.93 KB
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
const defaultConfig = require("@wordpress/scripts/config/webpack.config");
const path = require("path");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const ZipPlugin = require("zip-webpack-plugin");
module.exports = (env, argv) => {
if (env && env.package) {
return [buildConfig, packageConfig];
}
return buildConfig;
};
buildConfig = {
...defaultConfig,
entry: {
// SDL Block Scripts
//
// Note: Index will import style.scss, edit.js and icon.js too -> webpack will compile this
"blocks/sdl/index": "./assets/blocks/sdl/index.js",
// Adminpanel
"admin/admin-styles": "./assets/admin/admin.scss",
"admin/admin-scripts": "./assets/admin/admin.js",
},
output: {
path: path.resolve(__dirname, "dist"),
filename: "[name].js",
},
};
BUILD_FILES = [
"admin",
"blocks",
"dist",
"languages",
"lists",
"setup",
"templates",
"readme.txt",
"neofix_sdl.php",
];
const generatedPatterns = BUILD_FILES.map((folder) => ({
from: path.resolve(__dirname, folder),
to: folder,
}));
const packageConfig = {
mode: "production",
entry: {}, // No compilation needed
output: {
path: path.resolve(__dirname, "build/release"),
filename: "[name].js", // Placeholder
},
plugins: [
// 1. Clean the release folder
new CleanWebpackPlugin(),
// 2. Copy files from source folders to dist
new CopyWebpackPlugin({
patterns: [...generatedPatterns],
}),
// 3. Bundle everything into a ZIP
new ZipPlugin({
// **NEW OPTION:** Specifies the directory where the zip file will be saved.
path: path.resolve("build"), // Example: Go up one level, then into 'release' folder
// filename remains the name of the zip file
filename: "simple-downloads-list.zip",
// pathPrefix remains the root folder *inside* the zip file
pathPrefix: "simple-downloads-list",
}),
],
};