@flatjs/evolve 2.1.0-next.3 → 2.1.0-next.5
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/constants.js +26 -1
- package/dist/create-webpack/create-externals.js +6 -1
- package/dist/create-webpack/create-optimization.js +41 -1
- package/dist/create-webpack/create-output.js +35 -1
- package/dist/create-webpack/create-performance.js +7 -1
- package/dist/create-webpack/create-plugins.js +77 -1
- package/dist/create-webpack/create-resolve.js +37 -1
- package/dist/create-webpack/create-rule-sets.js +19 -1
- package/dist/create-webpack/load-webpack-config.js +56 -1
- package/dist/create-webpack/resolve-public-path.js +15 -1
- package/dist/create-webpack/rule-sets/constants.js +3 -1
- package/dist/create-webpack/rule-sets/rule-assets.js +50 -1
- package/dist/create-webpack/rule-sets/rule-css.js +101 -1
- package/dist/create-webpack/rule-sets/rule-less.js +44 -1
- package/dist/create-webpack/rule-sets/rule-scripts.js +34 -1
- package/dist/create-webpack/rule-sets/rule-svg-icon.js +25 -1
- package/dist/create-webpack/rule-sets/rule-utils.js +10 -1
- package/dist/create-webpack/types.js +1 -1
- package/dist/default-options.js +84 -1
- package/dist/define-config/define-config.js +4 -1
- package/dist/define-config/index.js +1 -1
- package/dist/dev-server/add-compiler-to-dev-server.js +58 -1
- package/dist/dev-server/create-app-page-route.js +13 -1
- package/dist/dev-server/create-dev-server-compiler-tasks.js +52 -1
- package/dist/dev-server/create-dev-server-entries.js +27 -1
- package/dist/dev-server/create-dev-server.js +24 -1
- package/dist/dev-server/index.js +6 -1
- package/dist/dev-server/middlewares/create-page-middleware.js +33 -1
- package/dist/dev-server/middlewares/create-public-assets-middleware.js +25 -1
- package/dist/dev-server/middlewares/get-all-sorted-modules.js +24 -1
- package/dist/dev-server/middlewares/get-bundle-asset.js +7 -1
- package/dist/dev-server/middlewares/get-dev-server-host-uri.js +5 -1
- package/dist/dev-server/middlewares/get-hmr-runtime-chunks.js +14 -1
- package/dist/dev-server/middlewares/get-normalized-entry-name.js +14 -1
- package/dist/dev-server/middlewares/get-page-main-html.js +42 -1
- package/dist/dev-server/middlewares/get-page-module-html.js +120 -1
- package/dist/dev-server/middlewares/get-project-virtual-path.js +3 -1
- package/dist/dev-server/middlewares/get-runtime-manifest.js +25 -1
- package/dist/dev-server/middlewares/index.js +2 -1
- package/dist/dev-server/middlewares/types.js +1 -1
- package/dist/errors/evolve-build-error.js +10 -1
- package/dist/helpers/allow-px2rem-for-module.js +6 -1
- package/dist/helpers/assert-only-single-entry-item.js +23 -1
- package/dist/helpers/chunk-entry-map.js +21 -1
- package/dist/helpers/enable-bundle-hashname-for-module.js +6 -1
- package/dist/helpers/filter-actived-entries.js +42 -1
- package/dist/helpers/get-bundle-file-name.js +23 -1
- package/dist/helpers/get-git-root.js +4 -1
- package/dist/helpers/get-html-plugin-config.js +47 -1
- package/dist/helpers/get-max-process-tasks.js +7 -1
- package/dist/helpers/get-pacakge-dir.js +13 -1
- package/dist/helpers/index.js +17 -1
- package/dist/helpers/json-serializer.js +52 -1
- package/dist/helpers/merge-babel-options.js +45 -1
- package/dist/helpers/normalize-entry-map.js +38 -1
- package/dist/helpers/normalize-page-proxy.js +9 -1
- package/dist/helpers/normalize-resolve-alias.js +7 -1
- package/dist/helpers/open-page.js +15 -1
- package/dist/helpers/print-log.js +49 -1
- package/dist/helpers/refresh-evolve-mock-options.js +34 -1
- package/dist/helpers/resolve-entry-map-input-files.js +20 -1
- package/dist/helpers/script-injects.js +39 -1
- package/dist/helpers/should-enable-react-fast-refresh.js +10 -1
- package/dist/helpers/split-to-multi-compiler.js +32 -1
- package/dist/index.js +5 -1
- package/dist/load-config/index.js +1 -1
- package/dist/load-config/load-evolve-config.js +41 -1
- package/dist/load-config/types.js +1 -1
- package/dist/main/create-thread-worker.js +42 -1
- package/dist/main/env-verify.js +21 -1
- package/dist/main/get-worker-path.js +5 -1
- package/dist/main/index.js +4 -1
- package/dist/main/prepare-build.js +38 -1
- package/dist/main/prepare-serve.js +45 -1
- package/dist/main/prepare-static.js +30 -1
- package/dist/main/start-build-dynamic.js +157 -1
- package/dist/main/start-build-worker.js +46 -1
- package/dist/main/start-build.js +53 -1
- package/dist/main/start-one-entry-build.js +35 -1
- package/dist/main/start-serve.js +34 -1
- package/dist/main/start-static.js +19 -1
- package/dist/minimizer/create-minimizers.js +25 -1
- package/dist/minimizer/default-options.js +14 -1
- package/dist/minimizer/image-minimizer.js +65 -1
- package/dist/minimizer/index.js +1 -1
- package/dist/minimizer/terser-minimizer.js +15 -3
- package/dist/minimizer/types.js +1 -1
- package/dist/plugins/circular-dependency/circular-dependency-plugin.js +119 -1
- package/dist/plugins/circular-dependency/index.js +15 -1
- package/dist/plugins/clean-webpack/clean-webpack-plugin.js +173 -1
- package/dist/plugins/clean-webpack/index.js +22 -1
- package/dist/plugins/define-variable/define-variable-plugin.js +28 -1
- package/dist/plugins/define-variable/index.js +1 -1
- package/dist/plugins/html-inject-scripts/plugin-html-inject-script.js +27 -1
- package/dist/plugins/module-federation/external-template-remotes.js +92 -1
- package/dist/plugins/module-federation/index.js +1 -1
- package/dist/plugins/module-federation/module-federation.js +98 -1
- package/dist/plugins/multi-html/index.js +15 -1
- package/dist/plugins/multi-html/multi-html-cdn-plugin.js +84 -1
- package/dist/plugins/multi-html/multi-html-plugin.js +70 -1
- package/dist/plugins/ts-checker/index.d.ts +1 -0
- package/dist/plugins/ts-checker/index.js +1 -0
- package/dist/plugins/ts-checker/ts-checker-plugin.d.ts +4 -0
- package/dist/plugins/ts-checker/ts-checker-plugin.js +18 -0
- package/dist/types/index.js +8 -1
- package/dist/types/types-ci.js +1 -1
- package/dist/types/types-dev-server.js +1 -1
- package/dist/types/types-entry-map.js +1 -1
- package/dist/types/types-federation.js +1 -1
- package/dist/types/types-loader-options.js +1 -1
- package/dist/types/types-modular-import.js +1 -1
- package/dist/types/types-multi-html.js +1 -1
- package/dist/types/types-options.js +1 -1
- package/dist/types/types-plugin-options.js +1 -1
- package/dist/types/types-webpack.js +1 -1
- package/package.json +5 -5
@@ -1 +1,92 @@
|
|
1
|
-
import webpackSources from
|
1
|
+
import webpackSources from 'webpack-sources';
|
2
|
+
const PLUGIN_NAME = 'ExternalTemplateRemotesPlugin';
|
3
|
+
const isExternalModule = (module) => {
|
4
|
+
return module.constructor.name === 'ExternalModule';
|
5
|
+
};
|
6
|
+
/**
|
7
|
+
* @param {string} urlAndGlobal the script request
|
8
|
+
* @returns {string[]} script url and its global variable
|
9
|
+
*/
|
10
|
+
function extractUrlAndGlobal(urlAndGlobal) {
|
11
|
+
const index = urlAndGlobal.indexOf('@');
|
12
|
+
if (index <= 0 || index === urlAndGlobal.length - 1) {
|
13
|
+
throw new Error(`Invalid request "${urlAndGlobal}"`);
|
14
|
+
}
|
15
|
+
return [urlAndGlobal.substring(index + 1), urlAndGlobal.substring(0, index)];
|
16
|
+
}
|
17
|
+
export class ExternalTemplateRemotesPlugin {
|
18
|
+
apply(compiler) {
|
19
|
+
compiler.hooks.make.tap(PLUGIN_NAME, (compilation) => {
|
20
|
+
const scriptExternalModules = [];
|
21
|
+
compilation.hooks.buildModule.tap(PLUGIN_NAME, (module) => {
|
22
|
+
if (isExternalModule(module) && module.externalType === 'script') {
|
23
|
+
scriptExternalModules.push(module);
|
24
|
+
}
|
25
|
+
});
|
26
|
+
compilation.hooks.afterCodeGeneration.tap(PLUGIN_NAME, () => {
|
27
|
+
scriptExternalModules.forEach((module) => {
|
28
|
+
const urlTemplate = extractUrlAndGlobal(module.request)[0];
|
29
|
+
const urlExpression = toExpression(urlTemplate);
|
30
|
+
const sourceMap = compilation.codeGenerationResults.get(module, undefined).sources;
|
31
|
+
const rawSource = sourceMap.get('javascript');
|
32
|
+
if (rawSource) {
|
33
|
+
const source = new webpackSources.RawSource(rawSource
|
34
|
+
.source()
|
35
|
+
.toString()
|
36
|
+
.replace(`"${urlTemplate}"`, urlExpression));
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
38
|
+
sourceMap.set('javascript', source);
|
39
|
+
}
|
40
|
+
});
|
41
|
+
});
|
42
|
+
});
|
43
|
+
}
|
44
|
+
}
|
45
|
+
/**
|
46
|
+
* app2@localhost/remoteEntry.js --> "\"app2@localhost/remoteEntry.js\""
|
47
|
+
* app2@[window.app2Url]/remoteEntry.js --> "\"app2@\" + window.app2Url + \"/remoteEntry.js\""
|
48
|
+
* @param templateUrl
|
49
|
+
* @returns
|
50
|
+
*/
|
51
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity
|
52
|
+
function toExpression(templateUrl) {
|
53
|
+
const result = [];
|
54
|
+
const current = [];
|
55
|
+
let isExpression = false;
|
56
|
+
let invalid = false;
|
57
|
+
for (const c of templateUrl) {
|
58
|
+
if (c === '[') {
|
59
|
+
if (isExpression) {
|
60
|
+
invalid = true;
|
61
|
+
break;
|
62
|
+
}
|
63
|
+
isExpression = true;
|
64
|
+
if (current.length) {
|
65
|
+
result.push(`"${current.join('')}"`);
|
66
|
+
current.length = 0;
|
67
|
+
}
|
68
|
+
}
|
69
|
+
else if (c === ']') {
|
70
|
+
if (!isExpression) {
|
71
|
+
invalid = true;
|
72
|
+
break;
|
73
|
+
}
|
74
|
+
isExpression = false;
|
75
|
+
if (current.length) {
|
76
|
+
result.push(`${current.join('')}`);
|
77
|
+
current.length = 0;
|
78
|
+
}
|
79
|
+
current.length = 0;
|
80
|
+
}
|
81
|
+
else {
|
82
|
+
current.push(c);
|
83
|
+
}
|
84
|
+
}
|
85
|
+
if (isExpression || invalid) {
|
86
|
+
throw new Error(`Invalid template URL "${templateUrl}"`);
|
87
|
+
}
|
88
|
+
if (current.length) {
|
89
|
+
result.push(`"${current.join('')}"`);
|
90
|
+
}
|
91
|
+
return result.join(' + ');
|
92
|
+
}
|
@@ -1 +1 @@
|
|
1
|
-
export*from
|
1
|
+
export * from './module-federation.js';
|
@@ -1 +1,98 @@
|
|
1
|
-
import
|
1
|
+
import { join } from 'node:path';
|
2
|
+
import { ensureSlash } from '@flatjs/common';
|
3
|
+
import webpack from 'webpack';
|
4
|
+
import { normalizeEvolveEntryName } from '../../helpers/normalize-entry-map.js';
|
5
|
+
import { injectFederationScripts } from '../../helpers/script-injects.js';
|
6
|
+
import { HtmlInjectScriptPlugin } from '../html-inject-scripts/plugin-html-inject-script.js';
|
7
|
+
import { ExternalTemplateRemotesPlugin } from './external-template-remotes.js';
|
8
|
+
/**
|
9
|
+
* `${projectVirtualPath}/mine` --> evolve_demo_mine
|
10
|
+
* @param entryPath `${projectVirtualPath}/mine`
|
11
|
+
*/
|
12
|
+
const normalizeWidgetName = (entryPath = '') => {
|
13
|
+
return entryPath.replace(/[/-]/g, '_').toLowerCase();
|
14
|
+
};
|
15
|
+
const remoteFileName = (entryName) => {
|
16
|
+
return join(entryName, `micro-remote-module.js`);
|
17
|
+
};
|
18
|
+
export const createModuleFederationPlugin = (serveMode, entryMapItem, evolveOptions) => {
|
19
|
+
const projectVirtualPath = evolveOptions.projectVirtualPath;
|
20
|
+
const [entryName, entryConfig] = entryMapItem;
|
21
|
+
const multiCdnConfig = evolveOptions.multiHtmlCdn;
|
22
|
+
const multiHtmlCdnResolver = evolveOptions.multiHtmlCdnEnvResolver;
|
23
|
+
const moduleFederation = entryConfig.options?.moduleFederation;
|
24
|
+
const plugins = [];
|
25
|
+
if (moduleFederation) {
|
26
|
+
const { remotes, exposes, ...restFederationOptions } = moduleFederation;
|
27
|
+
// e.g. `flatjs/evolve/mine` => `flatjs/evolve/home/micro-remote-module.js`
|
28
|
+
const entryRemoteFileName = remoteFileName(entryName);
|
29
|
+
// e.g. `flatjs/evolve/mine` => `flatjs_evolve_mine`
|
30
|
+
const containerName = normalizeWidgetName(entryName);
|
31
|
+
const patchExposes = exposes
|
32
|
+
? Array.isArray(exposes)
|
33
|
+
? exposes
|
34
|
+
: [exposes]
|
35
|
+
: [];
|
36
|
+
const myExposes = patchExposes.map((s) => {
|
37
|
+
const exposeItem = {};
|
38
|
+
for (const [key, config] of Object.entries(s)) {
|
39
|
+
exposeItem[key] = {
|
40
|
+
...config,
|
41
|
+
name: join(entryName, config.name.replace(/^\//, '')),
|
42
|
+
};
|
43
|
+
}
|
44
|
+
return exposeItem;
|
45
|
+
});
|
46
|
+
const myRemotes = (remotes || []).map(({ name, endpoint }) => {
|
47
|
+
// e.g. `flatjs/evolve/home`
|
48
|
+
const normalizedEntryName = normalizeEvolveEntryName(name, projectVirtualPath);
|
49
|
+
// e.g. `flatjs_evolve_home`
|
50
|
+
const remoteWidgetName = normalizeWidgetName(normalizedEntryName);
|
51
|
+
// e.g. `flatjs/evolve/home/micro-remote-module.js`
|
52
|
+
const refRemoteEntryFileName = remoteFileName(normalizedEntryName);
|
53
|
+
// construct endpoint for remote widget name.
|
54
|
+
const endpointPath = endpoint
|
55
|
+
? ensureSlash(endpoint(name, normalizedEntryName), false)
|
56
|
+
: `[window.evolveFetchMicroWidgets()]`;
|
57
|
+
return {
|
58
|
+
[remoteWidgetName]: `${remoteWidgetName}@${endpointPath}/${refRemoteEntryFileName}`,
|
59
|
+
};
|
60
|
+
});
|
61
|
+
plugins.push(
|
62
|
+
// https://webpack.js.org/plugins/module-federation-plugin/
|
63
|
+
new webpack.container.ModuleFederationPlugin({
|
64
|
+
/**
|
65
|
+
* Options for library.
|
66
|
+
* library: { type: 'var', name: containerName },
|
67
|
+
* other module federation configurations
|
68
|
+
*/
|
69
|
+
...restFederationOptions,
|
70
|
+
/**
|
71
|
+
* The name of the container
|
72
|
+
* `${projectName}-${moduleName}` e.g. `flatjs_evolve_home`
|
73
|
+
*/
|
74
|
+
name: containerName,
|
75
|
+
/**
|
76
|
+
* The filename of the container as relative path inside the `output.path` directory.
|
77
|
+
* `${entryName}/micro-remote-module.js`, e.g. `flatjs/evolve/home/micro-remote-module.js`
|
78
|
+
*/
|
79
|
+
filename: entryRemoteFileName,
|
80
|
+
/**
|
81
|
+
* Container locations and request scopes from which modules should be resolved and loaded at runtime.
|
82
|
+
* When provided, property name is used as request scope, otherwise request scope is automatically inferred from container location.
|
83
|
+
*/
|
84
|
+
remotes: myRemotes,
|
85
|
+
/**
|
86
|
+
* Modules that should be exposed by this container.
|
87
|
+
* When provided, property name is used as public name, otherwise public name is automatically inferred from request.
|
88
|
+
*/
|
89
|
+
exposes: myExposes,
|
90
|
+
}), new ExternalTemplateRemotesPlugin());
|
91
|
+
if (!serveMode) {
|
92
|
+
plugins.unshift(new HtmlInjectScriptPlugin([
|
93
|
+
injectFederationScripts(multiCdnConfig, multiHtmlCdnResolver),
|
94
|
+
]));
|
95
|
+
}
|
96
|
+
}
|
97
|
+
return plugins;
|
98
|
+
};
|
@@ -1 +1,15 @@
|
|
1
|
-
import{FlatEvolveMultiCdnPlugin}from
|
1
|
+
import { FlatEvolveMultiCdnPlugin } from './multi-html-cdn-plugin.js';
|
2
|
+
import { createMultiHtmlWebpackPlugin } from './multi-html-plugin.js';
|
3
|
+
export const createHtmlPlugins = (serveMode, entryMapItem, evolveOptions) => {
|
4
|
+
const plugins = [];
|
5
|
+
// Only for `production`, or `library` compiler mode do not need to attach `html-webpack-plugin`
|
6
|
+
if (serveMode || entryMapItem[1]?.options?.output?.library) {
|
7
|
+
return plugins;
|
8
|
+
}
|
9
|
+
// Attach `html-webpack-plugin` first
|
10
|
+
const allEnv = Object.keys(evolveOptions.multiHtmlCdn);
|
11
|
+
plugins.push(...createMultiHtmlWebpackPlugin(serveMode, evolveOptions, entryMapItem, allEnv));
|
12
|
+
// Attach `@flatjs/evolve-plugin-multi-html-cdn`
|
13
|
+
plugins.push(new FlatEvolveMultiCdnPlugin(evolveOptions));
|
14
|
+
return plugins;
|
15
|
+
};
|
@@ -1 +1,84 @@
|
|
1
|
-
import
|
1
|
+
import { basename } from 'node:path';
|
2
|
+
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
3
|
+
import webpack from 'webpack';
|
4
|
+
import { cdnFinder, findEnvCdn, httpUrlJoin, } from '../../helpers/script-injects.js';
|
5
|
+
export class FlatEvolveMultiCdnPlugin {
|
6
|
+
constructor(evolveOptions) {
|
7
|
+
this.pluginName = 'FlatEvolveMultiCdnPlugin';
|
8
|
+
// https://github.com/webpack/webpack/blob/3d653290fafe385277b48e5a36807124618b9561/lib/MainTemplate.js#L12
|
9
|
+
// the bundle public path RuntimeGlobals.publicPath: '__webpack_require__.p';
|
10
|
+
this.requireFn = webpack.RuntimeGlobals.publicPath;
|
11
|
+
this.config = evolveOptions.multiHtmlCdn;
|
12
|
+
this.cdnResolver =
|
13
|
+
evolveOptions.multiHtmlCdnEnvResolver ||
|
14
|
+
function cdnResolver() {
|
15
|
+
return undefined;
|
16
|
+
};
|
17
|
+
// Make sure we have `prod` configuration for each cdn node at least.
|
18
|
+
if (!this.config?.prod) {
|
19
|
+
throw new Error('We must setup `prod` for each CDN config node!');
|
20
|
+
}
|
21
|
+
}
|
22
|
+
/**
|
23
|
+
* Apply the plugin to check if there are non initial chunks which need to be imported using `require-ensure` or `import`
|
24
|
+
* https://github.com/webpack/webpack/blob/3d653290fafe385277b48e5a36807124618b9561/lib/MainTemplate.js#L158
|
25
|
+
* https://www.npmjs.com/package/vscode-webpack-debugger
|
26
|
+
* https://www.cnblogs.com/Scar007/p/9166068.html
|
27
|
+
* https://www.cnblogs.com/pluslius/p/10271537.html
|
28
|
+
*/
|
29
|
+
apply(compiler) {
|
30
|
+
// Handle chunk assets while `Compilation:before-chunk-assets`
|
31
|
+
// https://github.com/webpack/webpack/blob/3d653290fafe385277b48e5a36807124618b9561/lib/MainTemplate.js#L58
|
32
|
+
compiler.hooks.thisCompilation.tap(this.pluginName, (compilation) => {
|
33
|
+
compilation.mainTemplate.hooks.requireExtensions.tap(this.pluginName, (_source, chunk) => {
|
34
|
+
const buf = [];
|
35
|
+
buf.push('// Dynamic assets path override(`@flatjs/evolve`) plugin-multi-html-cdn`)');
|
36
|
+
const runtimeRequirements = compilation.chunkGraph?.getTreeRuntimeRequirements(chunk);
|
37
|
+
if (runtimeRequirements &&
|
38
|
+
runtimeRequirements.has(webpack.RuntimeGlobals.requireScope)) {
|
39
|
+
buf.push('(function () {');
|
40
|
+
buf.push(webpack.Template.indent(`var flatjsMultiCdn = {`));
|
41
|
+
buf.push(webpack.Template.indent(webpack.Template.indent([
|
42
|
+
`cdnConfig: ${JSON.stringify(this.config || {})},`,
|
43
|
+
])));
|
44
|
+
buf.push(webpack.Template.indent(webpack.Template.indent([
|
45
|
+
`cdnResolver: ${this.cdnResolver.toString()},`,
|
46
|
+
])));
|
47
|
+
buf.push(webpack.Template.indent(webpack.Template.indent([`cdnFinder: ${cdnFinder.toString()}`])));
|
48
|
+
buf.push(webpack.Template.indent(`};`));
|
49
|
+
buf.push(webpack.Template.indent(`${this.requireFn} = flatjsMultiCdn.cdnFinder(flatjsMultiCdn.cdnConfig, flatjsMultiCdn.cdnResolver) || ${this.requireFn};`));
|
50
|
+
buf.push('})();');
|
51
|
+
}
|
52
|
+
return webpack.Template.asString(buf);
|
53
|
+
});
|
54
|
+
});
|
55
|
+
// Using html webpack plugin hooks to replace `scripts` `styles` before inject to html temlate file.
|
56
|
+
compiler.hooks.compilation.tap(this.pluginName, (compilation) => {
|
57
|
+
HtmlWebpackPlugin.getHooks(compilation).beforeAssetTagGeneration.tap(this.pluginName, (data) => {
|
58
|
+
const { assets } = data;
|
59
|
+
const { userOptions } = data.plugin;
|
60
|
+
const multiCdn = userOptions.multiCdn;
|
61
|
+
const publicPath = assets.publicPath;
|
62
|
+
const scripts = assets.js.map((scriptItem) => {
|
63
|
+
// Normally for `index-dev.html` we need to use relative path.
|
64
|
+
if (multiCdn.disabled) {
|
65
|
+
return basename(scriptItem);
|
66
|
+
}
|
67
|
+
const randomCdn = findEnvCdn(this.config, multiCdn.env);
|
68
|
+
return httpUrlJoin(randomCdn, scriptItem.replace(publicPath, ''));
|
69
|
+
});
|
70
|
+
const styles = assets.css.map((styleItem) => {
|
71
|
+
// Normally for `index-dev.html` we need to use relative path.
|
72
|
+
if (multiCdn.disabled) {
|
73
|
+
return basename(styleItem);
|
74
|
+
}
|
75
|
+
const randomCdn = findEnvCdn(this.config, multiCdn.env);
|
76
|
+
return httpUrlJoin(randomCdn, styleItem.replace(publicPath, ''));
|
77
|
+
});
|
78
|
+
data.assets.js = scripts;
|
79
|
+
data.assets.css = styles;
|
80
|
+
return data;
|
81
|
+
});
|
82
|
+
});
|
83
|
+
}
|
84
|
+
}
|
@@ -1 +1,70 @@
|
|
1
|
-
import HtmlWebpackPlugin from
|
1
|
+
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
2
|
+
import { allowPx2remForModule } from '../../helpers/allow-px2rem-for-module.js';
|
3
|
+
import { getHtmlPluginConfig, } from '../../helpers/get-html-plugin-config.js';
|
4
|
+
import { findEnvCdn } from '../../helpers/script-injects.js';
|
5
|
+
const minifyOpts = {
|
6
|
+
minifyJS: true,
|
7
|
+
removeComments: true,
|
8
|
+
collapseWhitespace: true,
|
9
|
+
collapseBooleanAttributes: false,
|
10
|
+
};
|
11
|
+
/**
|
12
|
+
* Create `html-webpack-plugin` for this build, refer to best practices
|
13
|
+
* We'd better pass only one entry for each `build` cycle
|
14
|
+
* @param buildEntryItem the entries for this `build`
|
15
|
+
* @param allEnv
|
16
|
+
*/
|
17
|
+
export const createMultiHtmlWebpackPlugin = (serveMode, evolveOptions, entryMapItem, allEnv) => {
|
18
|
+
const [entryKey, entryConfig] = entryMapItem;
|
19
|
+
const htmlPlugins = [];
|
20
|
+
const { options } = entryConfig;
|
21
|
+
const mode = serveMode ? 'development' : 'production';
|
22
|
+
for (const env of allEnv) {
|
23
|
+
const envCdn = findEnvCdn(evolveOptions.multiHtmlCdn, env);
|
24
|
+
const configData = {
|
25
|
+
mode,
|
26
|
+
envCdn,
|
27
|
+
};
|
28
|
+
htmlPlugins.push(new HtmlWebpackPlugin({
|
29
|
+
inject: 'body',
|
30
|
+
title: getHtmlPluginConfig('title', configData, options?.title),
|
31
|
+
chunks: [entryKey],
|
32
|
+
// `minify` is true, `dev` always don't minify.
|
33
|
+
minify: options?.htmlMinify === false || ['me', 'dev'].includes(env)
|
34
|
+
? false
|
35
|
+
: minifyOpts,
|
36
|
+
// output file path
|
37
|
+
filename: `${entryKey}/index${env === 'prod' ? '' : `-${env}`}.html`,
|
38
|
+
// html template
|
39
|
+
template: getHtmlPluginConfig('templatePath', configData, options?.templatePath).replace(`{0}`, env),
|
40
|
+
// template parameters
|
41
|
+
templateParameters: {
|
42
|
+
// The page title
|
43
|
+
title: getHtmlPluginConfig('title', configData, options?.title),
|
44
|
+
// The page favicon
|
45
|
+
favicon: getHtmlPluginConfig('favicon', configData, options?.favicon),
|
46
|
+
// The customized inject head tags.
|
47
|
+
headBeforeHtmlTags: getHtmlPluginConfig('headBeforeHtmlTags', configData, options?.headBeforeHtmlTags),
|
48
|
+
// The customized inject inline scripts.
|
49
|
+
inlineScripts: getHtmlPluginConfig('inlineScripts', configData, options?.inlineScripts),
|
50
|
+
// The ordered styles will be injected start of html head.
|
51
|
+
headBeforeStyles: getHtmlPluginConfig('headBeforeStyles', configData, options?.headBeforeStyles),
|
52
|
+
// The ordered scripts will be injected before html head.
|
53
|
+
headBeforeScripts: getHtmlPluginConfig('headBeforeScripts', configData, options?.headBeforeScripts),
|
54
|
+
// The ordered scripts will be injected end of html body.
|
55
|
+
bodyAfterScripts: getHtmlPluginConfig('bodyAfterScripts', configData, options?.bodyAfterScripts),
|
56
|
+
// `allowPx2rem` default is true
|
57
|
+
viewport: allowPx2remForModule(entryMapItem, evolveOptions)
|
58
|
+
? getHtmlPluginConfig('viewport', configData, options?.viewport)
|
59
|
+
: '',
|
60
|
+
},
|
61
|
+
// Some options for plugin used the `hook` of `html-webpack-plugin`
|
62
|
+
multiCdn: {
|
63
|
+
env,
|
64
|
+
// use relative path for `me`, `dev`, `ntv`
|
65
|
+
disabled: (options?.excludeCdnEnvs || ['me', 'dev', 'ntv']).includes(env),
|
66
|
+
},
|
67
|
+
}));
|
68
|
+
}
|
69
|
+
return htmlPlugins;
|
70
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './ts-checker-plugin.js';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './ts-checker-plugin.js';
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import { type WebpackPlugin } from '../../create-webpack/types.js';
|
2
|
+
import { type EntryMapItem } from '../../types/types-entry-map.js';
|
3
|
+
import { type FlatEvolveOptions } from '../../types/types-options.js';
|
4
|
+
export declare const createTsCheckerPlugins: (serveMode: boolean, entryMapItem: EntryMapItem, evolveOptions: FlatEvolveOptions) => WebpackPlugin[];
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
|
2
|
+
export const createTsCheckerPlugins = (serveMode, entryMapItem, evolveOptions) => {
|
3
|
+
const plugins = [];
|
4
|
+
const itemEntries = entryMapItem[1].entry || [];
|
5
|
+
const isVueEntryItem = itemEntries.find((s) => /.vue$/.test(s));
|
6
|
+
// Runs typescript type checker and linter on separate process.
|
7
|
+
if (evolveOptions.loaderOptions.runTsChecker && !isVueEntryItem) {
|
8
|
+
plugins.push(new ForkTsCheckerWebpackPlugin({
|
9
|
+
async: serveMode,
|
10
|
+
issue: {},
|
11
|
+
typescript: {
|
12
|
+
context: evolveOptions.projectCwd,
|
13
|
+
memoryLimit: 2048 * 4,
|
14
|
+
},
|
15
|
+
}));
|
16
|
+
}
|
17
|
+
return plugins;
|
18
|
+
};
|
package/dist/types/index.js
CHANGED
@@ -1 +1,8 @@
|
|
1
|
-
export*from
|
1
|
+
export * from './types-dev-server.js';
|
2
|
+
export * from './types-entry-map.js';
|
3
|
+
export * from './types-federation.js';
|
4
|
+
export * from './types-modular-import.js';
|
5
|
+
export * from './types-multi-html.js';
|
6
|
+
export * from './types-options.js';
|
7
|
+
export * from './types-loader-options.js';
|
8
|
+
export * from './types-webpack.js';
|
package/dist/types/types-ci.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export{};
|
1
|
+
export {};
|
@@ -1 +1 @@
|
|
1
|
-
export{};
|
1
|
+
export {};
|
@@ -1 +1 @@
|
|
1
|
-
export{};
|
1
|
+
export {};
|
@@ -1 +1 @@
|
|
1
|
-
export{};
|
1
|
+
export {};
|
@@ -1 +1 @@
|
|
1
|
-
export{};
|
1
|
+
export {};
|
@@ -1 +1 @@
|
|
1
|
-
export{};
|
1
|
+
export {};
|
@@ -1 +1 @@
|
|
1
|
-
export{};
|
1
|
+
export {};
|
@@ -1 +1 @@
|
|
1
|
-
export{};
|
1
|
+
export {};
|
@@ -1 +1 @@
|
|
1
|
-
export{};
|
1
|
+
export {};
|
@@ -1 +1 @@
|
|
1
|
-
export{};
|
1
|
+
export {};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@flatjs/evolve",
|
3
|
-
"version": "2.1.0-next.
|
3
|
+
"version": "2.1.0-next.5",
|
4
4
|
"license": "MIT",
|
5
5
|
"type": "module",
|
6
6
|
"exports": {
|
@@ -19,7 +19,7 @@
|
|
19
19
|
],
|
20
20
|
"scripts": {
|
21
21
|
"serve": "yarn node --import=@armit/path-alias/register ./tests/dev-server/dev-server.ts",
|
22
|
-
"build": "rimraf dist && tsc -p ./tsconfig.build.json
|
22
|
+
"build": "rimraf dist && tsc -p ./tsconfig.build.json",
|
23
23
|
"?build-release": "When https://github.com/atlassian/changesets/issues/432 has a solution we can remove this trick",
|
24
24
|
"build-release": "yarn build && rimraf ./_release && yarn pack && mkdir ./_release && tar zxvf ./package.tgz --directory ./_release && rm ./package.tgz",
|
25
25
|
"minify": "node ../../scripts/minify.mjs --dest=dist",
|
@@ -41,12 +41,12 @@
|
|
41
41
|
"@armit/package": "^0.1.5",
|
42
42
|
"@armit/worker-threads": "^0.1.4",
|
43
43
|
"@babel/core": "7.24.3",
|
44
|
-
"@flatjs/babel-plugin-import": "2.1.0-next.
|
44
|
+
"@flatjs/babel-plugin-import": "2.1.0-next.3",
|
45
45
|
"@flatjs/common": "2.1.0-next.2",
|
46
46
|
"@flatjs/evolve-preset-babel": "2.1.0-next.2",
|
47
47
|
"@flatjs/forge-postcss-plugin-pixel": "2.1.0-next.2",
|
48
|
-
"@flatjs/graph": "2.1.0-next.
|
49
|
-
"@flatjs/mock": "2.1.0-next.
|
48
|
+
"@flatjs/graph": "2.1.0-next.4",
|
49
|
+
"@flatjs/mock": "2.1.0-next.4",
|
50
50
|
"@pmmmwh/react-refresh-webpack-plugin": "0.5.11",
|
51
51
|
"@types/babel__core": "7.20.5",
|
52
52
|
"babel-loader": "9.1.3",
|