piral-cli-webpack5 0.14.5-beta.3344 → 0.14.6-beta.3361
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -4
- package/extend-config.js +40 -8
- package/lib/enhancers/html5-entry-webpack-config-enhancer/index.js +11 -1
- package/lib/enhancers/html5-entry-webpack-config-enhancer/index.js.map +1 -1
- package/package.json +3 -3
- package/src/enhancers/html5-entry-webpack-config-enhancer/index.ts +11 -1
package/README.md
CHANGED
|
@@ -42,10 +42,6 @@ Right now it includes:
|
|
|
42
42
|
|
|
43
43
|
As such it should be prepared to include assets (images, videos, ...), stylesheets (CSS and SASS), and work with TypeScript.
|
|
44
44
|
|
|
45
|
-
> Right now the output of this plugin is for the **v1** pilet schema only!
|
|
46
|
-
|
|
47
|
-
No support for the legacy **v0** pilet schema.
|
|
48
|
-
|
|
49
45
|
### Customizing
|
|
50
46
|
|
|
51
47
|
You can still leverage your own `webpack.config.js`. Either just export *what you want to have overwritten*, e.g.,
|
package/extend-config.js
CHANGED
|
@@ -2,7 +2,11 @@ function changePlugin(config, classRef, cb) {
|
|
|
2
2
|
config.module.plugins = config.module.plugins
|
|
3
3
|
.map((plugin) => {
|
|
4
4
|
if (plugin instanceof classRef) {
|
|
5
|
-
|
|
5
|
+
if (typeof cb === 'function') {
|
|
6
|
+
return cb(plugin);
|
|
7
|
+
} else {
|
|
8
|
+
return cb;
|
|
9
|
+
}
|
|
6
10
|
}
|
|
7
11
|
|
|
8
12
|
return plugin;
|
|
@@ -17,7 +21,11 @@ function changeRule(config, name, cb) {
|
|
|
17
21
|
const uses = rule.use || [];
|
|
18
22
|
|
|
19
23
|
if (uses.some((m) => m && (m === loaderPath || (typeof m === 'object' && m.loader === loaderPath)))) {
|
|
20
|
-
|
|
24
|
+
if (typeof cb === 'function') {
|
|
25
|
+
return cb(rule);
|
|
26
|
+
} else {
|
|
27
|
+
return cb;
|
|
28
|
+
}
|
|
21
29
|
}
|
|
22
30
|
|
|
23
31
|
return rule;
|
|
@@ -31,9 +39,17 @@ function changeLoader(config, name, cb) {
|
|
|
31
39
|
changeRule(config, name, (rule) => {
|
|
32
40
|
rule.use = rule.use.map((m) => {
|
|
33
41
|
if (m === loaderPath) {
|
|
34
|
-
|
|
42
|
+
if (typeof cb === 'function') {
|
|
43
|
+
return cb({ loader: m });
|
|
44
|
+
} else {
|
|
45
|
+
return cb;
|
|
46
|
+
}
|
|
35
47
|
} else if (m.loader === loaderPath) {
|
|
36
|
-
|
|
48
|
+
if (typeof cb === 'function') {
|
|
49
|
+
return cb(m);
|
|
50
|
+
} else {
|
|
51
|
+
return cb;
|
|
52
|
+
}
|
|
37
53
|
} else {
|
|
38
54
|
return m;
|
|
39
55
|
}
|
|
@@ -97,22 +113,38 @@ module.exports = function (override) {
|
|
|
97
113
|
);
|
|
98
114
|
}
|
|
99
115
|
|
|
100
|
-
if ('
|
|
101
|
-
|
|
116
|
+
if ('updateRules' in override && Array.isArray(override.updateRules)) {
|
|
117
|
+
override.updateRules.forEach((def) => {
|
|
118
|
+
if (typeof def.name === 'string' && def.rule) {
|
|
119
|
+
changeRule(config, def.name, def.rule);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
102
122
|
}
|
|
103
123
|
|
|
104
124
|
if ('removeRules' in override && Array.isArray(override.removeRules)) {
|
|
105
125
|
override.removeRules.forEach((rule) => changeRule(config, rule, () => undefined));
|
|
106
126
|
}
|
|
107
127
|
|
|
108
|
-
if ('
|
|
109
|
-
config.
|
|
128
|
+
if ('rules' in override && Array.isArray(override.rules)) {
|
|
129
|
+
config.module.rules.push(...override.rules);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if ('updatePlugins' in override && Array.isArray(override.updatePlugins)) {
|
|
133
|
+
override.updatePlugins.forEach((def) => {
|
|
134
|
+
if (def.type && def.rule) {
|
|
135
|
+
changePlugin(config, def.type, def.plugin);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
110
138
|
}
|
|
111
139
|
|
|
112
140
|
if ('removePlugins' in override && Array.isArray(override.removePlugins)) {
|
|
113
141
|
override.removePlugins.forEach((plugin) => changePlugin(config, plugin, () => undefined));
|
|
114
142
|
}
|
|
115
143
|
|
|
144
|
+
if ('plugins' in override && Array.isArray(override.plugins)) {
|
|
145
|
+
config.plugins.push(...override.plugins);
|
|
146
|
+
}
|
|
147
|
+
|
|
116
148
|
if ('change' in override && typeof override.change === 'function') {
|
|
117
149
|
config = override.change(config);
|
|
118
150
|
}
|
|
@@ -11,7 +11,17 @@ const html5EntryWebpackConfigEnhancer = (options) => (compilerOptions) => {
|
|
|
11
11
|
const [template] = (0, helpers_1.getTemplates)(entry);
|
|
12
12
|
if (template) {
|
|
13
13
|
const src = (0, path_1.dirname)(template);
|
|
14
|
-
const
|
|
14
|
+
const html = (0, fs_1.readFileSync)(template, 'utf8');
|
|
15
|
+
const templateContent = (0, cheerio_1.load)(
|
|
16
|
+
// try to replace ejs tags, if any
|
|
17
|
+
html.replace(/<%=([\w\W]*?)%>/g, function (match, group) {
|
|
18
|
+
try {
|
|
19
|
+
return eval(group);
|
|
20
|
+
}
|
|
21
|
+
catch (_a) {
|
|
22
|
+
return match;
|
|
23
|
+
}
|
|
24
|
+
}));
|
|
15
25
|
const entries = (0, helpers_1.extractParts)(templateContent).map((entry) => (0, path_1.join)(src, entry));
|
|
16
26
|
const plugins = [
|
|
17
27
|
new HtmlWebpackPlugin(Object.assign(Object.assign({}, options), { templateContent: templateContent.html() })),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/enhancers/html5-entry-webpack-config-enhancer/index.ts"],"names":[],"mappings":";;;AAAA,yDAAyD;AAEzD,qCAA+B;AAC/B,2BAAkC;AAClC,+BAAqC;AACrC,uCAAmE;AAI5D,MAAM,+BAA+B,GAC1C,CAAC,OAAuC,EAAE,EAAE,CAAC,CAAC,eAA8B,EAAE,EAAE;IAC9E,MAAM,KAAK,GAAG,eAA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CAAC,IAAI,EAAE,IACvC;SACH,CAAC;QAEF,IAAI,CAAC,OAAO,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAElF,IAAA,oBAAU,EAAC,eAAe,EAAE,QAAQ,EAAE,OAAqC,CAAC,CAAC;QAE7E,eAAe,CAAC,OAAO,GAAG,CAAC,GAAG,eAAe,CAAC,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC;KACpE;IAED,OAAO,eAAe,CAAC;AACzB,CAAC,CAAC;AAlCS,QAAA,+BAA+B,mCAkCxC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-cli-webpack5",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.6-beta.3361",
|
|
4
4
|
"description": "Provides debug and build capabilities for pilets and Piral instances using Webpack v5.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"piral-cli",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"@types/node": "^13.9.0",
|
|
49
49
|
"@types/terser-webpack-plugin": "^5.0.0",
|
|
50
50
|
"@types/yargs": "^15.0.4",
|
|
51
|
-
"piral-cli": "0.14.
|
|
51
|
+
"piral-cli": "0.14.6-beta.3361",
|
|
52
52
|
"strip-ansi": "^3.0.0",
|
|
53
53
|
"typescript": "^4.0.2"
|
|
54
54
|
},
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
"webpack": "^5.1.3",
|
|
78
78
|
"webpack-inject-plugin": "^1.5.5"
|
|
79
79
|
},
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "de8dd4b06e6115257363f763e9d24fedf740fdc6"
|
|
81
81
|
}
|
|
@@ -14,7 +14,17 @@ export const html5EntryWebpackConfigEnhancer =
|
|
|
14
14
|
|
|
15
15
|
if (template) {
|
|
16
16
|
const src = dirname(template);
|
|
17
|
-
const
|
|
17
|
+
const html = readFileSync(template, 'utf8');
|
|
18
|
+
const templateContent = load(
|
|
19
|
+
// try to replace ejs tags, if any
|
|
20
|
+
html.replace(/<%=([\w\W]*?)%>/g, function (match, group) {
|
|
21
|
+
try {
|
|
22
|
+
return eval(group);
|
|
23
|
+
} catch {
|
|
24
|
+
return match;
|
|
25
|
+
}
|
|
26
|
+
}),
|
|
27
|
+
);
|
|
18
28
|
const entries = extractParts(templateContent).map((entry) => join(src, entry));
|
|
19
29
|
const plugins = [
|
|
20
30
|
new HtmlWebpackPlugin({
|