@modern-js/app-tools 2.0.0-beta.0 → 2.0.0-beta.2
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/CHANGELOG.md +375 -0
- package/dist/js/modern/analyze/generateCode.js +30 -38
- package/dist/js/modern/analyze/getBundleEntry.js +5 -13
- package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +5 -30
- package/dist/js/modern/analyze/getClientRoutes/getRoutesLegacy.js +5 -30
- package/dist/js/modern/analyze/getClientRoutes/utils.js +0 -3
- package/dist/js/modern/analyze/getFileSystemEntry.js +5 -18
- package/dist/js/modern/analyze/getHtmlTemplate.js +3 -10
- package/dist/js/modern/analyze/getServerRoutes.js +25 -38
- package/dist/js/modern/analyze/index.js +90 -48
- package/dist/js/modern/analyze/isDefaultExportFunction.js +0 -4
- package/dist/js/modern/analyze/makeLegalIdentifier.js +0 -2
- package/dist/js/modern/analyze/nestedRoutes.js +8 -33
- package/dist/js/modern/analyze/templates.js +22 -37
- package/dist/js/modern/analyze/utils.js +0 -7
- package/dist/js/modern/builder/builderPlugins/compatModern.js +41 -58
- package/dist/js/modern/builder/index.js +56 -37
- package/dist/js/modern/builder/share.js +1 -5
- package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -8
- package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +2 -13
- package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +97 -0
- package/dist/js/modern/commands/build.js +12 -46
- package/dist/js/modern/commands/dev.js +20 -23
- package/dist/js/modern/commands/inspect.js +4 -19
- package/dist/js/modern/commands/start.js +1 -2
- package/dist/js/modern/config/default.js +207 -0
- package/dist/js/modern/config/index.js +2 -0
- package/dist/js/modern/config/initial/createHtmlConfig.js +32 -0
- package/dist/js/modern/{builder → config/initial}/createOutputConfig.js +19 -18
- package/dist/js/modern/config/initial/createSourceConfig.js +32 -0
- package/dist/js/modern/config/initial/createToolsConfig.js +41 -0
- package/dist/js/modern/config/initial/index.js +11 -0
- package/dist/js/modern/config/initial/inits.js +117 -0
- package/dist/js/modern/config/initial/transformNormalizedConfig.js +40 -0
- package/dist/js/modern/defineConfig.js +12 -0
- package/dist/js/modern/hooks.js +23 -19
- package/dist/js/modern/index.js +12 -19
- package/dist/js/modern/initialize/index.js +72 -0
- package/dist/js/modern/schema/Schema.js +39 -0
- package/dist/js/modern/schema/index.js +139 -0
- package/dist/js/modern/schema/legacy.js +284 -0
- package/dist/js/modern/types/config/deploy.js +0 -0
- package/dist/js/modern/types/config/dev.js +0 -0
- package/dist/js/modern/types/config/experiments.js +0 -0
- package/dist/js/modern/types/config/html.js +0 -0
- package/dist/js/modern/types/config/index.js +2 -0
- package/dist/js/modern/types/config/output.js +0 -0
- package/dist/js/modern/types/config/performance.js +0 -0
- package/dist/js/modern/types/config/security.js +0 -0
- package/dist/js/modern/types/config/source.js +0 -0
- package/dist/js/modern/types/config/tools.js +0 -0
- package/dist/js/modern/types/hooks.js +0 -0
- package/dist/js/modern/types/index.js +4 -0
- package/dist/js/modern/types/legacyConfig/deploy.js +0 -0
- package/dist/js/modern/types/legacyConfig/dev.js +0 -0
- package/dist/js/modern/types/legacyConfig/index.js +0 -0
- package/dist/js/modern/types/legacyConfig/output.js +1 -0
- package/dist/js/modern/types/legacyConfig/source.js +0 -0
- package/dist/js/modern/types/legacyConfig/tools.js +0 -0
- package/dist/js/modern/utils/config.js +2 -13
- package/dist/js/modern/utils/createFileWatcher.js +82 -0
- package/dist/js/modern/utils/createServer.js +0 -5
- package/dist/js/modern/utils/getSpecifiedEntries.js +0 -6
- package/dist/js/modern/utils/printInstructions.js +2 -1
- package/dist/js/modern/utils/restart.js +17 -0
- package/dist/js/modern/utils/routes.js +0 -2
- package/dist/js/node/analyze/generateCode.js +30 -61
- package/dist/js/node/analyze/getBundleEntry.js +5 -19
- package/dist/js/node/analyze/getClientRoutes/getRoutes.js +5 -45
- package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +5 -45
- package/dist/js/node/analyze/getClientRoutes/index.js +0 -2
- package/dist/js/node/analyze/getClientRoutes/utils.js +0 -14
- package/dist/js/node/analyze/getFileSystemEntry.js +5 -26
- package/dist/js/node/analyze/getHtmlTemplate.js +3 -24
- package/dist/js/node/analyze/getServerRoutes.js +24 -46
- package/dist/js/node/analyze/index.js +91 -70
- package/dist/js/node/analyze/isDefaultExportFunction.js +0 -12
- package/dist/js/node/analyze/makeLegalIdentifier.js +0 -4
- package/dist/js/node/analyze/nestedRoutes.js +8 -41
- package/dist/js/node/analyze/templates.js +22 -47
- package/dist/js/node/analyze/utils.js +0 -20
- package/dist/js/node/builder/builderPlugins/compatModern.js +41 -69
- package/dist/js/node/builder/index.js +57 -51
- package/dist/js/node/builder/share.js +1 -13
- package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -10
- package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +2 -15
- package/dist/js/node/builder/webpackPlugins/routerPlugin.js +105 -0
- package/dist/js/node/commands/build.js +10 -57
- package/dist/js/node/commands/deploy.js +0 -2
- package/dist/js/node/commands/dev.js +19 -34
- package/dist/js/node/commands/index.js +0 -6
- package/dist/js/node/commands/inspect.js +4 -26
- package/dist/js/node/commands/start.js +1 -11
- package/dist/js/node/config/default.js +214 -0
- package/dist/js/node/config/index.js +31 -0
- package/dist/js/node/config/initial/createHtmlConfig.js +38 -0
- package/dist/js/node/{builder → config/initial}/createOutputConfig.js +19 -20
- package/dist/js/node/config/initial/createSourceConfig.js +38 -0
- package/dist/js/node/config/initial/createToolsConfig.js +47 -0
- package/dist/js/node/config/initial/index.js +24 -0
- package/dist/js/node/config/initial/inits.js +127 -0
- package/dist/js/node/config/initial/transformNormalizedConfig.js +46 -0
- package/dist/js/node/defineConfig.js +20 -0
- package/dist/js/node/exports/server.js +0 -1
- package/dist/js/node/hooks.js +23 -30
- package/dist/js/node/index.js +35 -48
- package/dist/js/node/initialize/index.js +79 -0
- package/dist/js/node/locale/index.js +0 -4
- package/dist/js/node/schema/Schema.js +46 -0
- package/dist/js/node/schema/index.js +152 -0
- package/dist/js/node/schema/legacy.js +291 -0
- package/dist/js/node/types/config/deploy.js +0 -0
- package/dist/js/node/types/config/dev.js +0 -0
- package/dist/js/node/types/config/experiments.js +0 -0
- package/dist/js/node/types/config/html.js +0 -0
- package/dist/js/node/types/config/index.js +16 -0
- package/dist/js/node/types/config/output.js +0 -0
- package/dist/js/node/types/config/performance.js +0 -0
- package/dist/js/node/types/config/security.js +0 -0
- package/dist/js/node/types/config/source.js +0 -0
- package/dist/js/node/types/config/tools.js +0 -0
- package/dist/js/node/types/hooks.js +0 -0
- package/dist/js/node/types/index.js +38 -0
- package/dist/js/node/types/legacyConfig/deploy.js +0 -0
- package/dist/js/node/types/legacyConfig/dev.js +0 -0
- package/dist/js/node/types/legacyConfig/index.js +0 -0
- package/dist/js/node/types/legacyConfig/output.js +5 -0
- package/dist/js/node/types/legacyConfig/source.js +0 -0
- package/dist/js/node/types/legacyConfig/tools.js +0 -0
- package/dist/js/node/utils/commands.js +0 -2
- package/dist/js/node/utils/config.js +2 -26
- package/dist/js/node/utils/createFileWatcher.js +90 -0
- package/dist/js/node/utils/createServer.js +0 -15
- package/dist/js/node/utils/getSpecifiedEntries.js +0 -9
- package/dist/js/node/utils/language.js +0 -2
- package/dist/js/node/utils/printInstructions.js +2 -5
- package/dist/js/node/utils/restart.js +23 -0
- package/dist/js/node/utils/routes.js +0 -5
- package/dist/js/treeshaking/analyze/generateCode.js +58 -101
- package/dist/js/treeshaking/analyze/getBundleEntry.js +12 -20
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +16 -42
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +16 -42
- package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +0 -3
- package/dist/js/treeshaking/analyze/getFileSystemEntry.js +5 -18
- package/dist/js/treeshaking/analyze/getHtmlTemplate.js +3 -27
- package/dist/js/treeshaking/analyze/getServerRoutes.js +29 -41
- package/dist/js/treeshaking/analyze/index.js +195 -91
- package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +0 -4
- package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +0 -2
- package/dist/js/treeshaking/analyze/nestedRoutes.js +9 -51
- package/dist/js/treeshaking/analyze/templates.js +31 -50
- package/dist/js/treeshaking/analyze/utils.js +7 -14
- package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +50 -68
- package/dist/js/treeshaking/builder/index.js +69 -65
- package/dist/js/treeshaking/builder/share.js +1 -5
- package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +1 -13
- package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +2 -14
- package/dist/js/treeshaking/builder/webpackPlugins/routerPlugin.js +121 -0
- package/dist/js/treeshaking/commands/build.js +41 -116
- package/dist/js/treeshaking/commands/deploy.js +0 -3
- package/dist/js/treeshaking/commands/dev.js +38 -46
- package/dist/js/treeshaking/commands/inspect.js +9 -27
- package/dist/js/treeshaking/commands/start.js +1 -9
- package/dist/js/treeshaking/config/default.js +200 -0
- package/dist/js/treeshaking/config/index.js +2 -0
- package/dist/js/treeshaking/config/initial/createHtmlConfig.js +31 -0
- package/dist/js/treeshaking/config/initial/createOutputConfig.js +67 -0
- package/dist/js/treeshaking/config/initial/createSourceConfig.js +41 -0
- package/dist/js/treeshaking/config/initial/createToolsConfig.js +38 -0
- package/dist/js/treeshaking/config/initial/index.js +11 -0
- package/dist/js/treeshaking/config/initial/inits.js +114 -0
- package/dist/js/treeshaking/config/initial/transformNormalizedConfig.js +38 -0
- package/dist/js/treeshaking/defineConfig.js +14 -0
- package/dist/js/treeshaking/hooks.js +23 -19
- package/dist/js/treeshaking/index.js +8 -43
- package/dist/js/treeshaking/initialize/index.js +121 -0
- package/dist/js/treeshaking/schema/Schema.js +75 -0
- package/dist/js/treeshaking/schema/index.js +138 -0
- package/dist/js/treeshaking/schema/legacy.js +273 -0
- package/dist/js/treeshaking/types/config/deploy.js +0 -0
- package/dist/js/treeshaking/types/config/dev.js +0 -0
- package/dist/js/treeshaking/types/config/experiments.js +0 -0
- package/dist/js/treeshaking/types/config/html.js +0 -0
- package/dist/js/treeshaking/types/config/index.js +2 -0
- package/dist/js/treeshaking/types/config/output.js +0 -0
- package/dist/js/treeshaking/types/config/performance.js +0 -0
- package/dist/js/treeshaking/types/config/security.js +0 -0
- package/dist/js/treeshaking/types/config/source.js +0 -0
- package/dist/js/treeshaking/types/config/tools.js +0 -0
- package/dist/js/treeshaking/types/hooks.js +0 -0
- package/dist/js/treeshaking/types/index.js +4 -0
- package/dist/js/treeshaking/types/legacyConfig/deploy.js +0 -0
- package/dist/js/treeshaking/types/legacyConfig/dev.js +0 -0
- package/dist/js/treeshaking/types/legacyConfig/index.js +0 -0
- package/dist/js/treeshaking/types/legacyConfig/output.js +1 -0
- package/dist/js/treeshaking/types/legacyConfig/source.js +0 -0
- package/dist/js/treeshaking/types/legacyConfig/tools.js +0 -0
- package/dist/js/treeshaking/utils/config.js +2 -18
- package/dist/js/treeshaking/utils/createFileWatcher.js +123 -0
- package/dist/js/treeshaking/utils/createServer.js +0 -10
- package/dist/js/treeshaking/utils/getSpecifiedEntries.js +0 -10
- package/dist/js/treeshaking/utils/printInstructions.js +0 -5
- package/dist/js/treeshaking/utils/restart.js +45 -0
- package/dist/js/treeshaking/utils/routes.js +0 -4
- package/dist/types/analyze/generateCode.d.ts +3 -2
- package/dist/types/analyze/getBundleEntry.d.ts +2 -2
- package/dist/types/analyze/getFileSystemEntry.d.ts +2 -2
- package/dist/types/analyze/getHtmlTemplate.d.ts +3 -3
- package/dist/types/analyze/getServerRoutes.d.ts +3 -2
- package/dist/types/analyze/index.d.ts +3 -42
- package/dist/types/analyze/nestedRoutes.d.ts +1 -1
- package/dist/types/analyze/templates.d.ts +4 -2
- package/dist/types/analyze/utils.d.ts +1 -1
- package/dist/types/builder/builderPlugins/compatModern.d.ts +2 -3
- package/dist/types/builder/index.d.ts +7 -8
- package/dist/types/builder/share.d.ts +2 -2
- package/dist/types/builder/webpackPlugins/routerPlugin.d.ts +10 -0
- package/dist/types/commands/build.d.ts +2 -2
- package/dist/types/commands/deploy.d.ts +2 -2
- package/dist/types/commands/dev.d.ts +2 -2
- package/dist/types/commands/inspect.d.ts +6 -1
- package/dist/types/commands/start.d.ts +2 -2
- package/dist/types/config/default.d.ts +3 -0
- package/dist/types/config/index.d.ts +2 -0
- package/dist/types/config/initial/createHtmlConfig.d.ts +2 -0
- package/dist/types/config/initial/createOutputConfig.d.ts +2 -0
- package/dist/types/config/initial/createSourceConfig.d.ts +2 -0
- package/dist/types/config/initial/createToolsConfig.d.ts +2 -0
- package/dist/types/config/initial/index.d.ts +4 -0
- package/dist/types/config/initial/inits.d.ts +4 -0
- package/dist/types/config/initial/transformNormalizedConfig.d.ts +2 -0
- package/dist/types/defineConfig.d.ts +7 -0
- package/dist/types/hooks.d.ts +2 -42
- package/dist/types/index.d.ts +5 -7
- package/dist/types/initialize/index.d.ts +3 -0
- package/dist/types/schema/Schema.d.ts +14 -0
- package/dist/types/schema/index.d.ts +4 -0
- package/dist/types/schema/legacy.d.ts +3 -0
- package/dist/types/types/config/deploy.d.ts +9 -0
- package/dist/types/types/config/dev.d.ts +13 -0
- package/dist/types/types/config/experiments.d.ts +4 -0
- package/dist/types/types/config/html.d.ts +4 -0
- package/dist/types/types/config/index.d.ts +62 -0
- package/dist/types/types/config/output.d.ts +23 -0
- package/dist/types/types/config/performance.d.ts +4 -0
- package/dist/types/types/config/security.d.ts +4 -0
- package/dist/types/types/config/source.d.ts +22 -0
- package/dist/types/types/config/tools.d.ts +15 -0
- package/dist/types/types/hooks.d.ts +80 -0
- package/dist/types/types/index.d.ts +23 -0
- package/dist/types/types/legacyConfig/deploy.d.ts +8 -0
- package/dist/types/types/legacyConfig/dev.d.ts +12 -0
- package/dist/types/types/legacyConfig/index.d.ts +33 -0
- package/dist/types/types/legacyConfig/output.d.ts +51 -0
- package/dist/types/types/legacyConfig/source.d.ts +25 -0
- package/dist/types/types/legacyConfig/tools.d.ts +16 -0
- package/dist/types/utils/config.d.ts +2 -3
- package/dist/types/utils/createFileWatcher.d.ts +3 -0
- package/dist/types/utils/printInstructions.d.ts +3 -3
- package/dist/types/utils/restart.d.ts +3 -0
- package/package.json +26 -25
- package/dist/js/modern/builder/createHtmlConfig.js +0 -58
- package/dist/js/modern/builder/createSourceConfig.js +0 -85
- package/dist/js/modern/builder/createToolsConfig.js +0 -94
- package/dist/js/modern/utils/createCompiler.js +0 -58
- package/dist/js/node/builder/createHtmlConfig.js +0 -76
- package/dist/js/node/builder/createSourceConfig.js +0 -99
- package/dist/js/node/builder/createToolsConfig.js +0 -103
- package/dist/js/node/utils/createCompiler.js +0 -75
- package/dist/js/treeshaking/builder/createHtmlConfig.js +0 -59
- package/dist/js/treeshaking/builder/createOutputConfig.js +0 -67
- package/dist/js/treeshaking/builder/createSourceConfig.js +0 -100
- package/dist/js/treeshaking/builder/createToolsConfig.js +0 -90
- package/dist/js/treeshaking/utils/createCompiler.js +0 -117
- package/dist/types/builder/createHtmlConfig.d.ts +0 -6
- package/dist/types/builder/createOutputConfig.d.ts +0 -3
- package/dist/types/builder/createSourceConfig.d.ts +0 -5
- package/dist/types/builder/createToolsConfig.d.ts +0 -13
- package/dist/types/utils/createCompiler.d.ts +0 -12
|
@@ -9,7 +9,7 @@ import { getEntryOptions } from '@modern-js/utils';
|
|
|
9
9
|
import { BottomTemplatePlugin } from "../webpackPlugins/htmlBottomTemplate";
|
|
10
10
|
import { HtmlAsyncChunkPlugin } from "../webpackPlugins/htmlAsyncChunkPlugin";
|
|
11
11
|
import { createCopyPattern } from "../share";
|
|
12
|
-
|
|
12
|
+
import RouterPlugin from "../webpackPlugins/routerPlugin";
|
|
13
13
|
/**
|
|
14
14
|
* Provides default configuration consistent with `@modern-js/webpack`
|
|
15
15
|
*/
|
|
@@ -25,15 +25,14 @@ export var PluginCompatModern = function PluginCompatModern(appContext, modernCo
|
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
|
-
|
|
29
28
|
return config;
|
|
30
29
|
});
|
|
31
30
|
api.modifyWebpackChain(function (chain, _ref) {
|
|
32
31
|
var target = _ref.target,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
var builderNormalizedConfig = api.getNormalizedConfig();
|
|
36
|
-
|
|
32
|
+
CHAIN_ID = _ref.CHAIN_ID,
|
|
33
|
+
isProd = _ref.isProd;
|
|
34
|
+
var builderNormalizedConfig = api.getNormalizedConfig();
|
|
35
|
+
// set webpack config name
|
|
37
36
|
if (target === 'node') {
|
|
38
37
|
chain.name('server');
|
|
39
38
|
} else if (target === 'modern-web') {
|
|
@@ -41,13 +40,12 @@ export var PluginCompatModern = function PluginCompatModern(appContext, modernCo
|
|
|
41
40
|
} else {
|
|
42
41
|
chain.name('client');
|
|
43
42
|
}
|
|
43
|
+
chain.resolve.modules.add('node_modules').add(join(api.context.rootPath, 'node_modules'));
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
// apply node compat
|
|
47
46
|
if (target === 'node') {
|
|
48
47
|
applyNodeCompat(chain, modernConfig, isProd);
|
|
49
48
|
}
|
|
50
|
-
|
|
51
49
|
if (isHtmlEnabled(builderNormalizedConfig, target)) {
|
|
52
50
|
applyBottomHtmlWebpackPlugin({
|
|
53
51
|
api: api,
|
|
@@ -61,36 +59,40 @@ export var PluginCompatModern = function PluginCompatModern(appContext, modernCo
|
|
|
61
59
|
CHAIN_ID: CHAIN_ID,
|
|
62
60
|
modernConfig: modernConfig
|
|
63
61
|
});
|
|
64
|
-
}
|
|
65
|
-
// const copyPatterns = createCopyPatterns(chain, appContext, modernConfig);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
var defaultCopyPattern = createCopyPattern(appContext, modernConfig, 'public', chain);
|
|
69
|
-
chain.plugin(CHAIN_ID.PLUGIN.COPY).tap(function (args) {
|
|
70
|
-
var _args$;
|
|
62
|
+
}
|
|
71
63
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
64
|
+
// apply copy plugin
|
|
65
|
+
if (chain.plugins.has(CHAIN_ID.PLUGIN.COPY)) {
|
|
66
|
+
var defaultCopyPattern = createCopyPattern(appContext, modernConfig, 'public', chain);
|
|
67
|
+
chain.plugin(CHAIN_ID.PLUGIN.COPY).tap(function (args) {
|
|
68
|
+
var _args$;
|
|
69
|
+
return [{
|
|
70
|
+
patterns: [].concat(_toConsumableArray(((_args$ = args[0]) === null || _args$ === void 0 ? void 0 : _args$.patterns) || []), [defaultCopyPattern])
|
|
71
|
+
}];
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
var entrypoints = appContext.entrypoints;
|
|
75
|
+
var existNestedRoutes = entrypoints.some(function (entrypoint) {
|
|
76
|
+
return entrypoint.nestedRoutesEntry;
|
|
75
77
|
});
|
|
76
|
-
|
|
78
|
+
chain.plugin('route-plugin').use(RouterPlugin, [{
|
|
79
|
+
existNestedRoutes: existNestedRoutes
|
|
80
|
+
}]);
|
|
77
81
|
function isHtmlEnabled(config, target) {
|
|
78
82
|
var _config$tools;
|
|
79
|
-
|
|
80
83
|
return ((_config$tools = config.tools) === null || _config$tools === void 0 ? void 0 : _config$tools.htmlPlugin) !== false && target !== 'node' && target !== 'web-worker';
|
|
81
84
|
}
|
|
82
85
|
});
|
|
83
|
-
|
|
84
86
|
if (options) {
|
|
85
87
|
applyCallbacks(api, options);
|
|
86
88
|
}
|
|
87
89
|
}
|
|
88
90
|
};
|
|
89
91
|
};
|
|
92
|
+
|
|
90
93
|
/**
|
|
91
94
|
* register builder hooks callback
|
|
92
95
|
*/
|
|
93
|
-
|
|
94
96
|
function applyCallbacks(api, options) {
|
|
95
97
|
options.onAfterBuild && api.onAfterBuild(options.onAfterBuild);
|
|
96
98
|
options.onAfterCreateCompiler && api.onAfterCreateCompiler(options.onAfterCreateCompiler);
|
|
@@ -101,41 +103,36 @@ function applyCallbacks(api, options) {
|
|
|
101
103
|
options.onDevCompileDone && api.onDevCompileDone(options.onDevCompileDone);
|
|
102
104
|
options.onExit && api.onExit(options.onExit);
|
|
103
105
|
}
|
|
106
|
+
|
|
104
107
|
/**
|
|
105
108
|
* compat some config, if target is `node`
|
|
106
109
|
*/
|
|
107
|
-
|
|
108
|
-
|
|
109
110
|
function applyNodeCompat(chain, modernConfig, isProd) {
|
|
110
111
|
// apply node resolve extensions
|
|
111
112
|
for (var _i = 0, _arr = ['.node.js', '.node.jsx', '.node.ts', '.node.tsx']; _i < _arr.length; _i++) {
|
|
112
113
|
var ext = _arr[_i];
|
|
113
114
|
chain.resolve.extensions.prepend(ext);
|
|
114
|
-
}
|
|
115
|
-
|
|
115
|
+
}
|
|
116
116
|
|
|
117
|
+
// apply filterEntriesBySSRConfig
|
|
117
118
|
filterEntriesBySSRConfig(isProd, chain, modernConfig.server, modernConfig.output);
|
|
118
|
-
|
|
119
119
|
function filterEntriesBySSRConfig(isProd, chain, serverConfig, outputConfig) {
|
|
120
120
|
var _outputConfig$ssg;
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
121
|
+
var entries = chain.entryPoints.entries();
|
|
122
|
+
// if prod and ssg config is true or function
|
|
124
123
|
if (isProd && ((outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg) === true || typeof (outputConfig === null || outputConfig === void 0 ? void 0 : (_outputConfig$ssg = outputConfig.ssg) === null || _outputConfig$ssg === void 0 ? void 0 : _outputConfig$ssg[0]) === 'function')) {
|
|
125
124
|
return;
|
|
126
|
-
}
|
|
127
|
-
// `ssg: {}` is not allowed if multi entry
|
|
128
|
-
|
|
125
|
+
}
|
|
129
126
|
|
|
127
|
+
// if single entry has ssg config
|
|
128
|
+
// `ssg: {}` is not allowed if multi entry
|
|
130
129
|
var entryNames = Object.keys(entries);
|
|
131
|
-
|
|
132
130
|
if (isProd && entryNames.length === 1 && outputConfig !== null && outputConfig !== void 0 && outputConfig.ssg) {
|
|
133
131
|
return;
|
|
134
|
-
}
|
|
135
|
-
|
|
132
|
+
}
|
|
136
133
|
|
|
134
|
+
// collect all ssg entries
|
|
137
135
|
var ssgEntries = [];
|
|
138
|
-
|
|
139
136
|
if (isProd && outputConfig !== null && outputConfig !== void 0 && outputConfig.ssg) {
|
|
140
137
|
var ssg = outputConfig.ssg;
|
|
141
138
|
entryNames.forEach(function (name) {
|
|
@@ -144,11 +141,9 @@ function applyNodeCompat(chain, modernConfig, isProd) {
|
|
|
144
141
|
}
|
|
145
142
|
});
|
|
146
143
|
}
|
|
147
|
-
|
|
148
144
|
var _ref2 = serverConfig || {},
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
145
|
+
ssr = _ref2.ssr,
|
|
146
|
+
ssrByEntries = _ref2.ssrByEntries;
|
|
152
147
|
entryNames.forEach(function (name) {
|
|
153
148
|
if (!ssgEntries.includes(name) && (ssr && (ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]) === false || !ssr && !(ssrByEntries !== null && ssrByEntries !== void 0 && ssrByEntries[name]))) {
|
|
154
149
|
chain.entryPoints["delete"](name);
|
|
@@ -156,28 +151,24 @@ function applyNodeCompat(chain, modernConfig, isProd) {
|
|
|
156
151
|
});
|
|
157
152
|
}
|
|
158
153
|
}
|
|
154
|
+
|
|
159
155
|
/**
|
|
160
156
|
* inject bottom template
|
|
161
157
|
*/
|
|
162
|
-
|
|
163
|
-
|
|
164
158
|
function applyBottomHtmlWebpackPlugin(_ref3) {
|
|
165
159
|
var api = _ref3.api,
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
160
|
+
chain = _ref3.chain,
|
|
161
|
+
modernConfig = _ref3.modernConfig,
|
|
162
|
+
appContext = _ref3.appContext,
|
|
163
|
+
CHAIN_ID = _ref3.CHAIN_ID;
|
|
171
164
|
var _loop = function _loop() {
|
|
172
165
|
var entryName = _Object$keys[_i2];
|
|
173
|
-
|
|
174
166
|
// FIXME: the only need necessary
|
|
175
167
|
var baseTemplateParams = _objectSpread({
|
|
176
168
|
entryName: entryName,
|
|
177
|
-
title: getEntryOptions(entryName, modernConfig.
|
|
178
|
-
mountId: modernConfig.
|
|
179
|
-
}, getEntryOptions(entryName, modernConfig.
|
|
180
|
-
|
|
169
|
+
title: getEntryOptions(entryName, modernConfig.html.title, modernConfig.html.titleByEntries, appContext.packageName),
|
|
170
|
+
mountId: modernConfig.html.mountId
|
|
171
|
+
}, getEntryOptions(entryName, modernConfig.html.templateParameters, modernConfig.html.templateParametersByEntries, appContext.packageName));
|
|
181
172
|
chain.plugin("".concat(CHAIN_ID.PLUGIN.HTML, "-").concat(entryName)).tap(function (args) {
|
|
182
173
|
return [_objectSpread(_objectSpread({}, args[0] || {}), {}, {
|
|
183
174
|
__internal__: true,
|
|
@@ -185,46 +176,37 @@ function applyBottomHtmlWebpackPlugin(_ref3) {
|
|
|
185
176
|
})];
|
|
186
177
|
});
|
|
187
178
|
};
|
|
188
|
-
|
|
189
179
|
// inject bottomTemplate into html-webpack-plugin
|
|
190
180
|
for (var _i2 = 0, _Object$keys = Object.keys(api.context.entry); _i2 < _Object$keys.length; _i2++) {
|
|
191
181
|
_loop();
|
|
192
182
|
}
|
|
193
|
-
|
|
194
183
|
chain.plugin(CHAIN_ID.PLUGIN.BOTTOM_TEMPLATE).use(BottomTemplatePlugin, [HtmlWebpackPlugin]);
|
|
195
184
|
}
|
|
196
|
-
|
|
197
185
|
var isStreamingSSR = function isStreamingSSR(userConfig) {
|
|
198
186
|
var isStreaming = function isStreaming(ssr) {
|
|
199
187
|
return ssr && _typeof(ssr) === 'object' && ssr.mode === 'stream';
|
|
200
188
|
};
|
|
201
|
-
|
|
202
189
|
var server = userConfig.server;
|
|
203
|
-
|
|
204
190
|
if (isStreaming(server.ssr)) {
|
|
205
191
|
return true;
|
|
206
|
-
}
|
|
207
|
-
// we regard the whole app as streaming ssr only if one entry meets the requirement.
|
|
208
|
-
|
|
192
|
+
}
|
|
209
193
|
|
|
194
|
+
// Since we cannot apply different plugins for different entries,
|
|
195
|
+
// we regard the whole app as streaming ssr only if one entry meets the requirement.
|
|
210
196
|
if (server !== null && server !== void 0 && server.ssrByEntries && _typeof(server.ssrByEntries) === 'object') {
|
|
211
197
|
for (var _i3 = 0, _Object$keys2 = Object.keys(server.ssrByEntries); _i3 < _Object$keys2.length; _i3++) {
|
|
212
198
|
var name = _Object$keys2[_i3];
|
|
213
|
-
|
|
214
199
|
if (isStreaming(server.ssrByEntries[name])) {
|
|
215
200
|
return true;
|
|
216
201
|
}
|
|
217
202
|
}
|
|
218
203
|
}
|
|
219
|
-
|
|
220
204
|
return false;
|
|
221
205
|
};
|
|
222
|
-
|
|
223
206
|
function applyAsyncChunkHtmlPlugin(_ref4) {
|
|
224
207
|
var chain = _ref4.chain,
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
208
|
+
modernConfig = _ref4.modernConfig,
|
|
209
|
+
CHAIN_ID = _ref4.CHAIN_ID;
|
|
228
210
|
if (isStreamingSSR(modernConfig)) {
|
|
229
211
|
chain.plugin(CHAIN_ID.PLUGIN.HTML_ASYNC_CHUNK).use(HtmlAsyncChunkPlugin, [HtmlWebpackPlugin]);
|
|
230
212
|
}
|
|
@@ -1,96 +1,110 @@
|
|
|
1
|
-
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
2
1
|
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
2
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
3
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
4
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
3
5
|
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
4
6
|
import { createBuilder } from '@modern-js/builder';
|
|
5
7
|
import { builderWebpackProvider } from '@modern-js/builder-webpack-provider';
|
|
6
|
-
import { applyOptionsChain } from '@modern-js/utils';
|
|
8
|
+
import { applyOptionsChain, isUseSSRBundle } from '@modern-js/utils';
|
|
7
9
|
import { PluginCompatModern } from "./builderPlugins/compatModern";
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
import { createCopyPattern } from "./share";
|
|
11
|
+
function getBuilderTargets(normalizedConfig) {
|
|
12
|
+
var targets = ['web'];
|
|
13
|
+
if (normalizedConfig.output.enableModernMode && !targets.includes('modern-web')) {
|
|
14
|
+
targets.push('modern-web');
|
|
15
|
+
}
|
|
16
|
+
if (isUseSSRBundle(normalizedConfig)) {
|
|
17
|
+
targets.push('node');
|
|
18
|
+
}
|
|
19
|
+
return targets;
|
|
20
|
+
}
|
|
21
|
+
export function createBuilderForEdenX(_x) {
|
|
22
|
+
return _createBuilderForEdenX.apply(this, arguments);
|
|
23
|
+
}
|
|
24
|
+
function _createBuilderForEdenX() {
|
|
25
|
+
_createBuilderForEdenX = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
26
|
+
var normalizedConfig, appContext, compatPluginConfig, builderConfig, webpackProvider, target, builderOptions, builder;
|
|
16
27
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
17
28
|
while (1) {
|
|
18
29
|
switch (_context.prev = _context.next) {
|
|
19
30
|
case 0:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (normalizedConfig.output.enableModernMode && !targets.includes('modern-web')) {
|
|
24
|
-
targets.push('modern-web');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
builderConfig = createBuilderProviderConfig(normalizedConfig, appContext); // create webpack provider
|
|
28
|
-
|
|
31
|
+
normalizedConfig = _ref.normalizedConfig, appContext = _ref.appContext, compatPluginConfig = _ref.compatPluginConfig;
|
|
32
|
+
// create webpack provider
|
|
33
|
+
builderConfig = createBuilderProviderConfig(normalizedConfig, appContext);
|
|
29
34
|
webpackProvider = builderWebpackProvider({
|
|
30
35
|
builderConfig: builderConfig
|
|
31
36
|
});
|
|
37
|
+
target = getBuilderTargets(normalizedConfig);
|
|
32
38
|
builderOptions = createBuilderOptions(target, appContext);
|
|
33
|
-
_context.next =
|
|
39
|
+
_context.next = 7;
|
|
34
40
|
return createBuilder(webpackProvider, builderOptions);
|
|
35
|
-
|
|
36
|
-
case 8:
|
|
41
|
+
case 7:
|
|
37
42
|
builder = _context.sent;
|
|
38
|
-
_context.next =
|
|
43
|
+
_context.next = 10;
|
|
39
44
|
return applyBuilderPlugins(builder, normalizedConfig, appContext, compatPluginConfig);
|
|
40
|
-
|
|
41
|
-
case 11:
|
|
45
|
+
case 10:
|
|
42
46
|
return _context.abrupt("return", builder);
|
|
43
|
-
|
|
44
|
-
case 12:
|
|
47
|
+
case 11:
|
|
45
48
|
case "end":
|
|
46
49
|
return _context.stop();
|
|
47
50
|
}
|
|
48
51
|
}
|
|
49
52
|
}, _callee);
|
|
50
53
|
}));
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
};
|
|
55
|
-
})();
|
|
56
|
-
|
|
57
|
-
function createBuilderProviderConfig(normalizedConfig, appContext) {
|
|
58
|
-
var source = createSourceConfig(normalizedConfig, appContext);
|
|
59
|
-
var html = createHtmlConfig(normalizedConfig, appContext);
|
|
54
|
+
return _createBuilderForEdenX.apply(this, arguments);
|
|
55
|
+
}
|
|
56
|
+
export function createBuilderProviderConfig(normalizedConfig, appContext) {
|
|
60
57
|
var output = createOutputConfig(normalizedConfig, appContext);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
58
|
+
return _objectSpread(_objectSpread({}, normalizedConfig), {}, {
|
|
59
|
+
source: _objectSpread(_objectSpread({}, normalizedConfig.source), {}, {
|
|
60
|
+
resolveExtensionPrefix: '.web'
|
|
61
|
+
}),
|
|
65
62
|
output: output,
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
dev: {
|
|
64
|
+
https: normalizedConfig.dev.https,
|
|
65
|
+
assetPrefix: normalizedConfig.dev.assetPrefix
|
|
66
|
+
},
|
|
67
|
+
html: _objectSpread(_objectSpread({}, normalizedConfig.html), {}, {
|
|
68
|
+
templateByEntries: normalizedConfig.html.templateByEntries || appContext.htmlTemplates
|
|
69
|
+
}),
|
|
70
|
+
performance: _objectSpread(_objectSpread({}, normalizedConfig.performance), {}, {
|
|
68
71
|
// `@modern-js/webpack` used to remove moment locale by default
|
|
69
72
|
removeMomentLocale: true
|
|
70
|
-
}
|
|
71
|
-
};
|
|
73
|
+
})
|
|
74
|
+
});
|
|
75
|
+
function createOutputConfig(config, appContext) {
|
|
76
|
+
var defaultCopyPattern = createCopyPattern(appContext, config, 'upload');
|
|
77
|
+
var copy = config.output.copy;
|
|
78
|
+
var copyOptions = Array.isArray(copy) ? copy : copy === null || copy === void 0 ? void 0 : copy.patterns;
|
|
79
|
+
var builderCopy = [].concat(_toConsumableArray(copyOptions || []), [defaultCopyPattern]);
|
|
80
|
+
return _objectSpread(_objectSpread({}, config.output), {}, {
|
|
81
|
+
copy: builderCopy,
|
|
82
|
+
// We need to do this in the app-tools prepare hook because some files will be generated into the dist directory in the analyze process
|
|
83
|
+
cleanDistPath: false,
|
|
84
|
+
// `@modern-js/webpack` used to generate asset manifest by default
|
|
85
|
+
enableAssetManifest: true,
|
|
86
|
+
// compatible the modern-js with fallback behavior
|
|
87
|
+
enableAssetFallback: true
|
|
88
|
+
});
|
|
89
|
+
}
|
|
72
90
|
}
|
|
73
|
-
|
|
74
91
|
export function createBuilderOptions(target, appContext) {
|
|
75
92
|
// create entries
|
|
93
|
+
|
|
76
94
|
var entries = {};
|
|
77
95
|
var _appContext$entrypoin = appContext.entrypoints,
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
96
|
+
entrypoints = _appContext$entrypoin === void 0 ? [] : _appContext$entrypoin,
|
|
97
|
+
checkedEntries = appContext.checkedEntries;
|
|
81
98
|
var _iterator = _createForOfIteratorHelper(entrypoints),
|
|
82
|
-
|
|
83
|
-
|
|
99
|
+
_step;
|
|
84
100
|
try {
|
|
85
101
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
86
102
|
var _step$value = _step.value,
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
103
|
+
entryName = _step$value.entryName,
|
|
104
|
+
entry = _step$value.entry;
|
|
90
105
|
if (checkedEntries && !checkedEntries.includes(entryName)) {
|
|
91
106
|
continue;
|
|
92
107
|
}
|
|
93
|
-
|
|
94
108
|
if (entryName in entries) {
|
|
95
109
|
entries[entryName].push(entry);
|
|
96
110
|
} else {
|
|
@@ -102,7 +116,6 @@ export function createBuilderOptions(target, appContext) {
|
|
|
102
116
|
} finally {
|
|
103
117
|
_iterator.f();
|
|
104
118
|
}
|
|
105
|
-
|
|
106
119
|
return {
|
|
107
120
|
cwd: appContext.appDirectory,
|
|
108
121
|
target: target,
|
|
@@ -111,18 +124,16 @@ export function createBuilderOptions(target, appContext) {
|
|
|
111
124
|
framework: appContext.metaName
|
|
112
125
|
};
|
|
113
126
|
}
|
|
127
|
+
|
|
114
128
|
/**
|
|
115
129
|
* register builder Plugin by condition
|
|
116
130
|
*/
|
|
117
|
-
|
|
118
131
|
function applyBuilderPlugins(_x2, _x3, _x4, _x5) {
|
|
119
132
|
return _applyBuilderPlugins.apply(this, arguments);
|
|
120
133
|
}
|
|
121
|
-
|
|
122
134
|
function _applyBuilderPlugins() {
|
|
123
135
|
_applyBuilderPlugins = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(builder, normalizedConfig, appContext, compatPluginConfig) {
|
|
124
136
|
var _yield$import, PluginNodePolyfill, esbuildOptions, _yield$import2, PluginEsbuild;
|
|
125
|
-
|
|
126
137
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
127
138
|
while (1) {
|
|
128
139
|
switch (_context2.prev = _context2.next) {
|
|
@@ -131,25 +142,20 @@ function _applyBuilderPlugins() {
|
|
|
131
142
|
_context2.next = 6;
|
|
132
143
|
break;
|
|
133
144
|
}
|
|
134
|
-
|
|
135
145
|
_context2.next = 3;
|
|
136
146
|
return import('@modern-js/builder-plugin-node-polyfill');
|
|
137
|
-
|
|
138
147
|
case 3:
|
|
139
148
|
_yield$import = _context2.sent;
|
|
140
149
|
PluginNodePolyfill = _yield$import.PluginNodePolyfill;
|
|
141
150
|
builder.addPlugins([PluginNodePolyfill()]);
|
|
142
|
-
|
|
143
151
|
case 6:
|
|
144
152
|
if (!normalizedConfig.tools.esbuild) {
|
|
145
153
|
_context2.next = 13;
|
|
146
154
|
break;
|
|
147
155
|
}
|
|
148
|
-
|
|
149
156
|
esbuildOptions = normalizedConfig.tools.esbuild;
|
|
150
157
|
_context2.next = 10;
|
|
151
158
|
return import('@modern-js/builder-plugin-esbuild');
|
|
152
|
-
|
|
153
159
|
case 10:
|
|
154
160
|
_yield$import2 = _context2.sent;
|
|
155
161
|
PluginEsbuild = _yield$import2.PluginEsbuild;
|
|
@@ -157,10 +163,8 @@ function _applyBuilderPlugins() {
|
|
|
157
163
|
loader: false,
|
|
158
164
|
minimize: applyOptionsChain({}, esbuildOptions)
|
|
159
165
|
})]);
|
|
160
|
-
|
|
161
166
|
case 13:
|
|
162
167
|
builder.addPlugins([PluginCompatModern(appContext, normalizedConfig, compatPluginConfig)]);
|
|
163
|
-
|
|
164
168
|
case 14:
|
|
165
169
|
case "end":
|
|
166
170
|
return _context2.stop();
|
|
@@ -2,11 +2,10 @@ import path from 'path';
|
|
|
2
2
|
import { template as lodashTemplate } from '@modern-js/utils/lodash';
|
|
3
3
|
import { removeTailSlash } from '@modern-js/utils';
|
|
4
4
|
export function createCopyPattern(appContext, config, patternsType, chain) {
|
|
5
|
-
var configDir = path.resolve(appContext.appDirectory, config.source.configDir);
|
|
5
|
+
var configDir = path.resolve(appContext.appDirectory, config.source.configDir || './config');
|
|
6
6
|
var uploadDir = path.posix.join(configDir.replace(/\\/g, '/'), 'upload');
|
|
7
7
|
var publicDir = path.posix.join(configDir.replace(/\\/g, '/'), 'public');
|
|
8
8
|
var minifiedJsRexExp = /\.min\.js/;
|
|
9
|
-
|
|
10
9
|
var info = function info(file) {
|
|
11
10
|
return {
|
|
12
11
|
// If the file name ends with `.min.js`, we assume it's a compressed file.
|
|
@@ -15,12 +14,10 @@ export function createCopyPattern(appContext, config, patternsType, chain) {
|
|
|
15
14
|
minimized: minifiedJsRexExp.test(file.sourceFilename)
|
|
16
15
|
};
|
|
17
16
|
};
|
|
18
|
-
|
|
19
17
|
if (patternsType === 'public') {
|
|
20
18
|
if (!chain) {
|
|
21
19
|
throw new Error("expect get a webpackChain, but receive 'undefined'");
|
|
22
20
|
}
|
|
23
|
-
|
|
24
21
|
return {
|
|
25
22
|
info: info,
|
|
26
23
|
from: '**/*',
|
|
@@ -32,7 +29,6 @@ export function createCopyPattern(appContext, config, patternsType, chain) {
|
|
|
32
29
|
if (!/\.html?$/.test(absoluteFrom)) {
|
|
33
30
|
return content;
|
|
34
31
|
}
|
|
35
|
-
|
|
36
32
|
return lodashTemplate(content.toString('utf8'))({
|
|
37
33
|
assetPrefix: removeTailSlash(chain.output.get('publicPath'))
|
|
38
34
|
});
|
|
@@ -6,36 +6,26 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
|
6
6
|
export var HtmlAsyncChunkPlugin = /*#__PURE__*/function () {
|
|
7
7
|
function HtmlAsyncChunkPlugin(htmlWebpackPlugin) {
|
|
8
8
|
_classCallCheck(this, HtmlAsyncChunkPlugin);
|
|
9
|
-
|
|
10
9
|
_defineProperty(this, "name", void 0);
|
|
11
|
-
|
|
12
10
|
_defineProperty(this, "htmlWebpackPlugin", void 0);
|
|
13
|
-
|
|
14
11
|
this.name = 'HtmlAsyncChunkPlugin';
|
|
15
12
|
this.htmlWebpackPlugin = htmlWebpackPlugin;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
_createClass(HtmlAsyncChunkPlugin, [{
|
|
19
15
|
key: "apply",
|
|
20
16
|
value: function apply(compiler) {
|
|
21
17
|
var _this = this;
|
|
22
|
-
|
|
23
18
|
compiler.hooks.compilation.tap(this.name, function (compilation) {
|
|
24
19
|
var hooks = _this.htmlWebpackPlugin.getHooks(compilation);
|
|
25
|
-
|
|
26
20
|
hooks.alterAssetTagGroups.tap(_this.name, function (assets) {
|
|
27
21
|
var tags = [].concat(_toConsumableArray(assets.headTags), _toConsumableArray(assets.bodyTags));
|
|
28
|
-
|
|
29
22
|
var _iterator = _createForOfIteratorHelper(tags),
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
_step;
|
|
32
24
|
try {
|
|
33
25
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
34
26
|
var tag = _step.value;
|
|
35
|
-
|
|
36
27
|
if (tag.tagName === 'script') {
|
|
37
28
|
var attributes = tag.attributes;
|
|
38
|
-
|
|
39
29
|
if (attributes && attributes.defer === true) {
|
|
40
30
|
attributes.async = true;
|
|
41
31
|
delete attributes.defer;
|
|
@@ -47,12 +37,10 @@ export var HtmlAsyncChunkPlugin = /*#__PURE__*/function () {
|
|
|
47
37
|
} finally {
|
|
48
38
|
_iterator.f();
|
|
49
39
|
}
|
|
50
|
-
|
|
51
40
|
return assets;
|
|
52
41
|
});
|
|
53
42
|
});
|
|
54
43
|
}
|
|
55
44
|
}]);
|
|
56
|
-
|
|
57
45
|
return HtmlAsyncChunkPlugin;
|
|
58
46
|
}();
|
|
@@ -4,50 +4,38 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
|
4
4
|
export var BottomTemplatePlugin = /*#__PURE__*/function () {
|
|
5
5
|
function BottomTemplatePlugin(htmlWebpackPlugin) {
|
|
6
6
|
_classCallCheck(this, BottomTemplatePlugin);
|
|
7
|
-
|
|
8
7
|
_defineProperty(this, "htmlWebpackPlugin", void 0);
|
|
9
|
-
|
|
10
8
|
_defineProperty(this, "bottomTemplateReg", /<!--<\?-\s*bottomTemplate\s*\?>-->/);
|
|
11
|
-
|
|
12
9
|
_defineProperty(this, "bodyRegExp", /(<\/\s*body\s*>)/i);
|
|
13
|
-
|
|
14
10
|
_defineProperty(this, "name", void 0);
|
|
15
|
-
|
|
16
11
|
this.htmlWebpackPlugin = htmlWebpackPlugin;
|
|
17
12
|
this.name = 'bottom-template';
|
|
18
13
|
}
|
|
19
|
-
|
|
20
14
|
_createClass(BottomTemplatePlugin, [{
|
|
21
15
|
key: "apply",
|
|
22
16
|
value: function apply(compiler) {
|
|
23
17
|
var _this = this;
|
|
24
|
-
|
|
25
18
|
compiler.hooks.compilation.tap(this.name, function (compilation) {
|
|
26
19
|
_this.htmlWebpackPlugin.getHooks(compilation).beforeEmit.tap(_this.name, function (data) {
|
|
27
20
|
var _data$plugin$options;
|
|
28
|
-
|
|
29
21
|
if (!((_data$plugin$options = data.plugin.options) !== null && _data$plugin$options !== void 0 && _data$plugin$options.__internal__)) {
|
|
30
22
|
return data;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
23
|
+
}
|
|
24
|
+
// 含有 <!--<?- bottomTemplate ?>--> 占位符时才需要注入 bottom.html
|
|
34
25
|
if (_this.bottomTemplateReg.test(data.html)) {
|
|
35
26
|
// 清空占位符
|
|
36
27
|
data.html = data.html.replace(_this.bottomTemplateReg, '');
|
|
37
28
|
var bottomTemplate = data.plugin.options.bottomTemplate;
|
|
38
|
-
|
|
39
29
|
if (bottomTemplate) {
|
|
40
30
|
data.html = data.html.replace(_this.bodyRegExp, function (match) {
|
|
41
31
|
return "\n".concat(bottomTemplate, "\n").concat(match);
|
|
42
32
|
});
|
|
43
33
|
}
|
|
44
34
|
}
|
|
45
|
-
|
|
46
35
|
return data;
|
|
47
36
|
});
|
|
48
37
|
});
|
|
49
38
|
}
|
|
50
39
|
}]);
|
|
51
|
-
|
|
52
40
|
return BottomTemplatePlugin;
|
|
53
41
|
}();
|