-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
77 lines (69 loc) · 1.99 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
const path = require("path");
const fs = require("fs");
const defaultConfig = require("@wordpress/scripts/config/webpack.config");
const BrowserSyncPlugin = require("browser-sync-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
module.exports = (env, { mode }) => {
const is_production = mode === "production";
const is_development = !is_production;
if (is_production) {
// eslint-disable-next-line global-require
require("./config/utils/regenerate-setup-file.v1")();
const BUILD_PATH = path.resolve(process.cwd(), "build");
if (fs.existsSync(BUILD_PATH)) {
fs.rmSync(BUILD_PATH, { recursive: true, force: true });
fs.mkdirSync(BUILD_PATH, { recursive: true, force: true });
}
}
const config = {
...defaultConfig,
// entry: {
// // "dbe.blocks.editor.build": "./src/scss/editor.scss",
// // "dbe.blocks.frontend.build": "./src/scss/frontend.scss",
// ...defaultConfig.entry,
// },
entry: defaultConfig.entry(),
module: {
...defaultConfig.module,
rules: [
...defaultConfig.module.rules,
{
test: /\.svg$/,
use: ["@svgr/webpack", "url-loader"],
},
],
},
resolve: {
symlinks: false,
extensions: ["js", "jsx"],
alias: {
...defaultConfig.resolve.alias,
"@": path.resolve(__dirname, "src/"),
},
...defaultConfig.resolve,
},
plugins: [...defaultConfig.plugins],
};
config.entry["dbe.blocks.editor.build"] = "./src/scss/editor.scss";
config.entry["dbe.blocks.frontend.build"] = "./src/scss/frontend.scss";
if (is_development) {
config.plugins.push(
new BrowserSyncPlugin({
host: "localhost",
port: 3005,
proxy: "http://dbe.test/",
})
);
}
config.plugins.push(
new CopyWebpackPlugin({
patterns: [
{
from: "**/*.svg",
context: process.env.WP_SRC_DIRECTORY,
},
],
})
);
return config;
};