-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
67 lines (61 loc) · 1.95 KB
/
webpack.config.js
File metadata and controls
67 lines (61 loc) · 1.95 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
/*
* Erweiterte Webpack-Konfiguration für WordPress-Block-Plugins
* (z. B. für zusätzliche Einträge und SVG-Handling).
*
* ⚙️ Hinweis:
* Diese Datei wird **nur verwendet**, wenn sie in der package.json explizit angegeben ist:
*
* "scripts": {
* "build": "webpack --config webpack.config.js",
* "start": "webpack --watch --config webpack.config.js"
* }
*
* Wenn du diese Angabe weglässt, verwendet WordPress standardmässig
* die interne Konfiguration von @wordpress/scripts – diese Datei wird dann ignoriert.
*/
const defaultConfig = require("@wordpress/scripts/config/webpack.config");
const path = require("path");
// Entferne die ursprüngliche Regel für SVG-Dateien aus der Standardkonfiguration.
// Dadurch vermeiden wir Konflikte und können eigene Optionen (z. B. SVGR) definieren.
const filteredRules = defaultConfig.module.rules.filter(
(rule) => !rule.test?.toString().includes("svg")
);
module.exports = {
...defaultConfig,
// Explizite Einträge für Editor/Frontend (JS & SCSS)
entry: {
'editor-script': path.resolve(__dirname, "src/js/editor.js"),
'frontend-script': path.resolve(__dirname, "src/js/frontend.js"),
'editor-style': path.resolve(__dirname, "src/css/editor.scss"),
'frontend-style': path.resolve(__dirname, "src/css/frontend.scss"),
},
output: {
path: path.resolve(__dirname, "build"),
filename: "[name].js",
},
module: {
rules: [
...filteredRules,
/*
* 🔧 Eigene SVG-Behandlung:
* SVG-Dateien werden mit @svgr/webpack als React-Komponenten importiert,
* statt als statische Dateien. Dadurch können sie direkt im JSX verwendet werden:
*
* import { ReactComponent as Icon } from "../assets/icons/star.svg";
* <Icon />
*
* Das ist besonders nützlich für Gutenberg-Icons oder UI-Komponenten.
*/
{
test: /\.svg$/i,
issuer: /\.[jt]sx?$/,
use: [
{
loader: '@svgr/webpack',
options: { icon: true },
},
],
},
],
},
};