@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
|
@@ -4,29 +4,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.walkDirectory = exports.replaceWithAlias = exports.isRouteComponentFile = exports.getDefaultImports = void 0;
|
|
7
|
-
|
|
8
7
|
var _fs = _interopRequireDefault(require("fs"));
|
|
9
|
-
|
|
10
8
|
var _path = _interopRequireDefault(require("path"));
|
|
11
|
-
|
|
12
9
|
var _utils = require("@modern-js/utils");
|
|
13
|
-
|
|
14
10
|
var _constants = require("./constants");
|
|
15
|
-
|
|
16
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
12
|
const walkDirectory = dir => _fs.default.readdirSync(dir).reduce((previous, filename) => {
|
|
19
13
|
const filePath = _path.default.join(dir, filename);
|
|
20
|
-
|
|
21
14
|
if (_fs.default.statSync(filePath).isDirectory()) {
|
|
22
15
|
return [...previous, ...walkDirectory(filePath)];
|
|
23
16
|
} else {
|
|
24
17
|
return [...previous, filePath];
|
|
25
18
|
}
|
|
26
19
|
}, []);
|
|
27
|
-
|
|
28
20
|
exports.walkDirectory = walkDirectory;
|
|
29
|
-
|
|
30
21
|
const getDefaultImports = ({
|
|
31
22
|
entrypoint,
|
|
32
23
|
srcDirectory,
|
|
@@ -63,7 +54,6 @@ const getDefaultImports = ({
|
|
|
63
54
|
}],
|
|
64
55
|
value: (0, _utils.normalizeToPosixPath)(customBootstrap.replace(srcDirectory, internalSrcAlias))
|
|
65
56
|
}].filter(Boolean);
|
|
66
|
-
|
|
67
57
|
if (fileSystemRoutes) {
|
|
68
58
|
const route = {
|
|
69
59
|
specifiers: [{
|
|
@@ -71,7 +61,6 @@ const getDefaultImports = ({
|
|
|
71
61
|
}],
|
|
72
62
|
value: (0, _utils.normalizeToPosixPath)(`${internalDirAlias}/${entryName}/${_constants.FILE_SYSTEM_ROUTES_FILE_NAME}`)
|
|
73
63
|
};
|
|
74
|
-
|
|
75
64
|
if (fileSystemRoutes.globalApp) {
|
|
76
65
|
imports.push({
|
|
77
66
|
specifiers: [{
|
|
@@ -82,7 +71,6 @@ const getDefaultImports = ({
|
|
|
82
71
|
} else {
|
|
83
72
|
route.initialize = 'const App = false;';
|
|
84
73
|
}
|
|
85
|
-
|
|
86
74
|
imports.push(route);
|
|
87
75
|
} else {
|
|
88
76
|
imports.push({
|
|
@@ -92,26 +80,18 @@ const getDefaultImports = ({
|
|
|
92
80
|
value: (0, _utils.normalizeToPosixPath)(entry.replace(srcDirectory, internalSrcAlias))
|
|
93
81
|
});
|
|
94
82
|
}
|
|
95
|
-
|
|
96
83
|
return imports;
|
|
97
84
|
};
|
|
98
|
-
|
|
99
85
|
exports.getDefaultImports = getDefaultImports;
|
|
100
|
-
|
|
101
86
|
const isRouteComponentFile = filePath => {
|
|
102
87
|
if (/\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/.test(filePath)) {
|
|
103
88
|
return false;
|
|
104
89
|
}
|
|
105
|
-
|
|
106
90
|
if (['.js', '.jsx', '.ts', '.tsx'].includes(_path.default.extname(filePath))) {
|
|
107
91
|
return true;
|
|
108
92
|
}
|
|
109
|
-
|
|
110
93
|
return false;
|
|
111
94
|
};
|
|
112
|
-
|
|
113
95
|
exports.isRouteComponentFile = isRouteComponentFile;
|
|
114
|
-
|
|
115
96
|
const replaceWithAlias = (base, filePath, alias) => (0, _utils.normalizeToPosixPath)(_path.default.join(alias, _path.default.relative(base, filePath)));
|
|
116
|
-
|
|
117
97
|
exports.replaceWithAlias = replaceWithAlias;
|
|
@@ -4,37 +4,24 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.PluginCompatModern = void 0;
|
|
7
|
-
|
|
8
7
|
var _path = require("path");
|
|
9
|
-
|
|
10
8
|
var _builderShared = require("@modern-js/builder-shared");
|
|
11
|
-
|
|
12
9
|
var _lodash = require("@modern-js/utils/lodash");
|
|
13
|
-
|
|
14
10
|
var _htmlWebpackPlugin = _interopRequireDefault(require("@modern-js/builder-webpack-provider/html-webpack-plugin"));
|
|
15
|
-
|
|
16
11
|
var _utils = require("@modern-js/utils");
|
|
17
|
-
|
|
18
12
|
var _htmlBottomTemplate = require("../webpackPlugins/htmlBottomTemplate");
|
|
19
|
-
|
|
20
13
|
var _htmlAsyncChunkPlugin = require("../webpackPlugins/htmlAsyncChunkPlugin");
|
|
21
|
-
|
|
22
14
|
var _share = require("../share");
|
|
23
|
-
|
|
15
|
+
var _routerPlugin = _interopRequireDefault(require("../webpackPlugins/routerPlugin"));
|
|
24
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
|
-
|
|
26
17
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
27
|
-
|
|
28
18
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
29
|
-
|
|
30
19
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
31
|
-
|
|
32
20
|
/**
|
|
33
21
|
* Provides default configuration consistent with `@modern-js/webpack`
|
|
34
22
|
*/
|
|
35
23
|
const PluginCompatModern = (appContext, modernConfig, options) => ({
|
|
36
24
|
name: 'builder-plugin-compat-modern',
|
|
37
|
-
|
|
38
25
|
setup(api) {
|
|
39
26
|
api.modifyBuilderConfig(config => {
|
|
40
27
|
if (isStreamingSSR(modernConfig)) {
|
|
@@ -44,7 +31,6 @@ const PluginCompatModern = (appContext, modernConfig, options) => ({
|
|
|
44
31
|
}
|
|
45
32
|
});
|
|
46
33
|
}
|
|
47
|
-
|
|
48
34
|
return config;
|
|
49
35
|
});
|
|
50
36
|
api.modifyWebpackChain((chain, {
|
|
@@ -52,8 +38,8 @@ const PluginCompatModern = (appContext, modernConfig, options) => ({
|
|
|
52
38
|
CHAIN_ID,
|
|
53
39
|
isProd
|
|
54
40
|
}) => {
|
|
55
|
-
const builderNormalizedConfig = api.getNormalizedConfig();
|
|
56
|
-
|
|
41
|
+
const builderNormalizedConfig = api.getNormalizedConfig();
|
|
42
|
+
// set webpack config name
|
|
57
43
|
if (target === 'node') {
|
|
58
44
|
chain.name('server');
|
|
59
45
|
} else if (target === 'modern-web') {
|
|
@@ -61,13 +47,12 @@ const PluginCompatModern = (appContext, modernConfig, options) => ({
|
|
|
61
47
|
} else {
|
|
62
48
|
chain.name('client');
|
|
63
49
|
}
|
|
50
|
+
chain.resolve.modules.add('node_modules').add((0, _path.join)(api.context.rootPath, 'node_modules'));
|
|
64
51
|
|
|
65
|
-
|
|
66
|
-
|
|
52
|
+
// apply node compat
|
|
67
53
|
if (target === 'node') {
|
|
68
54
|
applyNodeCompat(chain, modernConfig, isProd);
|
|
69
55
|
}
|
|
70
|
-
|
|
71
56
|
if (isHtmlEnabled(builderNormalizedConfig, target)) {
|
|
72
57
|
applyBottomHtmlWebpackPlugin({
|
|
73
58
|
api,
|
|
@@ -81,39 +66,40 @@ const PluginCompatModern = (appContext, modernConfig, options) => ({
|
|
|
81
66
|
CHAIN_ID,
|
|
82
67
|
modernConfig
|
|
83
68
|
});
|
|
84
|
-
}
|
|
85
|
-
// const copyPatterns = createCopyPatterns(chain, appContext, modernConfig);
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const defaultCopyPattern = (0, _share.createCopyPattern)(appContext, modernConfig, 'public', chain);
|
|
89
|
-
chain.plugin(CHAIN_ID.PLUGIN.COPY).tap(args => {
|
|
90
|
-
var _args$;
|
|
91
|
-
|
|
92
|
-
return [{
|
|
93
|
-
patterns: [...(((_args$ = args[0]) === null || _args$ === void 0 ? void 0 : _args$.patterns) || []), defaultCopyPattern]
|
|
94
|
-
}];
|
|
95
|
-
});
|
|
69
|
+
}
|
|
96
70
|
|
|
71
|
+
// apply copy plugin
|
|
72
|
+
if (chain.plugins.has(CHAIN_ID.PLUGIN.COPY)) {
|
|
73
|
+
const defaultCopyPattern = (0, _share.createCopyPattern)(appContext, modernConfig, 'public', chain);
|
|
74
|
+
chain.plugin(CHAIN_ID.PLUGIN.COPY).tap(args => {
|
|
75
|
+
var _args$;
|
|
76
|
+
return [{
|
|
77
|
+
patterns: [...(((_args$ = args[0]) === null || _args$ === void 0 ? void 0 : _args$.patterns) || []), defaultCopyPattern]
|
|
78
|
+
}];
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
const {
|
|
82
|
+
entrypoints
|
|
83
|
+
} = appContext;
|
|
84
|
+
const existNestedRoutes = entrypoints.some(entrypoint => entrypoint.nestedRoutesEntry);
|
|
85
|
+
chain.plugin('route-plugin').use(_routerPlugin.default, [{
|
|
86
|
+
existNestedRoutes
|
|
87
|
+
}]);
|
|
97
88
|
function isHtmlEnabled(config, target) {
|
|
98
89
|
var _config$tools;
|
|
99
|
-
|
|
100
90
|
return ((_config$tools = config.tools) === null || _config$tools === void 0 ? void 0 : _config$tools.htmlPlugin) !== false && target !== 'node' && target !== 'web-worker';
|
|
101
91
|
}
|
|
102
92
|
});
|
|
103
|
-
|
|
104
93
|
if (options) {
|
|
105
94
|
applyCallbacks(api, options);
|
|
106
95
|
}
|
|
107
96
|
}
|
|
108
|
-
|
|
109
97
|
});
|
|
98
|
+
|
|
110
99
|
/**
|
|
111
100
|
* register builder hooks callback
|
|
112
101
|
*/
|
|
113
|
-
|
|
114
|
-
|
|
115
102
|
exports.PluginCompatModern = PluginCompatModern;
|
|
116
|
-
|
|
117
103
|
function applyCallbacks(api, options) {
|
|
118
104
|
options.onAfterBuild && api.onAfterBuild(options.onAfterBuild);
|
|
119
105
|
options.onAfterCreateCompiler && api.onAfterCreateCompiler(options.onAfterCreateCompiler);
|
|
@@ -124,40 +110,35 @@ function applyCallbacks(api, options) {
|
|
|
124
110
|
options.onDevCompileDone && api.onDevCompileDone(options.onDevCompileDone);
|
|
125
111
|
options.onExit && api.onExit(options.onExit);
|
|
126
112
|
}
|
|
113
|
+
|
|
127
114
|
/**
|
|
128
115
|
* compat some config, if target is `node`
|
|
129
116
|
*/
|
|
130
|
-
|
|
131
|
-
|
|
132
117
|
function applyNodeCompat(chain, modernConfig, isProd) {
|
|
133
118
|
// apply node resolve extensions
|
|
134
119
|
for (const ext of ['.node.js', '.node.jsx', '.node.ts', '.node.tsx']) {
|
|
135
120
|
chain.resolve.extensions.prepend(ext);
|
|
136
|
-
}
|
|
137
|
-
|
|
121
|
+
}
|
|
138
122
|
|
|
123
|
+
// apply filterEntriesBySSRConfig
|
|
139
124
|
filterEntriesBySSRConfig(isProd, chain, modernConfig.server, modernConfig.output);
|
|
140
|
-
|
|
141
125
|
function filterEntriesBySSRConfig(isProd, chain, serverConfig, outputConfig) {
|
|
142
126
|
var _outputConfig$ssg;
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
127
|
+
const entries = chain.entryPoints.entries();
|
|
128
|
+
// if prod and ssg config is true or function
|
|
146
129
|
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')) {
|
|
147
130
|
return;
|
|
148
|
-
}
|
|
149
|
-
// `ssg: {}` is not allowed if multi entry
|
|
150
|
-
|
|
131
|
+
}
|
|
151
132
|
|
|
133
|
+
// if single entry has ssg config
|
|
134
|
+
// `ssg: {}` is not allowed if multi entry
|
|
152
135
|
const entryNames = Object.keys(entries);
|
|
153
|
-
|
|
154
136
|
if (isProd && entryNames.length === 1 && outputConfig !== null && outputConfig !== void 0 && outputConfig.ssg) {
|
|
155
137
|
return;
|
|
156
|
-
}
|
|
157
|
-
|
|
138
|
+
}
|
|
158
139
|
|
|
140
|
+
// collect all ssg entries
|
|
159
141
|
const ssgEntries = [];
|
|
160
|
-
|
|
161
142
|
if (isProd && outputConfig !== null && outputConfig !== void 0 && outputConfig.ssg) {
|
|
162
143
|
const {
|
|
163
144
|
ssg
|
|
@@ -168,7 +149,6 @@ function applyNodeCompat(chain, modernConfig, isProd) {
|
|
|
168
149
|
}
|
|
169
150
|
});
|
|
170
151
|
}
|
|
171
|
-
|
|
172
152
|
const {
|
|
173
153
|
ssr,
|
|
174
154
|
ssrByEntries
|
|
@@ -180,11 +160,10 @@ function applyNodeCompat(chain, modernConfig, isProd) {
|
|
|
180
160
|
});
|
|
181
161
|
}
|
|
182
162
|
}
|
|
163
|
+
|
|
183
164
|
/**
|
|
184
165
|
* inject bottom template
|
|
185
166
|
*/
|
|
186
|
-
|
|
187
|
-
|
|
188
167
|
function applyBottomHtmlWebpackPlugin({
|
|
189
168
|
api,
|
|
190
169
|
chain,
|
|
@@ -197,32 +176,27 @@ function applyBottomHtmlWebpackPlugin({
|
|
|
197
176
|
// FIXME: the only need necessary
|
|
198
177
|
const baseTemplateParams = _objectSpread({
|
|
199
178
|
entryName,
|
|
200
|
-
title: (0, _utils.getEntryOptions)(entryName, modernConfig.
|
|
201
|
-
mountId: modernConfig.
|
|
202
|
-
}, (0, _utils.getEntryOptions)(entryName, modernConfig.
|
|
203
|
-
|
|
179
|
+
title: (0, _utils.getEntryOptions)(entryName, modernConfig.html.title, modernConfig.html.titleByEntries, appContext.packageName),
|
|
180
|
+
mountId: modernConfig.html.mountId
|
|
181
|
+
}, (0, _utils.getEntryOptions)(entryName, modernConfig.html.templateParameters, modernConfig.html.templateParametersByEntries, appContext.packageName));
|
|
204
182
|
chain.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`).tap(args => [_objectSpread(_objectSpread({}, args[0] || {}), {}, {
|
|
205
183
|
__internal__: true,
|
|
206
184
|
bottomTemplate: appContext.htmlTemplates[`__${entryName}-bottom__`] && (0, _lodash.template)(appContext.htmlTemplates[`__${entryName}-bottom__`])(baseTemplateParams)
|
|
207
185
|
})]);
|
|
208
186
|
}
|
|
209
|
-
|
|
210
187
|
chain.plugin(CHAIN_ID.PLUGIN.BOTTOM_TEMPLATE).use(_htmlBottomTemplate.BottomTemplatePlugin, [_htmlWebpackPlugin.default]);
|
|
211
188
|
}
|
|
212
|
-
|
|
213
189
|
const isStreamingSSR = userConfig => {
|
|
214
190
|
const isStreaming = ssr => ssr && typeof ssr === 'object' && ssr.mode === 'stream';
|
|
215
|
-
|
|
216
191
|
const {
|
|
217
192
|
server
|
|
218
193
|
} = userConfig;
|
|
219
|
-
|
|
220
194
|
if (isStreaming(server.ssr)) {
|
|
221
195
|
return true;
|
|
222
|
-
}
|
|
223
|
-
// we regard the whole app as streaming ssr only if one entry meets the requirement.
|
|
224
|
-
|
|
196
|
+
}
|
|
225
197
|
|
|
198
|
+
// Since we cannot apply different plugins for different entries,
|
|
199
|
+
// we regard the whole app as streaming ssr only if one entry meets the requirement.
|
|
226
200
|
if (server !== null && server !== void 0 && server.ssrByEntries && typeof server.ssrByEntries === 'object') {
|
|
227
201
|
for (const name of Object.keys(server.ssrByEntries)) {
|
|
228
202
|
if (isStreaming(server.ssrByEntries[name])) {
|
|
@@ -230,10 +204,8 @@ const isStreamingSSR = userConfig => {
|
|
|
230
204
|
}
|
|
231
205
|
}
|
|
232
206
|
}
|
|
233
|
-
|
|
234
207
|
return false;
|
|
235
208
|
};
|
|
236
|
-
|
|
237
209
|
function applyAsyncChunkHtmlPlugin({
|
|
238
210
|
chain,
|
|
239
211
|
modernConfig,
|
|
@@ -3,79 +3,90 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.createBuilderForEdenX = createBuilderForEdenX;
|
|
6
7
|
exports.createBuilderOptions = createBuilderOptions;
|
|
7
|
-
exports.
|
|
8
|
-
|
|
8
|
+
exports.createBuilderProviderConfig = createBuilderProviderConfig;
|
|
9
9
|
var _builder = require("@modern-js/builder");
|
|
10
|
-
|
|
11
10
|
var _builderWebpackProvider = require("@modern-js/builder-webpack-provider");
|
|
12
|
-
|
|
13
11
|
var _utils = require("@modern-js/utils");
|
|
14
|
-
|
|
15
12
|
var _compatModern = require("./builderPlugins/compatModern");
|
|
16
|
-
|
|
17
|
-
var _createHtmlConfig = require("./createHtmlConfig");
|
|
18
|
-
|
|
19
|
-
var _createOutputConfig = require("./createOutputConfig");
|
|
20
|
-
|
|
21
|
-
var _createSourceConfig = require("./createSourceConfig");
|
|
22
|
-
|
|
23
|
-
var _createToolsConfig = require("./createToolsConfig");
|
|
24
|
-
|
|
13
|
+
var _share = require("./share");
|
|
25
14
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
26
|
-
|
|
27
15
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
28
|
-
|
|
29
|
-
var
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
compatPluginConfig
|
|
34
|
-
}) => {
|
|
35
|
-
const targets = Array.isArray(_target) ? _target : [_target];
|
|
36
|
-
|
|
16
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
17
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
18
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
19
|
+
function getBuilderTargets(normalizedConfig) {
|
|
20
|
+
const targets = ['web'];
|
|
37
21
|
if (normalizedConfig.output.enableModernMode && !targets.includes('modern-web')) {
|
|
38
22
|
targets.push('modern-web');
|
|
39
23
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
24
|
+
if ((0, _utils.isUseSSRBundle)(normalizedConfig)) {
|
|
25
|
+
targets.push('node');
|
|
26
|
+
}
|
|
27
|
+
return targets;
|
|
28
|
+
}
|
|
29
|
+
async function createBuilderForEdenX({
|
|
30
|
+
normalizedConfig,
|
|
31
|
+
appContext,
|
|
32
|
+
compatPluginConfig
|
|
33
|
+
}) {
|
|
34
|
+
// create webpack provider
|
|
35
|
+
const builderConfig = createBuilderProviderConfig(normalizedConfig, appContext);
|
|
43
36
|
const webpackProvider = (0, _builderWebpackProvider.builderWebpackProvider)({
|
|
44
37
|
builderConfig
|
|
45
38
|
});
|
|
46
|
-
const
|
|
39
|
+
const target = getBuilderTargets(normalizedConfig);
|
|
40
|
+
const builderOptions = createBuilderOptions(target, appContext);
|
|
47
41
|
const builder = await (0, _builder.createBuilder)(webpackProvider, builderOptions);
|
|
48
42
|
await applyBuilderPlugins(builder, normalizedConfig, appContext, compatPluginConfig);
|
|
49
43
|
return builder;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
exports.default = _default;
|
|
53
|
-
|
|
44
|
+
}
|
|
54
45
|
function createBuilderProviderConfig(normalizedConfig, appContext) {
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
source,
|
|
61
|
-
html,
|
|
46
|
+
const output = createOutputConfig(normalizedConfig, appContext);
|
|
47
|
+
return _objectSpread(_objectSpread({}, normalizedConfig), {}, {
|
|
48
|
+
source: _objectSpread(_objectSpread({}, normalizedConfig.source), {}, {
|
|
49
|
+
resolveExtensionPrefix: '.web'
|
|
50
|
+
}),
|
|
62
51
|
output,
|
|
63
|
-
|
|
64
|
-
|
|
52
|
+
dev: {
|
|
53
|
+
https: normalizedConfig.dev.https,
|
|
54
|
+
assetPrefix: normalizedConfig.dev.assetPrefix
|
|
55
|
+
},
|
|
56
|
+
html: _objectSpread(_objectSpread({}, normalizedConfig.html), {}, {
|
|
57
|
+
templateByEntries: normalizedConfig.html.templateByEntries || appContext.htmlTemplates
|
|
58
|
+
}),
|
|
59
|
+
performance: _objectSpread(_objectSpread({}, normalizedConfig.performance), {}, {
|
|
65
60
|
// `@modern-js/webpack` used to remove moment locale by default
|
|
66
61
|
removeMomentLocale: true
|
|
67
|
-
}
|
|
68
|
-
};
|
|
62
|
+
})
|
|
63
|
+
});
|
|
64
|
+
function createOutputConfig(config, appContext) {
|
|
65
|
+
const defaultCopyPattern = (0, _share.createCopyPattern)(appContext, config, 'upload');
|
|
66
|
+
const {
|
|
67
|
+
copy
|
|
68
|
+
} = config.output;
|
|
69
|
+
const copyOptions = Array.isArray(copy) ? copy : copy === null || copy === void 0 ? void 0 : copy.patterns;
|
|
70
|
+
const builderCopy = [...(copyOptions || []), defaultCopyPattern];
|
|
71
|
+
return _objectSpread(_objectSpread({}, config.output), {}, {
|
|
72
|
+
copy: builderCopy,
|
|
73
|
+
// 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
|
|
74
|
+
cleanDistPath: false,
|
|
75
|
+
// `@modern-js/webpack` used to generate asset manifest by default
|
|
76
|
+
enableAssetManifest: true,
|
|
77
|
+
// compatible the modern-js with fallback behavior
|
|
78
|
+
enableAssetFallback: true
|
|
79
|
+
});
|
|
80
|
+
}
|
|
69
81
|
}
|
|
70
|
-
|
|
71
82
|
function createBuilderOptions(target, appContext) {
|
|
72
83
|
// create entries
|
|
84
|
+
|
|
73
85
|
const entries = {};
|
|
74
86
|
const {
|
|
75
87
|
entrypoints = [],
|
|
76
88
|
checkedEntries
|
|
77
89
|
} = appContext;
|
|
78
|
-
|
|
79
90
|
for (const {
|
|
80
91
|
entryName,
|
|
81
92
|
entry
|
|
@@ -83,14 +94,12 @@ function createBuilderOptions(target, appContext) {
|
|
|
83
94
|
if (checkedEntries && !checkedEntries.includes(entryName)) {
|
|
84
95
|
continue;
|
|
85
96
|
}
|
|
86
|
-
|
|
87
97
|
if (entryName in entries) {
|
|
88
98
|
entries[entryName].push(entry);
|
|
89
99
|
} else {
|
|
90
100
|
entries[entryName] = [entry];
|
|
91
101
|
}
|
|
92
102
|
}
|
|
93
|
-
|
|
94
103
|
return {
|
|
95
104
|
cwd: appContext.appDirectory,
|
|
96
105
|
target,
|
|
@@ -99,11 +108,10 @@ function createBuilderOptions(target, appContext) {
|
|
|
99
108
|
framework: appContext.metaName
|
|
100
109
|
};
|
|
101
110
|
}
|
|
111
|
+
|
|
102
112
|
/**
|
|
103
113
|
* register builder Plugin by condition
|
|
104
114
|
*/
|
|
105
|
-
|
|
106
|
-
|
|
107
115
|
async function applyBuilderPlugins(builder, normalizedConfig, appContext, compatPluginConfig) {
|
|
108
116
|
if (!normalizedConfig.output.disableNodePolyfill) {
|
|
109
117
|
const {
|
|
@@ -111,7 +119,6 @@ async function applyBuilderPlugins(builder, normalizedConfig, appContext, compat
|
|
|
111
119
|
} = await Promise.resolve().then(() => _interopRequireWildcard(require('@modern-js/builder-plugin-node-polyfill')));
|
|
112
120
|
builder.addPlugins([PluginNodePolyfill()]);
|
|
113
121
|
}
|
|
114
|
-
|
|
115
122
|
if (normalizedConfig.tools.esbuild) {
|
|
116
123
|
const {
|
|
117
124
|
esbuild: esbuildOptions
|
|
@@ -124,6 +131,5 @@ async function applyBuilderPlugins(builder, normalizedConfig, appContext, compat
|
|
|
124
131
|
minimize: (0, _utils.applyOptionsChain)({}, esbuildOptions)
|
|
125
132
|
})]);
|
|
126
133
|
}
|
|
127
|
-
|
|
128
134
|
builder.addPlugins([(0, _compatModern.PluginCompatModern)(appContext, normalizedConfig, compatPluginConfig)]);
|
|
129
135
|
}
|
|
@@ -4,36 +4,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.createCopyPattern = createCopyPattern;
|
|
7
|
-
|
|
8
7
|
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
8
|
var _lodash = require("@modern-js/utils/lodash");
|
|
11
|
-
|
|
12
9
|
var _utils = require("@modern-js/utils");
|
|
13
|
-
|
|
14
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
11
|
function createCopyPattern(appContext, config, patternsType, chain) {
|
|
17
|
-
const configDir = _path.default.resolve(appContext.appDirectory, config.source.configDir);
|
|
18
|
-
|
|
12
|
+
const configDir = _path.default.resolve(appContext.appDirectory, config.source.configDir || './config');
|
|
19
13
|
const uploadDir = _path.default.posix.join(configDir.replace(/\\/g, '/'), 'upload');
|
|
20
|
-
|
|
21
14
|
const publicDir = _path.default.posix.join(configDir.replace(/\\/g, '/'), 'public');
|
|
22
|
-
|
|
23
15
|
const minifiedJsRexExp = /\.min\.js/;
|
|
24
|
-
|
|
25
16
|
const info = file => ({
|
|
26
17
|
// If the file name ends with `.min.js`, we assume it's a compressed file.
|
|
27
18
|
// So we don't want copy-webpack-plugin to minify it.
|
|
28
19
|
// ref: https://github.com/webpack-contrib/copy-webpack-plugin#info
|
|
29
20
|
minimized: minifiedJsRexExp.test(file.sourceFilename)
|
|
30
21
|
});
|
|
31
|
-
|
|
32
22
|
if (patternsType === 'public') {
|
|
33
23
|
if (!chain) {
|
|
34
24
|
throw new Error("expect get a webpackChain, but receive 'undefined'");
|
|
35
25
|
}
|
|
36
|
-
|
|
37
26
|
return {
|
|
38
27
|
info,
|
|
39
28
|
from: '**/*',
|
|
@@ -45,7 +34,6 @@ function createCopyPattern(appContext, config, patternsType, chain) {
|
|
|
45
34
|
if (!/\.html?$/.test(absoluteFrom)) {
|
|
46
35
|
return content;
|
|
47
36
|
}
|
|
48
|
-
|
|
49
37
|
return (0, _lodash.template)(content.toString('utf8'))({
|
|
50
38
|
assetPrefix: (0, _utils.removeTailSlash)(chain.output.get('publicPath'))
|
|
51
39
|
});
|
|
@@ -4,43 +4,33 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.HtmlAsyncChunkPlugin = void 0;
|
|
7
|
-
|
|
8
7
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9
|
-
|
|
10
8
|
class HtmlAsyncChunkPlugin {
|
|
11
9
|
constructor(htmlWebpackPlugin) {
|
|
12
10
|
_defineProperty(this, "name", void 0);
|
|
13
|
-
|
|
14
11
|
_defineProperty(this, "htmlWebpackPlugin", void 0);
|
|
15
|
-
|
|
16
12
|
this.name = 'HtmlAsyncChunkPlugin';
|
|
17
13
|
this.htmlWebpackPlugin = htmlWebpackPlugin;
|
|
18
14
|
}
|
|
19
|
-
|
|
20
15
|
apply(compiler) {
|
|
21
16
|
compiler.hooks.compilation.tap(this.name, compilation => {
|
|
22
17
|
const hooks = this.htmlWebpackPlugin.getHooks(compilation);
|
|
23
18
|
hooks.alterAssetTagGroups.tap(this.name, assets => {
|
|
24
19
|
const tags = [...assets.headTags, ...assets.bodyTags];
|
|
25
|
-
|
|
26
20
|
for (const tag of tags) {
|
|
27
21
|
if (tag.tagName === 'script') {
|
|
28
22
|
const {
|
|
29
23
|
attributes
|
|
30
24
|
} = tag;
|
|
31
|
-
|
|
32
25
|
if (attributes && attributes.defer === true) {
|
|
33
26
|
attributes.async = true;
|
|
34
27
|
delete attributes.defer;
|
|
35
28
|
}
|
|
36
29
|
}
|
|
37
30
|
}
|
|
38
|
-
|
|
39
31
|
return assets;
|
|
40
32
|
});
|
|
41
33
|
});
|
|
42
34
|
}
|
|
43
|
-
|
|
44
35
|
}
|
|
45
|
-
|
|
46
36
|
exports.HtmlAsyncChunkPlugin = HtmlAsyncChunkPlugin;
|
|
@@ -4,50 +4,37 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.BottomTemplatePlugin = void 0;
|
|
7
|
-
|
|
8
7
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9
|
-
|
|
10
8
|
class BottomTemplatePlugin {
|
|
11
9
|
constructor(htmlWebpackPlugin) {
|
|
12
10
|
_defineProperty(this, "htmlWebpackPlugin", void 0);
|
|
13
|
-
|
|
14
11
|
_defineProperty(this, "bottomTemplateReg", /<!--<\?-\s*bottomTemplate\s*\?>-->/);
|
|
15
|
-
|
|
16
12
|
_defineProperty(this, "bodyRegExp", /(<\/\s*body\s*>)/i);
|
|
17
|
-
|
|
18
13
|
_defineProperty(this, "name", void 0);
|
|
19
|
-
|
|
20
14
|
this.htmlWebpackPlugin = htmlWebpackPlugin;
|
|
21
15
|
this.name = 'bottom-template';
|
|
22
16
|
}
|
|
23
|
-
|
|
24
17
|
apply(compiler) {
|
|
25
18
|
compiler.hooks.compilation.tap(this.name, compilation => {
|
|
26
19
|
this.htmlWebpackPlugin.getHooks(compilation).beforeEmit.tap(this.name, 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
|
const {
|
|
38
29
|
bottomTemplate
|
|
39
30
|
} = data.plugin.options;
|
|
40
|
-
|
|
41
31
|
if (bottomTemplate) {
|
|
42
32
|
data.html = data.html.replace(this.bodyRegExp, match => `\n${bottomTemplate}\n${match}`);
|
|
43
33
|
}
|
|
44
34
|
}
|
|
45
|
-
|
|
46
35
|
return data;
|
|
47
36
|
});
|
|
48
37
|
});
|
|
49
38
|
}
|
|
50
|
-
|
|
51
39
|
}
|
|
52
|
-
|
|
53
40
|
exports.BottomTemplatePlugin = BottomTemplatePlugin;
|