piral-cli-webpack5 1.0.0-pre.1960 → 1.0.0
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/LICENSE +1 -1
- package/README.md +31 -10
- package/extend-config.js +125 -18
- package/lib/actions.d.ts +2 -2
- package/lib/actions.js +33 -39
- package/lib/actions.js.map +1 -1
- package/lib/{configs → enhancers/hmr-webpack-config-enhancer}/HotModuleServerPlugin.js +1 -1
- package/lib/enhancers/hmr-webpack-config-enhancer/HotModuleServerPlugin.js.map +1 -0
- package/lib/enhancers/hmr-webpack-config-enhancer/index.d.ts +5 -0
- package/lib/enhancers/hmr-webpack-config-enhancer/index.js +30 -0
- package/lib/enhancers/hmr-webpack-config-enhancer/index.js.map +1 -0
- package/lib/enhancers/html5-entry-webpack-config-enhancer/helpers.d.ts +2 -2
- package/lib/enhancers/html5-entry-webpack-config-enhancer/helpers.js +1 -1
- package/lib/enhancers/html5-entry-webpack-config-enhancer/helpers.js.map +1 -1
- package/lib/enhancers/html5-entry-webpack-config-enhancer/index.d.ts +2 -1
- package/lib/enhancers/html5-entry-webpack-config-enhancer/index.js +17 -6
- package/lib/enhancers/html5-entry-webpack-config-enhancer/index.js.map +1 -1
- package/lib/enhancers/pilet-webpack-config-enhancer/helpers.d.ts +5 -0
- package/lib/enhancers/pilet-webpack-config-enhancer/helpers.js +53 -1
- package/lib/enhancers/pilet-webpack-config-enhancer/helpers.js.map +1 -1
- package/lib/enhancers/pilet-webpack-config-enhancer/index.d.ts +18 -4
- package/lib/enhancers/pilet-webpack-config-enhancer/index.js +117 -49
- package/lib/enhancers/pilet-webpack-config-enhancer/index.js.map +1 -1
- package/lib/enhancers/piral-instance-webpack-config-enhancer/helpers.js +2 -0
- package/lib/enhancers/piral-instance-webpack-config-enhancer/helpers.js.map +1 -1
- package/lib/enhancers/piral-instance-webpack-config-enhancer/index.d.ts +2 -3
- package/lib/enhancers/piral-instance-webpack-config-enhancer/index.js +6 -7
- package/lib/enhancers/piral-instance-webpack-config-enhancer/index.js.map +1 -1
- package/lib/helpers.d.ts +2 -1
- package/lib/helpers.js +10 -4
- package/lib/helpers.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/plugins/SheetLoader.d.ts +1 -0
- package/lib/plugins/SheetLoader.js +19 -0
- package/lib/plugins/SheetLoader.js.map +1 -0
- package/lib/plugins/SheetPlugin.d.ts +7 -0
- package/lib/plugins/SheetPlugin.js +31 -0
- package/lib/plugins/SheetPlugin.js.map +1 -0
- package/lib/plugins/StylesLoader.d.ts +1 -0
- package/lib/plugins/StylesLoader.js +14 -0
- package/lib/plugins/StylesLoader.js.map +1 -0
- package/lib/plugins/StylesPlugin.d.ts +6 -0
- package/lib/plugins/StylesPlugin.js +34 -0
- package/lib/plugins/StylesPlugin.js.map +1 -0
- package/lib/webpack/bundler-run.d.ts +2 -21
- package/lib/webpack/bundler-run.js +54 -46
- package/lib/webpack/bundler-run.js.map +1 -1
- package/lib/webpack/common.d.ts +8 -0
- package/lib/webpack/common.js +104 -0
- package/lib/webpack/common.js.map +1 -0
- package/lib/webpack/pilet.d.ts +19 -0
- package/lib/webpack/pilet.js +97 -0
- package/lib/webpack/pilet.js.map +1 -0
- package/lib/webpack/piral.d.ts +16 -0
- package/lib/webpack/piral.js +90 -0
- package/lib/webpack/piral.js.map +1 -0
- package/package.json +28 -29
- package/src/actions.ts +33 -20
- package/src/{configs → enhancers/hmr-webpack-config-enhancer}/HotModuleServerPlugin.ts +1 -1
- package/src/enhancers/hmr-webpack-config-enhancer/index.ts +34 -0
- package/src/enhancers/html5-entry-webpack-config-enhancer/helpers.ts +7 -7
- package/src/enhancers/html5-entry-webpack-config-enhancer/index.ts +31 -19
- package/src/enhancers/pilet-webpack-config-enhancer/helpers.ts +62 -0
- package/src/enhancers/pilet-webpack-config-enhancer/index.ts +187 -59
- package/src/enhancers/piral-instance-webpack-config-enhancer/helpers.ts +2 -0
- package/src/enhancers/piral-instance-webpack-config-enhancer/index.ts +14 -18
- package/src/helpers.ts +15 -5
- package/src/index.ts +1 -1
- package/src/plugins/SheetLoader.ts +16 -0
- package/src/plugins/SheetPlugin.ts +34 -0
- package/src/plugins/StylesLoader.ts +11 -0
- package/src/plugins/StylesPlugin.ts +35 -0
- package/src/webpack/bundler-run.ts +60 -56
- package/src/webpack/common.ts +111 -0
- package/src/webpack/pilet.ts +121 -0
- package/src/webpack/piral.ts +110 -0
- package/src/webpack-hot-middleware/LICENSE +20 -0
- package/src/webpack-hot-middleware/client-overlay.js +99 -0
- package/src/webpack-hot-middleware/client.js +306 -0
- package/src/webpack-hot-middleware/helpers.js +9 -0
- package/src/webpack-hot-middleware/middleware.js +175 -0
- package/src/webpack-hot-middleware/process-update.js +157 -0
- package/lib/configs/HotModuleServerPlugin.js.map +0 -1
- package/lib/configs/SheetLoader.d.ts +0 -1
- package/lib/configs/SheetLoader.js +0 -27
- package/lib/configs/SheetLoader.js.map +0 -1
- package/lib/configs/common.d.ts +0 -6
- package/lib/configs/common.js +0 -115
- package/lib/configs/common.js.map +0 -1
- package/lib/configs/index.d.ts +0 -2
- package/lib/configs/index.js +0 -15
- package/lib/configs/index.js.map +0 -1
- package/lib/configs/pilet.d.ts +0 -3
- package/lib/configs/pilet.js +0 -72
- package/lib/configs/pilet.js.map +0 -1
- package/lib/configs/piral.d.ts +0 -2
- package/lib/configs/piral.js +0 -65
- package/lib/configs/piral.js.map +0 -1
- package/lib/webpack/bundler-calls.d.ts +0 -3
- package/lib/webpack/bundler-calls.js +0 -93
- package/lib/webpack/bundler-calls.js.map +0 -1
- package/lib/webpack/index.d.ts +0 -1
- package/lib/webpack/index.js +0 -14
- package/lib/webpack/index.js.map +0 -1
- package/lib/webpack/run-build-pilet.d.ts +0 -1
- package/lib/webpack/run-build-pilet.js +0 -53
- package/lib/webpack/run-build-pilet.js.map +0 -1
- package/lib/webpack/run-build-piral.d.ts +0 -1
- package/lib/webpack/run-build-piral.js +0 -56
- package/lib/webpack/run-build-piral.js.map +0 -1
- package/lib/webpack/run-debug-mono-piral.d.ts +0 -1
- package/lib/webpack/run-debug-mono-piral.js +0 -61
- package/lib/webpack/run-debug-mono-piral.js.map +0 -1
- package/lib/webpack/run-debug-pilet.d.ts +0 -1
- package/lib/webpack/run-debug-pilet.js +0 -77
- package/lib/webpack/run-debug-pilet.js.map +0 -1
- package/lib/webpack/run-debug-piral.d.ts +0 -1
- package/lib/webpack/run-debug-piral.js +0 -76
- package/lib/webpack/run-debug-piral.js.map +0 -1
- package/src/configs/SheetLoader.ts +0 -12
- package/src/configs/common.ts +0 -118
- package/src/configs/index.ts +0 -2
- package/src/configs/pilet.ts +0 -82
- package/src/configs/piral.ts +0 -73
- package/src/webpack/bundler-calls.ts +0 -107
- package/src/webpack/index.ts +0 -1
- package/src/webpack/run-build-pilet.ts +0 -82
- package/src/webpack/run-build-piral.ts +0 -83
- package/src/webpack/run-debug-mono-piral.ts +0 -76
- package/src/webpack/run-debug-pilet.ts +0 -94
- package/src/webpack/run-debug-piral.ts +0 -95
- /package/lib/{configs → enhancers/hmr-webpack-config-enhancer}/HotModuleServerPlugin.d.ts +0 -0
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
[](https://piral.io)
|
|
2
2
|
|
|
3
|
-
# [Piral CLI Webpack5](https://piral.io) · [](https://github.com/smapiot/piral/blob/
|
|
3
|
+
# [Piral CLI Webpack5](https://piral.io) · [](https://github.com/smapiot/piral/blob/main/LICENSE) [](https://www.npmjs.com/package/piral-cli-webpack5) [](https://jestjs.io) [](https://gitter.im/piral-io/community)
|
|
4
4
|
|
|
5
5
|
This plugin enables using [Webpack v5](https://webpack.js.org) as the bundler for Piral instances and pilets.
|
|
6
6
|
|
|
@@ -32,10 +32,7 @@ Right now it includes:
|
|
|
32
32
|
- `style-loader`,
|
|
33
33
|
- `ts-loader`,
|
|
34
34
|
- `parcel-codegen-loader`,
|
|
35
|
-
- `
|
|
36
|
-
- `pilet-webpack-plugin`,
|
|
37
|
-
- `html5-entry-webpack-plugin`,
|
|
38
|
-
- `import-map-webpack-plugin`,
|
|
35
|
+
- `import-maps-webpack-plugin`,
|
|
39
36
|
- `html-webpack-plugin`,
|
|
40
37
|
- `mini-css-extract-plugin`,
|
|
41
38
|
- `optimize-css-assets-webpack-plugin`,
|
|
@@ -45,10 +42,6 @@ Right now it includes:
|
|
|
45
42
|
|
|
46
43
|
As such it should be prepared to include assets (images, videos, ...), stylesheets (CSS and SASS), and work with TypeScript.
|
|
47
44
|
|
|
48
|
-
> Right now the output of this plugin is for the **v1** pilet schema only!
|
|
49
|
-
|
|
50
|
-
No support for the legacy **v0** pilet schema.
|
|
51
|
-
|
|
52
45
|
### Customizing
|
|
53
46
|
|
|
54
47
|
You can still leverage your own `webpack.config.js`. Either just export *what you want to have overwritten*, e.g.,
|
|
@@ -71,6 +64,34 @@ module.exports = function(config) {
|
|
|
71
64
|
};
|
|
72
65
|
```
|
|
73
66
|
|
|
67
|
+
Otherwise, you can also use the `extend-config` helper module to get the job done without having to know the internals:
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
const extendConfig = require('piral-cli-webpack5/extend-config');
|
|
71
|
+
|
|
72
|
+
module.exports = extendConfig({
|
|
73
|
+
checkTypes: true, // not only transpiles TS, but also checks the types
|
|
74
|
+
noPresets: true, // removes existing presets from Babel
|
|
75
|
+
rules: [], // adds additional rules
|
|
76
|
+
removeRules: [], // removes the rules mentioned by their loader name
|
|
77
|
+
plugins: [], // adds additional plugins
|
|
78
|
+
removePlugins: [], // removes the plugins mentioned by their class reference
|
|
79
|
+
fileLoaderOptions: {}, // sets the options for the file loader
|
|
80
|
+
tsLoaderOptions: {}, // sets the options for the TS loader
|
|
81
|
+
babelLoaderOptions: {}, // sets the options for the Babel loader
|
|
82
|
+
cssLoaderOptions: {}, // sets the options for the CSS loader
|
|
83
|
+
sassLoaderOptions: {}, // sets the options for the SASS loader
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
If you want to name your Webpack configuration different than `webpack.config.js` you can use the `--config` CLI option.
|
|
88
|
+
|
|
89
|
+
Example:
|
|
90
|
+
|
|
91
|
+
```sh
|
|
92
|
+
npx piral build --config my-webpack.js
|
|
93
|
+
```
|
|
94
|
+
|
|
74
95
|
## License
|
|
75
96
|
|
|
76
97
|
Piral is released using the MIT license. For more information see the [license file](./LICENSE).
|
package/extend-config.js
CHANGED
|
@@ -1,28 +1,106 @@
|
|
|
1
|
+
function changePlugin(config, classRef, cb) {
|
|
2
|
+
config.plugins = config.plugins
|
|
3
|
+
.map((plugin) => {
|
|
4
|
+
if (plugin instanceof classRef) {
|
|
5
|
+
if (typeof cb === 'function') {
|
|
6
|
+
return cb(plugin);
|
|
7
|
+
} else {
|
|
8
|
+
return cb;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return plugin;
|
|
13
|
+
})
|
|
14
|
+
.filter(Boolean);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function matchesLoader(r, loaderPath, cb, otherwise) {
|
|
18
|
+
const uses = r.use || [];
|
|
19
|
+
|
|
20
|
+
if (uses.some((m) => m && (m === loaderPath || (typeof m === 'object' && m.loader === loaderPath)))) {
|
|
21
|
+
if (typeof cb === 'function') {
|
|
22
|
+
return cb(r);
|
|
23
|
+
} else {
|
|
24
|
+
return cb;
|
|
25
|
+
}
|
|
26
|
+
} else if (typeof otherwise === 'function') {
|
|
27
|
+
return otherwise();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return r;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function changeRule(config, name, cb) {
|
|
34
|
+
const loaderPath = require.resolve(name);
|
|
35
|
+
config.module.rules = config.module.rules
|
|
36
|
+
.map((rule) =>
|
|
37
|
+
matchesLoader(rule, loaderPath, cb, () => {
|
|
38
|
+
if (rule.oneOf) {
|
|
39
|
+
rule.oneOf = rule.oneOf.map((r) => matchesLoader(r, loaderPath, cb)).filter(Boolean);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return rule;
|
|
43
|
+
}),
|
|
44
|
+
)
|
|
45
|
+
.filter(Boolean);
|
|
46
|
+
}
|
|
47
|
+
|
|
1
48
|
function changeLoader(config, name, cb) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
49
|
+
const loaderPath = require.resolve(name);
|
|
50
|
+
|
|
51
|
+
changeRule(config, name, (rule) => {
|
|
52
|
+
rule.use = rule.use.map((m) => {
|
|
53
|
+
if (m === loaderPath) {
|
|
54
|
+
if (typeof cb === 'function') {
|
|
55
|
+
return cb({ loader: m });
|
|
56
|
+
} else {
|
|
57
|
+
return cb;
|
|
10
58
|
}
|
|
11
|
-
})
|
|
59
|
+
} else if (m.loader === loaderPath) {
|
|
60
|
+
if (typeof cb === 'function') {
|
|
61
|
+
return cb(m);
|
|
62
|
+
} else {
|
|
63
|
+
return cb;
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
return m;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
return rule;
|
|
12
71
|
});
|
|
13
72
|
}
|
|
14
73
|
|
|
15
74
|
function changeLoaderOptions(config, name, options) {
|
|
16
|
-
changeLoader(config, name, (rule) =>
|
|
75
|
+
changeLoader(config, name, (rule) => {
|
|
76
|
+
rule.options = options;
|
|
77
|
+
return rule;
|
|
78
|
+
});
|
|
17
79
|
}
|
|
18
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Use this function to create a function to return from your webpack
|
|
83
|
+
* configuration module. The created function can be used to conveniently
|
|
84
|
+
* override and etend the original configuration.
|
|
85
|
+
* @typedef OverrideOptions
|
|
86
|
+
* @property {any=} tsLoaderOptions The new options for the ts-loader
|
|
87
|
+
* @property {any=} babelLoaderOptions The new options for the babel-loader
|
|
88
|
+
* @property {any=} cssLoaderOptions The new options for the css-loader
|
|
89
|
+
* @property {any=} sassLoaderOptions The new options for the sass-loader
|
|
90
|
+
* @property {boolean=} checkTypes Determines the value of the transpileOnly option in ts-loader
|
|
91
|
+
* @property {boolean=} noPresets Determines if presets should be set to undefined in babel-loader
|
|
92
|
+
* @property {Array<{ name: string, rule: any }>=} updateRules Overrides the rules determined by its loader name with the provided rule
|
|
93
|
+
* @property {Array<string>=} removeRules Removes the rules determined by its loader name
|
|
94
|
+
* @property {Array<any>=} rules Inserts the given rules in the beginning
|
|
95
|
+
* @property {Array<{ type: any, plugin: any }>=} updatePlugins Overrides the plugins determined by its class reference (instance) with the provided plugin
|
|
96
|
+
* @property {Array<any>=} removePlugins Removes the plugins determined by its class reference (instance)
|
|
97
|
+
* @property {Array<any>=} plugins Inserts the given plugins in the end
|
|
98
|
+
* @param {OverrideOptions} override
|
|
99
|
+
* @returns {(config: webpack.Configuration) => webpack.Configuration}
|
|
100
|
+
*/
|
|
19
101
|
module.exports = function (override) {
|
|
20
102
|
return (config) => {
|
|
21
103
|
if (override && typeof override === 'object') {
|
|
22
|
-
if ('fileLoaderOptions' in override) {
|
|
23
|
-
changeLoaderOptions(config, 'file-loader', override.fileLoaderOptions);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
104
|
if ('tsLoaderOptions' in override) {
|
|
27
105
|
changeLoaderOptions(config, 'ts-loader', override.tsLoaderOptions);
|
|
28
106
|
}
|
|
@@ -63,16 +141,45 @@ module.exports = function (override) {
|
|
|
63
141
|
);
|
|
64
142
|
}
|
|
65
143
|
|
|
66
|
-
if ('
|
|
67
|
-
|
|
144
|
+
if ('updateRules' in override && Array.isArray(override.updateRules)) {
|
|
145
|
+
override.updateRules.forEach((def) => {
|
|
146
|
+
if (typeof def.name === 'string' && def.rule) {
|
|
147
|
+
changeRule(config, def.name, def.rule);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if ('removeRules' in override && Array.isArray(override.removeRules)) {
|
|
153
|
+
override.removeRules.forEach((rule) => changeRule(config, rule, () => undefined));
|
|
68
154
|
}
|
|
69
155
|
|
|
70
156
|
if ('rules' in override && Array.isArray(override.rules)) {
|
|
71
|
-
config.module.rules
|
|
157
|
+
for (const rule of config.module.rules) {
|
|
158
|
+
if (Array.isArray(rule.oneOf)) {
|
|
159
|
+
rule.oneOf.unshift(...override.rules);
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if ('updatePlugins' in override && Array.isArray(override.updatePlugins)) {
|
|
166
|
+
override.updatePlugins.forEach((def) => {
|
|
167
|
+
if (def.type && def.plugin) {
|
|
168
|
+
changePlugin(config, def.type, def.plugin);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if ('removePlugins' in override && Array.isArray(override.removePlugins)) {
|
|
174
|
+
override.removePlugins.forEach((plugin) => changePlugin(config, plugin, () => undefined));
|
|
72
175
|
}
|
|
73
176
|
|
|
74
177
|
if ('plugins' in override && Array.isArray(override.plugins)) {
|
|
75
|
-
config.plugins.push(...plugins);
|
|
178
|
+
config.plugins.push(...override.plugins);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if ('change' in override && typeof override.change === 'function') {
|
|
182
|
+
config = override.change(config);
|
|
76
183
|
}
|
|
77
184
|
}
|
|
78
185
|
|
package/lib/actions.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DebugPiletBundlerDefinition, DebugPiralBundlerDefinition, BuildPiletBundlerDefinition, BuildPiralBundlerDefinition, WatchPiralBundlerDefinition } from 'piral-cli';
|
|
2
|
-
export declare const debugPiral: DebugPiralBundlerDefinition;
|
|
1
|
+
import type { DebugPiletBundlerDefinition, DebugPiralBundlerDefinition, BuildPiletBundlerDefinition, BuildPiralBundlerDefinition, WatchPiralBundlerDefinition } from 'piral-cli';
|
|
3
2
|
export declare const watchPiral: WatchPiralBundlerDefinition;
|
|
3
|
+
export declare const debugPiral: DebugPiralBundlerDefinition;
|
|
4
4
|
export declare const buildPiral: BuildPiralBundlerDefinition;
|
|
5
5
|
export declare const debugPilet: DebugPiletBundlerDefinition;
|
|
6
6
|
export declare const buildPilet: BuildPiletBundlerDefinition;
|
package/lib/actions.js
CHANGED
|
@@ -1,54 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.buildPilet = exports.debugPilet = exports.buildPiral = exports.
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
run(args) {
|
|
16
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
const bundler = yield webpack_1.callDynamic('debug-piral', args);
|
|
18
|
-
return bundler;
|
|
19
|
-
});
|
|
20
|
-
},
|
|
21
|
-
};
|
|
3
|
+
exports.buildPilet = exports.debugPilet = exports.buildPiral = exports.debugPiral = exports.watchPiral = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
22
6
|
exports.watchPiral = {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
7
|
+
path: (0, path_1.resolve)(__dirname, 'webpack', 'piral.js'),
|
|
8
|
+
};
|
|
9
|
+
exports.debugPiral = {
|
|
10
|
+
flags(argv) {
|
|
11
|
+
return argv
|
|
12
|
+
.string('config')
|
|
13
|
+
.describe('config', 'Sets configuration file for modifying the Webpack configuration.')
|
|
14
|
+
.default('config', constants_1.defaultWebpackConfig)
|
|
15
|
+
.number('hmr-port')
|
|
16
|
+
.describe('hmr-port', 'Sets the port to be used for HMR for reloading the application.')
|
|
17
|
+
.default('hmr-port', 62123);
|
|
28
18
|
},
|
|
19
|
+
path: (0, path_1.resolve)(__dirname, 'webpack', 'piral.js'),
|
|
29
20
|
};
|
|
30
21
|
exports.buildPiral = {
|
|
31
|
-
|
|
32
|
-
return
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
22
|
+
flags(argv) {
|
|
23
|
+
return argv
|
|
24
|
+
.string('config')
|
|
25
|
+
.describe('config', 'Sets configuration file for modifying the Webpack configuration.')
|
|
26
|
+
.default('config', constants_1.defaultWebpackConfig);
|
|
36
27
|
},
|
|
28
|
+
path: (0, path_1.resolve)(__dirname, 'webpack', 'piral.js'),
|
|
37
29
|
};
|
|
38
30
|
exports.debugPilet = {
|
|
39
|
-
|
|
40
|
-
return
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
31
|
+
flags(argv) {
|
|
32
|
+
return argv
|
|
33
|
+
.string('config')
|
|
34
|
+
.describe('config', 'Sets configuration file for modifying the Webpack configuration.')
|
|
35
|
+
.default('config', constants_1.defaultWebpackConfig);
|
|
44
36
|
},
|
|
37
|
+
path: (0, path_1.resolve)(__dirname, 'webpack', 'pilet.js'),
|
|
45
38
|
};
|
|
46
39
|
exports.buildPilet = {
|
|
47
|
-
|
|
48
|
-
return
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
40
|
+
flags(argv) {
|
|
41
|
+
return argv
|
|
42
|
+
.string('config')
|
|
43
|
+
.describe('config', 'Sets configuration file for modifying the Webpack configuration.')
|
|
44
|
+
.default('config', constants_1.defaultWebpackConfig);
|
|
52
45
|
},
|
|
46
|
+
path: (0, path_1.resolve)(__dirname, 'webpack', 'pilet.js'),
|
|
53
47
|
};
|
|
54
48
|
//# sourceMappingURL=actions.js.map
|
package/lib/actions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":";;;AAAA,+BAA+B;AAQ/B,2CAAmD;AAEtC,QAAA,UAAU,GAAgC;IACrD,IAAI,EAAE,IAAA,cAAO,EAAC,SAAS,EAAE,SAAS,EAAE,UAAU,CAAC;CAChD,CAAC;AAEW,QAAA,UAAU,GAAgC;IACrD,KAAK,CAAC,IAAI;QACR,OAAO,IAAI;aACR,MAAM,CAAC,QAAQ,CAAC;aAChB,QAAQ,CAAC,QAAQ,EAAE,kEAAkE,CAAC;aACtF,OAAO,CAAC,QAAQ,EAAE,gCAAoB,CAAC;aACvC,MAAM,CAAC,UAAU,CAAC;aAClB,QAAQ,CAAC,UAAU,EAAE,iEAAiE,CAAC;aACvF,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IAChC,CAAC;IACD,IAAI,EAAE,IAAA,cAAO,EAAC,SAAS,EAAE,SAAS,EAAE,UAAU,CAAC;CAChD,CAAC;AAEW,QAAA,UAAU,GAAgC;IACrD,KAAK,CAAC,IAAI;QACR,OAAO,IAAI;aACR,MAAM,CAAC,QAAQ,CAAC;aAChB,QAAQ,CAAC,QAAQ,EAAE,kEAAkE,CAAC;aACtF,OAAO,CAAC,QAAQ,EAAE,gCAAoB,CAAC,CAAC;IAC7C,CAAC;IACD,IAAI,EAAE,IAAA,cAAO,EAAC,SAAS,EAAE,SAAS,EAAE,UAAU,CAAC;CAChD,CAAC;AAEW,QAAA,UAAU,GAAgC;IACrD,KAAK,CAAC,IAAI;QACR,OAAO,IAAI;aACR,MAAM,CAAC,QAAQ,CAAC;aAChB,QAAQ,CAAC,QAAQ,EAAE,kEAAkE,CAAC;aACtF,OAAO,CAAC,QAAQ,EAAE,gCAAoB,CAAC,CAAC;IAC7C,CAAC;IACD,IAAI,EAAE,IAAA,cAAO,EAAC,SAAS,EAAE,SAAS,EAAE,UAAU,CAAC;CAChD,CAAC;AAEW,QAAA,UAAU,GAAgC;IACrD,KAAK,CAAC,IAAI;QACR,OAAO,IAAI;aACR,MAAM,CAAC,QAAQ,CAAC;aAChB,QAAQ,CAAC,QAAQ,EAAE,kEAAkE,CAAC;aACtF,OAAO,CAAC,QAAQ,EAAE,gCAAoB,CAAC,CAAC;IAC7C,CAAC;IACD,IAAI,EAAE,IAAA,cAAO,EAAC,SAAS,EAAE,SAAS,EAAE,UAAU,CAAC;CAChD,CAAC"}
|
|
@@ -8,7 +8,7 @@ class HotModuleServerPlugin {
|
|
|
8
8
|
apply(compiler) {
|
|
9
9
|
const express = require('express');
|
|
10
10
|
const app = express();
|
|
11
|
-
app.use(require('webpack-hot-middleware')(compiler));
|
|
11
|
+
app.use(require('../../../src/webpack-hot-middleware/middleware')(compiler));
|
|
12
12
|
app.listen(this.hmrPort, () => { });
|
|
13
13
|
}
|
|
14
14
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HotModuleServerPlugin.js","sourceRoot":"","sources":["../../../src/enhancers/hmr-webpack-config-enhancer/HotModuleServerPlugin.ts"],"names":[],"mappings":";;;AAEA,MAAa,qBAAqB;IAChC,YAAoB,OAAe;QAAf,YAAO,GAAP,OAAO,CAAQ;IAAG,CAAC;IAEvC,KAAK,CAAC,QAAkB;QACtB,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;QACnC,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC;QACtB,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,gDAAgD,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC7E,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IACrC,CAAC;CACF;AATD,sDASC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hmrWebpackConfigEnhancer = void 0;
|
|
4
|
+
const webpack_1 = require("webpack");
|
|
5
|
+
const HotModuleServerPlugin_1 = require("./HotModuleServerPlugin");
|
|
6
|
+
function getHmrEntry(hmrPort) {
|
|
7
|
+
return hmrPort
|
|
8
|
+
? [
|
|
9
|
+
`piral-cli-webpack5/src/webpack-hot-middleware/client?path=http://localhost:${hmrPort}/__webpack_hmr&reload=true`,
|
|
10
|
+
]
|
|
11
|
+
: [];
|
|
12
|
+
}
|
|
13
|
+
const hmrWebpackConfigEnhancer = (options) => (compilerOptions) => {
|
|
14
|
+
const { port } = options;
|
|
15
|
+
if (port) {
|
|
16
|
+
if (Array.isArray(compilerOptions.entry)) {
|
|
17
|
+
compilerOptions.entry.unshift(...getHmrEntry(port));
|
|
18
|
+
}
|
|
19
|
+
const newPlugins = [new webpack_1.HotModuleReplacementPlugin(), new HotModuleServerPlugin_1.HotModuleServerPlugin(port)];
|
|
20
|
+
if (!compilerOptions.plugins) {
|
|
21
|
+
compilerOptions.plugins = newPlugins;
|
|
22
|
+
}
|
|
23
|
+
else if (Array.isArray(compilerOptions.plugins)) {
|
|
24
|
+
compilerOptions.plugins.push(...newPlugins);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return compilerOptions;
|
|
28
|
+
};
|
|
29
|
+
exports.hmrWebpackConfigEnhancer = hmrWebpackConfigEnhancer;
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/enhancers/hmr-webpack-config-enhancer/index.ts"],"names":[],"mappings":";;;AAAA,qCAAoE;AACpE,mEAAgE;AAMhE,SAAS,WAAW,CAAC,OAAe;IAClC,OAAO,OAAO;QACZ,CAAC,CAAC;YACE,8EAA8E,OAAO,4BAA4B;SAClH;QACH,CAAC,CAAC,EAAE,CAAC;AACT,CAAC;AAEM,MAAM,wBAAwB,GAAG,CAAC,OAAgC,EAAE,EAAE,CAAC,CAAC,eAA8B,EAAE,EAAE;IAC/G,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;IAEzB,IAAI,IAAI,EAAE;QACR,IAAI,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE;YACxC,eAAe,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;SACrD;QAED,MAAM,UAAU,GAAG,CAAC,IAAI,oCAA0B,EAAE,EAAE,IAAI,6CAAqB,CAAC,IAAI,CAAC,CAAC,CAAC;QAEvF,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE;YAC5B,eAAe,CAAC,OAAO,GAAG,UAAU,CAAC;SACtC;aAAM,IAAI,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE;YACjD,eAAe,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,CAAC;SAC7C;KACF;IAED,OAAO,eAAe,CAAC;AACzB,CAAC,CAAC;AAlBW,QAAA,wBAAwB,4BAkBnC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="cheerio" />
|
|
2
2
|
import { Configuration, Entry } from 'webpack';
|
|
3
3
|
export declare function isLocal(path: string): boolean;
|
|
4
|
-
export declare function extractParts(content:
|
|
4
|
+
export declare function extractParts(content: cheerio.Root): string[];
|
|
5
5
|
export declare function getTemplates(entry: Entry): Array<string>;
|
|
6
6
|
export declare function replaceEntries(existingEntries: Array<string>, oldEntry: string, newEntries: Array<string>): void;
|
|
7
|
-
export declare function setEntries(config: Configuration, template: string, entries: [string, ...string
|
|
7
|
+
export declare function setEntries(config: Configuration, template: string, entries: [string, ...Array<string>]): void;
|
|
@@ -21,7 +21,7 @@ function isLocal(path) {
|
|
|
21
21
|
}
|
|
22
22
|
exports.isLocal = isLocal;
|
|
23
23
|
function extractParts(content) {
|
|
24
|
-
const sheets = content('link[href]')
|
|
24
|
+
const sheets = content('link[href][rel=stylesheet]')
|
|
25
25
|
.filter((_, e) => isLocal(e.attribs.href))
|
|
26
26
|
.remove()
|
|
27
27
|
.toArray();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/enhancers/html5-entry-webpack-config-enhancer/helpers.ts"],"names":[],"mappings":";;;AAEA,SAAgB,OAAO,CAAC,IAAY;IAClC,IAAI,IAAI,EAAE;QACR,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;YACxB,OAAO,KAAK,CAAC;SACd;aAAM,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;YACnC,OAAO,KAAK,CAAC;SACd;aAAM,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;YACpC,OAAO,KAAK,CAAC;SACd;aAAM,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;YACnC,OAAO,KAAK,CAAC;SACd;QAED,OAAO,IAAI,CAAC;KACb;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAhBD,0BAgBC;AAED,SAAgB,YAAY,CAAC,
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/enhancers/html5-entry-webpack-config-enhancer/helpers.ts"],"names":[],"mappings":";;;AAEA,SAAgB,OAAO,CAAC,IAAY;IAClC,IAAI,IAAI,EAAE;QACR,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;YACxB,OAAO,KAAK,CAAC;SACd;aAAM,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;YACnC,OAAO,KAAK,CAAC;SACd;aAAM,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ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KAAK,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC;aAC7B;iBAAM,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;gBAC/B,cAAc,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;aAC1C;QACH,CAAC,CAAC,CAAC;KACJ;AACH,CAAC;AAhBD,gCAgBC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
2
|
+
import { Configuration } from 'webpack';
|
|
2
3
|
export interface Html5EntryWebpackPluginOptions extends Omit<HtmlWebpackPlugin.Options, 'templateContent'> {
|
|
3
4
|
}
|
|
4
|
-
export declare const html5EntryWebpackConfigEnhancer: (options: Html5EntryWebpackPluginOptions) => (compilerOptions:
|
|
5
|
+
export declare const html5EntryWebpackConfigEnhancer: (options: Html5EntryWebpackPluginOptions) => (compilerOptions: Configuration) => Configuration;
|
|
@@ -6,21 +6,32 @@ const cheerio_1 = require("cheerio");
|
|
|
6
6
|
const fs_1 = require("fs");
|
|
7
7
|
const path_1 = require("path");
|
|
8
8
|
const helpers_1 = require("./helpers");
|
|
9
|
-
|
|
9
|
+
const html5EntryWebpackConfigEnhancer = (options) => (compilerOptions) => {
|
|
10
10
|
const entry = compilerOptions.entry;
|
|
11
|
-
const [template] = helpers_1.getTemplates(entry);
|
|
11
|
+
const [template] = (0, helpers_1.getTemplates)(entry);
|
|
12
12
|
if (template) {
|
|
13
|
-
const src = path_1.dirname(template);
|
|
14
|
-
const
|
|
15
|
-
const
|
|
13
|
+
const src = (0, path_1.dirname)(template);
|
|
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
|
+
}));
|
|
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() })),
|
|
18
28
|
];
|
|
19
29
|
if (!entries.length)
|
|
20
30
|
throw new Error('Template entries expected to be not empty');
|
|
21
|
-
helpers_1.setEntries(compilerOptions, template, entries);
|
|
31
|
+
(0, helpers_1.setEntries)(compilerOptions, template, entries);
|
|
22
32
|
compilerOptions.plugins = [...compilerOptions.plugins, ...plugins];
|
|
23
33
|
}
|
|
24
34
|
return compilerOptions;
|
|
25
35
|
};
|
|
36
|
+
exports.html5EntryWebpackConfigEnhancer = html5EntryWebpackConfigEnhancer;
|
|
26
37
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/enhancers/html5-entry-webpack-config-enhancer/index.ts"],"names":[],"mappings":";;;AAAA,yDAAyD;
|
|
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,eAAe,CAAC,KAAK,CAAC;IACpC,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAA,sBAAY,EAAC,KAAK,CAAC,CAAC;IAEvC,IAAI,QAAQ,EAAE;QACZ,MAAM,GAAG,GAAG,IAAA,cAAO,EAAC,QAAQ,CAAC,CAAC;QAC9B,MAAM,IAAI,GAAG,IAAA,iBAAY,EAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAC5C,MAAM,eAAe,GAAG,IAAA,cAAI;QAC1B,kCAAkC;QAClC,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE,UAAU,KAAK,EAAE,KAAK;YACrD,IAAI;gBACF,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;aACpB;YAAC,WAAM;gBACN,OAAO,KAAK,CAAC;aACd;QACH,CAAC,CAAC,CACH,CAAC;QACF,MAAM,OAAO,GAAG,IAAA,sBAAY,EAAC,eAAe,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,WAAI,EAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;QAC/E,MAAM,OAAO,GAAG;YACd,IAAI,iBAAiB,iCAChB,OAAO,KACV,eAAe,EAAE,eAAe,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"}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import { SharedDependency } from 'piral-cli';
|
|
2
|
+
import { Configuration } from 'webpack';
|
|
1
3
|
export declare function getVariables(name: string, version: string, env: string): Record<string, string>;
|
|
2
4
|
export declare function setEnvironment(variables: Record<string, string>): void;
|
|
3
5
|
export declare function getDefineVariables(variables: Record<string, string>): {};
|
|
6
|
+
export declare function getDependencies(importmap: Array<SharedDependency>, compilerOptions: Configuration): {};
|
|
7
|
+
export declare function withSetPath(compilerOptions: Configuration): void;
|
|
8
|
+
export declare function withExternals(compilerOptions: Configuration, externals: Array<string>): void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDefineVariables = exports.setEnvironment = exports.getVariables = void 0;
|
|
3
|
+
exports.withExternals = exports.withSetPath = exports.getDependencies = exports.getDefineVariables = exports.setEnvironment = exports.getVariables = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
4
5
|
function getVariables(name, version, env) {
|
|
5
6
|
return {
|
|
6
7
|
NODE_ENV: env,
|
|
@@ -22,4 +23,55 @@ function getDefineVariables(variables) {
|
|
|
22
23
|
}, {});
|
|
23
24
|
}
|
|
24
25
|
exports.getDefineVariables = getDefineVariables;
|
|
26
|
+
function getDependencies(importmap, compilerOptions) {
|
|
27
|
+
const dependencies = {};
|
|
28
|
+
const { entry, externals } = compilerOptions;
|
|
29
|
+
if (typeof entry === 'object' && entry && Array.isArray(externals) && typeof externals[0] === 'object') {
|
|
30
|
+
for (const dep of importmap) {
|
|
31
|
+
dependencies[dep.id] = dep.ref;
|
|
32
|
+
externals[0][dep.name] = dep.requireId;
|
|
33
|
+
if (dep.type === 'local') {
|
|
34
|
+
entry[dep.ref.replace(/\.js$/, '')] = dep.entry;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return dependencies;
|
|
39
|
+
}
|
|
40
|
+
exports.getDependencies = getDependencies;
|
|
41
|
+
function withSetPath(compilerOptions) {
|
|
42
|
+
if (typeof compilerOptions.entry === 'object' && compilerOptions.entry) {
|
|
43
|
+
const setPath = (0, path_1.join)(__dirname, '..', '..', 'set-path');
|
|
44
|
+
if (Array.isArray(compilerOptions.entry)) {
|
|
45
|
+
compilerOptions.entry.unshift(setPath);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
for (const key of Object.keys(compilerOptions.entry)) {
|
|
49
|
+
const entry = compilerOptions.entry[key];
|
|
50
|
+
if (Array.isArray(entry)) {
|
|
51
|
+
entry.unshift(setPath);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.withSetPath = withSetPath;
|
|
58
|
+
function withExternals(compilerOptions, externals) {
|
|
59
|
+
const current = compilerOptions.externals || [];
|
|
60
|
+
const arrayExternals = Array.isArray(current) ? current : [current];
|
|
61
|
+
const objectExternal = externals.reduce((external, dep) => {
|
|
62
|
+
external[dep] = dep;
|
|
63
|
+
return external;
|
|
64
|
+
}, {});
|
|
65
|
+
const newExternals = arrayExternals.filter(external => {
|
|
66
|
+
if (typeof external === 'object' && Object.keys(external).length) {
|
|
67
|
+
for (const dep in external) {
|
|
68
|
+
objectExternal[dep] = external[dep];
|
|
69
|
+
}
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
return true;
|
|
73
|
+
});
|
|
74
|
+
compilerOptions.externals = [objectExternal, ...newExternals];
|
|
75
|
+
}
|
|
76
|
+
exports.withExternals = withExternals;
|
|
25
77
|
//# sourceMappingURL=helpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/enhancers/pilet-webpack-config-enhancer/helpers.ts"],"names":[],"mappings":";;;AAAA,SAAgB,YAAY,CAAC,IAAY,EAAE,OAAe,EAAE,GAAW;IACrE,OAAO;QACL,QAAQ,EAAE,GAAG;QACb,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,YAAY,EAAE;QACrC,eAAe,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACzC,kBAAkB,EAAE,OAAO;QAC3B,eAAe,EAAE,IAAI;KACtB,CAAC;AACJ,CAAC;AARD,oCAQC;AAED,SAAgB,cAAc,CAAC,SAAiC;IAC9D,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,SAAS,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ral-cli';
|
|
2
|
+
import { Configuration } from 'webpack';
|
|
1
3
|
export interface PiletWebpackConfigEnhancerOptions {
|
|
2
4
|
/**
|
|
3
5
|
* The name of the pilet.
|
|
4
6
|
*/
|
|
5
7
|
name: string;
|
|
8
|
+
/**
|
|
9
|
+
* The name of the entry module.
|
|
10
|
+
*/
|
|
11
|
+
entry: string;
|
|
6
12
|
/**
|
|
7
13
|
* The version of the pilet.
|
|
8
14
|
*/
|
|
9
15
|
version: string;
|
|
10
16
|
/**
|
|
11
|
-
* The name of the Piral
|
|
17
|
+
* The name of the Piral instances.
|
|
18
|
+
*/
|
|
19
|
+
piralInstances: Array<string>;
|
|
20
|
+
/**
|
|
21
|
+
* The name of the main output file.
|
|
12
22
|
*/
|
|
13
|
-
|
|
23
|
+
filename: string;
|
|
14
24
|
/**
|
|
15
25
|
* The schema version. By default, v1 is used.
|
|
16
26
|
*/
|
|
17
|
-
schema?: 'v0' | 'v1' | 'none';
|
|
27
|
+
schema?: 'v0' | 'v1' | 'v2' | 'v3' | 'none';
|
|
18
28
|
/**
|
|
19
29
|
* The shared dependencies. By default, these are read from the
|
|
20
30
|
* Piral instance.
|
|
@@ -24,5 +34,9 @@ export interface PiletWebpackConfigEnhancerOptions {
|
|
|
24
34
|
* Additional environment variables to define.
|
|
25
35
|
*/
|
|
26
36
|
variables?: Record<string, string>;
|
|
37
|
+
/**
|
|
38
|
+
* The shared dependencies to consider.
|
|
39
|
+
*/
|
|
40
|
+
importmap: Array<SharedDependency>;
|
|
27
41
|
}
|
|
28
|
-
export declare const piletWebpackConfigEnhancer: (
|
|
42
|
+
export declare const piletWebpackConfigEnhancer: (details: PiletWebpackConfigEnhancerOptions) => (compiler: Configuration) => Configuration;
|