xhs-mp-compiler-cli 1.0.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/bin/xhs-mp-cli-build.d.ts +2 -0
- package/dist/bin/xhs-mp-cli-build.js +42 -0
- package/dist/bin/xhs-mp-cli-dev.d.ts +2 -0
- package/dist/bin/xhs-mp-cli-dev.js +84 -0
- package/dist/bin/xhs-mp-cli.d.ts +2 -0
- package/dist/bin/xhs-mp-cli.js +16 -0
- package/dist/build/index.d.ts +3 -0
- package/dist/build/index.js +22 -0
- package/dist/dev-server/index.d.ts +3 -0
- package/dist/dev-server/index.js +62 -0
- package/dist/dev-server/lib/ensurePort.d.ts +2 -0
- package/dist/dev-server/lib/ensurePort.js +32 -0
- package/dist/dev-server/lib/openBrowser.d.ts +2 -0
- package/dist/dev-server/lib/openBrowser.js +23 -0
- package/dist/dev-server/lib/openChrome.applescript +78 -0
- package/dist/globalData/SjsModule.d.ts +32 -0
- package/dist/globalData/SjsModule.js +34 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +118 -0
- package/dist/types/index.d.ts +110 -0
- package/dist/types/index.js +13 -0
- package/dist/utils/asyncWebpack.d.ts +3 -0
- package/dist/utils/asyncWebpack.js +38 -0
- package/dist/utils/combineExtJson.d.ts +3 -0
- package/dist/utils/combineExtJson.js +74 -0
- package/dist/utils/common.d.ts +7 -0
- package/dist/utils/common.js +35 -0
- package/dist/utils/depenedHelper.d.ts +31 -0
- package/dist/utils/depenedHelper.js +89 -0
- package/dist/utils/getCssSuffixName.d.ts +1 -0
- package/dist/utils/getCssSuffixName.js +9 -0
- package/dist/utils/getMlSuffixName.d.ts +1 -0
- package/dist/utils/getMlSuffixName.js +6 -0
- package/dist/utils/getPrefixName.d.ts +1 -0
- package/dist/utils/getPrefixName.js +6 -0
- package/dist/utils/projectConfig.d.ts +1 -0
- package/dist/utils/projectConfig.js +20 -0
- package/dist/utils/transformAppJson.d.ts +16 -0
- package/dist/utils/transformAppJson.js +199 -0
- package/dist/utils/validateAppJson.d.ts +4 -0
- package/dist/utils/validateAppJson.js +111 -0
- package/dist/webpack-config/index.d.ts +4 -0
- package/dist/webpack-config/index.js +41 -0
- package/dist/webpack-config/lib/const.d.ts +13 -0
- package/dist/webpack-config/lib/const.js +15 -0
- package/dist/webpack-config/lib/css.d.ts +2 -0
- package/dist/webpack-config/lib/css.js +41 -0
- package/dist/webpack-config/lib/postcssRpx2Vw.d.ts +13 -0
- package/dist/webpack-config/lib/postcssRpx2Vw.js +40 -0
- package/dist/webpack-config/lib/tagTransformMap.d.ts +35 -0
- package/dist/webpack-config/lib/tagTransformMap.js +38 -0
- package/dist/webpack-config/lib/utils.d.ts +5 -0
- package/dist/webpack-config/lib/utils.js +37 -0
- package/dist/webpack-config/loaders/component-entry-loader.d.ts +1 -0
- package/dist/webpack-config/loaders/component-entry-loader.js +31 -0
- package/dist/webpack-config/loaders/component-entry-requirements-loader.d.ts +1 -0
- package/dist/webpack-config/loaders/component-entry-requirements-loader.js +24 -0
- package/dist/webpack-config/loaders/mini-style-loader.d.ts +1 -0
- package/dist/webpack-config/loaders/mini-style-loader.js +69 -0
- package/dist/webpack-config/loaders/ml-loader/index.d.ts +3 -0
- package/dist/webpack-config/loaders/ml-loader/index.js +66 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/generator.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/generator.js +107 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/index.d.ts +6 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/index.js +64 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/injectScript.d.ts +11 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/injectScript.js +41 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/injectTemplate.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/injectTemplate.js +18 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/parser.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/parser.js +21 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformer.d.ts +7 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformer.js +185 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleBindAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleBindAttribute.js +73 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleBlockTag.d.ts +13 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleBlockTag.js +42 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleCatchAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleCatchAttribute.js +30 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleClassAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleClassAttribute.js +17 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleDataAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleDataAttribute.js +23 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleHiddenAttribute.d.ts +13 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleHiddenAttribute.js +25 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleImportTag.d.ts +4 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleImportTag.js +30 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleIncludeTag.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleIncludeTag.js +30 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleLoopAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleLoopAttribute.js +89 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleMLAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleMLAttribute.js +33 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleModelAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleModelAttribute.js +61 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleOtherAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleOtherAttribute.js +35 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSjsEvent.d.ts +11 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSjsEvent.js +72 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSlotAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSlotAttribute.js +74 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSpaceAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSpaceAttribute.js +12 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleStyleAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleStyleAttribute.js +16 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/utils.d.ts +10 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/utils.js +80 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/utils.d.ts +7 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/utils.js +41 -0
- package/dist/webpack-config/loaders/render-entry-loader.d.ts +1 -0
- package/dist/webpack-config/loaders/render-entry-loader.js +50 -0
- package/dist/webpack-config/loaders/service-entry-loader.d.ts +1 -0
- package/dist/webpack-config/loaders/service-entry-loader.js +51 -0
- package/dist/webpack-config/loaders/sjs-loader/frame.d.ts +1 -0
- package/dist/webpack-config/loaders/sjs-loader/frame.js +51 -0
- package/dist/webpack-config/loaders/sjs-loader/index.d.ts +1 -0
- package/dist/webpack-config/loaders/sjs-loader/index.js +93 -0
- package/dist/webpack-config/loaders/utils.d.ts +13 -0
- package/dist/webpack-config/loaders/utils.js +41 -0
- package/dist/webpack-config/loaders/wxss-loader.d.ts +1 -0
- package/dist/webpack-config/loaders/wxss-loader.js +76 -0
- package/dist/webpack-config/plugins/VueLoaderPlugin.d.ts +19 -0
- package/dist/webpack-config/plugins/VueLoaderPlugin.js +205 -0
- package/dist/webpack-config/plugins/XhsMpErrorTransformPlugin.d.ts +8 -0
- package/dist/webpack-config/plugins/XhsMpErrorTransformPlugin.js +40 -0
- package/dist/webpack-config/plugins/XhsMpJsonPlugin.d.ts +36 -0
- package/dist/webpack-config/plugins/XhsMpJsonPlugin.js +71 -0
- package/dist/webpack-config/presets/babel.d.ts +8 -0
- package/dist/webpack-config/presets/babel.js +57 -0
- package/dist/webpack-config/presets/common.d.ts +4 -0
- package/dist/webpack-config/presets/common.js +40 -0
- package/dist/webpack-config/presets/mp/MpEntryPlugin.d.ts +23 -0
- package/dist/webpack-config/presets/mp/MpEntryPlugin.js +87 -0
- package/dist/webpack-config/presets/mp/index.d.ts +4 -0
- package/dist/webpack-config/presets/mp/index.js +48 -0
- package/dist/webpack-config/presets/prod.d.ts +4 -0
- package/dist/webpack-config/presets/prod.js +85 -0
- package/dist/webpack-config/presets/render/ComponentEntryPlugin.d.ts +18 -0
- package/dist/webpack-config/presets/render/ComponentEntryPlugin.js +77 -0
- package/dist/webpack-config/presets/render/RenderChunkPlugin.d.ts +9 -0
- package/dist/webpack-config/presets/render/RenderChunkPlugin.js +65 -0
- package/dist/webpack-config/presets/render/RenderEntryPlugin.d.ts +14 -0
- package/dist/webpack-config/presets/render/RenderEntryPlugin.js +42 -0
- package/dist/webpack-config/presets/render/SjsEntryPlugin.d.ts +31 -0
- package/dist/webpack-config/presets/render/SjsEntryPlugin.js +124 -0
- package/dist/webpack-config/presets/render/index.d.ts +4 -0
- package/dist/webpack-config/presets/render/index.js +99 -0
- package/dist/webpack-config/presets/service/ServiceEntryPlugin.d.ts +8 -0
- package/dist/webpack-config/presets/service/ServiceEntryPlugin.js +36 -0
- package/dist/webpack-config/presets/service/XhsMpServiceChunkPlugin.d.ts +6 -0
- package/dist/webpack-config/presets/service/XhsMpServiceChunkPlugin.js +46 -0
- package/dist/webpack-config/presets/service/XhsResolveLimitPlugin.d.ts +8 -0
- package/dist/webpack-config/presets/service/XhsResolveLimitPlugin.js +65 -0
- package/dist/webpack-config/presets/service/XhsV2AssetsPlugin.d.ts +5 -0
- package/dist/webpack-config/presets/service/XhsV2AssetsPlugin.js +27 -0
- package/dist/webpack-config/presets/service/index.d.ts +4 -0
- package/dist/webpack-config/presets/service/index.js +38 -0
- package/package.json +124 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const const_1 = __importDefault(require("../lib/const"));
|
|
7
|
+
// import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
|
|
8
|
+
const getProdConfig = (chain, options) => {
|
|
9
|
+
chain.mode('production');
|
|
10
|
+
if (!options.noJs) {
|
|
11
|
+
// 生产环境使用 babel-loader
|
|
12
|
+
chain.module
|
|
13
|
+
.rule('js')
|
|
14
|
+
.use('js-loader')
|
|
15
|
+
.loader(require.resolve('babel-loader'))
|
|
16
|
+
.options({
|
|
17
|
+
configFile: false,
|
|
18
|
+
babelrc: false,
|
|
19
|
+
sourceType: 'unambiguous',
|
|
20
|
+
presets: [
|
|
21
|
+
[
|
|
22
|
+
require.resolve('@babel/preset-env'),
|
|
23
|
+
{
|
|
24
|
+
useBuiltIns: false,
|
|
25
|
+
corejs: {
|
|
26
|
+
version: 3,
|
|
27
|
+
proposals: true,
|
|
28
|
+
},
|
|
29
|
+
shippedProposals: true,
|
|
30
|
+
targets: const_1.default.PROD_BROWSERSLIST,
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
],
|
|
34
|
+
plugins: [[require.resolve('@babel/plugin-transform-runtime'), { corejs: false }]],
|
|
35
|
+
});
|
|
36
|
+
chain.module
|
|
37
|
+
.rule('ts')
|
|
38
|
+
.use('ts-loader')
|
|
39
|
+
.loader(require.resolve('babel-loader'))
|
|
40
|
+
.options({
|
|
41
|
+
sourceType: 'unambiguous',
|
|
42
|
+
presets: [
|
|
43
|
+
[
|
|
44
|
+
require.resolve('@babel/preset-typescript'),
|
|
45
|
+
{
|
|
46
|
+
allExtensions: true,
|
|
47
|
+
isTSX: true,
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
[
|
|
51
|
+
require.resolve('@babel/preset-env'),
|
|
52
|
+
{
|
|
53
|
+
useBuiltIns: false,
|
|
54
|
+
corejs: {
|
|
55
|
+
version: 3,
|
|
56
|
+
proposals: true,
|
|
57
|
+
},
|
|
58
|
+
shippedProposals: true,
|
|
59
|
+
targets: const_1.default.PROD_BROWSERSLIST,
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
],
|
|
63
|
+
plugins: [[require.resolve('@babel/plugin-transform-runtime'), { corejs: false }]],
|
|
64
|
+
});
|
|
65
|
+
chain.optimization.minimizer('js').use(require.resolve('terser-webpack-plugin'), [
|
|
66
|
+
{
|
|
67
|
+
terserOptions: {
|
|
68
|
+
safari10: true,
|
|
69
|
+
compress: { drop_console: false },
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
]);
|
|
73
|
+
}
|
|
74
|
+
chain.optimization.minimize(!!options.compressJs);
|
|
75
|
+
// mini-style-loader 中已压缩
|
|
76
|
+
// chain.optimization.minimizer('css').use(require.resolve('css-minimizer-webpack-plugin'), [
|
|
77
|
+
// {
|
|
78
|
+
// minimizerOptions: {
|
|
79
|
+
// preset: ['default', { normalizeUrl: false }],
|
|
80
|
+
// },
|
|
81
|
+
// },
|
|
82
|
+
// ])
|
|
83
|
+
// chain.plugin('abc').use(BundleAnalyzerPlugin)
|
|
84
|
+
};
|
|
85
|
+
exports.default = getProdConfig;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Compiler } from 'webpack';
|
|
2
|
+
interface IRenderEntryPluginOptions {
|
|
3
|
+
enableV1?: boolean;
|
|
4
|
+
enableV2?: boolean;
|
|
5
|
+
}
|
|
6
|
+
declare class RenderEntryPlugin {
|
|
7
|
+
enableV1?: boolean;
|
|
8
|
+
enableV2?: boolean;
|
|
9
|
+
entriesCache: Map<string, boolean>;
|
|
10
|
+
subPackageRoots: string[];
|
|
11
|
+
constructor(options: IRenderEntryPluginOptions);
|
|
12
|
+
isFileInMainPkg(filePath: any): boolean;
|
|
13
|
+
isFileInSubpackage(filePath: any): boolean;
|
|
14
|
+
apply(compiler: Compiler): void;
|
|
15
|
+
makeGlobalEntry(compiler: Compiler, filename: string, url: string): void;
|
|
16
|
+
makeUmdEntry(compiler: Compiler, filename: string, url: string, libraryName: string): void;
|
|
17
|
+
}
|
|
18
|
+
export default RenderEntryPlugin;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const webpack_1 = require("webpack");
|
|
7
|
+
const XhsMpJsonPlugin_1 = __importDefault(require("../../plugins/XhsMpJsonPlugin"));
|
|
8
|
+
class RenderEntryPlugin {
|
|
9
|
+
constructor(options) {
|
|
10
|
+
const { enableV1, enableV2 } = options;
|
|
11
|
+
this.enableV1 = enableV1;
|
|
12
|
+
this.enableV2 = enableV2;
|
|
13
|
+
this.entriesCache = new Map();
|
|
14
|
+
this.subPackageRoots = [];
|
|
15
|
+
}
|
|
16
|
+
isFileInMainPkg(filePath) {
|
|
17
|
+
return this.subPackageRoots.every(root => !filePath.startsWith(`${root}/`));
|
|
18
|
+
}
|
|
19
|
+
isFileInSubpackage(filePath) {
|
|
20
|
+
return this.subPackageRoots.some(root => filePath.startsWith(`${root}/`));
|
|
21
|
+
}
|
|
22
|
+
apply(compiler) {
|
|
23
|
+
new webpack_1.library.EnableLibraryPlugin('global').apply(compiler);
|
|
24
|
+
const hooks = XhsMpJsonPlugin_1.default.getHooks();
|
|
25
|
+
hooks.collected.tap('RenderEntryPlugin', ({ xhsData }) => {
|
|
26
|
+
const { appJSON } = xhsData;
|
|
27
|
+
this.subPackageRoots = appJSON.subPackages.map(pkg => pkg.root);
|
|
28
|
+
if (this.enableV2) {
|
|
29
|
+
new webpack_1.library.EnableLibraryPlugin('global').apply(compiler);
|
|
30
|
+
Object.keys(appJSON.componentsMap).forEach(compPath => {
|
|
31
|
+
if (this.isFileInMainPkg(compPath)) {
|
|
32
|
+
this.makeGlobalEntry(compiler, `v2/${compPath}.js`, `component-entry-requirements-loader?compPath=${compPath}&pkg=main!`);
|
|
33
|
+
}
|
|
34
|
+
if (this.isFileInSubpackage(compPath)) {
|
|
35
|
+
const root = this.subPackageRoots.find(root => compPath.startsWith(`${root}/`));
|
|
36
|
+
this.makeGlobalEntry(compiler, `v2/${root}/${compPath}.js`, `component-entry-requirements-loader?compPath=${compPath}&pkg=sub&root=${root}!`);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* 继续构建 v1 的包,向前兼容
|
|
42
|
+
*/
|
|
43
|
+
if (this.enableV1) {
|
|
44
|
+
new webpack_1.library.EnableLibraryPlugin('umd').apply(compiler);
|
|
45
|
+
// components
|
|
46
|
+
this.makeUmdEntry(compiler, 'v1/components.js', 'component-entry-loader?pkg=main!', 'XHS_COMPONENTS');
|
|
47
|
+
for (const subPackage of appJSON.subPackages) {
|
|
48
|
+
const { root } = subPackage;
|
|
49
|
+
// subPackages 的 components
|
|
50
|
+
this.makeUmdEntry(compiler, `v1/${root}/components.js`, `component-entry-loader?pkg=sub&root=${root}!`, `XHS_COMPONENTS_${root}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
makeGlobalEntry(compiler, filename, url) {
|
|
56
|
+
if (this.entriesCache.get(filename))
|
|
57
|
+
return;
|
|
58
|
+
const entryOption = webpack_1.EntryOptionPlugin.entryDescriptionToOptions(compiler, filename, {
|
|
59
|
+
import: [url],
|
|
60
|
+
filename,
|
|
61
|
+
});
|
|
62
|
+
new webpack_1.EntryPlugin(compiler.context, url, entryOption).apply(compiler);
|
|
63
|
+
this.entriesCache.set(filename, true);
|
|
64
|
+
}
|
|
65
|
+
makeUmdEntry(compiler, filename, url, libraryName) {
|
|
66
|
+
if (this.entriesCache.get(filename))
|
|
67
|
+
return;
|
|
68
|
+
const entryOption = webpack_1.EntryOptionPlugin.entryDescriptionToOptions(compiler, filename, {
|
|
69
|
+
import: [url],
|
|
70
|
+
filename,
|
|
71
|
+
library: { name: libraryName, type: 'umd' },
|
|
72
|
+
});
|
|
73
|
+
new webpack_1.EntryPlugin(compiler.context, url, entryOption).apply(compiler);
|
|
74
|
+
this.entriesCache.set(filename, true);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.default = RenderEntryPlugin;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const webpack_1 = require("webpack");
|
|
4
|
+
const webpack_sources_1 = require("webpack-sources");
|
|
5
|
+
const runtimeName = 'runtime.render.js';
|
|
6
|
+
const injectCSS = `
|
|
7
|
+
globalThis.__XHS_APPEND_CSS = function(cssText){
|
|
8
|
+
var headTags = document.getElementsByTagName('head')
|
|
9
|
+
var head = document.head || (headTags && headTags[0])
|
|
10
|
+
var cssTextNode = document.createTextNode(String(cssText))
|
|
11
|
+
var styleNode = document.createElement('style')
|
|
12
|
+
styleNode.appendChild(cssTextNode)
|
|
13
|
+
head.appendChild(styleNode)
|
|
14
|
+
};
|
|
15
|
+
`;
|
|
16
|
+
// 注入css跟webpack runtime
|
|
17
|
+
class RenderChunkPlugin {
|
|
18
|
+
constructor(options) {
|
|
19
|
+
this.enableVDom = options.enableVDom;
|
|
20
|
+
}
|
|
21
|
+
apply(compiler) {
|
|
22
|
+
compiler.hooks.compilation.tap(RenderChunkPlugin.name, compilation => {
|
|
23
|
+
compilation.hooks.processAssets.tap({
|
|
24
|
+
name: RenderChunkPlugin.name,
|
|
25
|
+
stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
|
|
26
|
+
}, (assets) => {
|
|
27
|
+
var _a, _b, _c;
|
|
28
|
+
let injectCode = "";
|
|
29
|
+
if (this.enableVDom) {
|
|
30
|
+
// 向前兼容旧架构
|
|
31
|
+
injectCode = injectCSS;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
const runtimeCode = (_a = compilation.getAsset(runtimeName)) === null || _a === void 0 ? void 0 : _a.source.source();
|
|
35
|
+
// 注入css逻辑
|
|
36
|
+
injectCode = `
|
|
37
|
+
${injectCSS}
|
|
38
|
+
if (!globalThis.__XHS_RUNTIME_REGISTERED__) {
|
|
39
|
+
globalThis.__XHS_RUNTIME_REGISTERED__ = true;
|
|
40
|
+
${runtimeCode}
|
|
41
|
+
};`;
|
|
42
|
+
}
|
|
43
|
+
// @ts-ignore
|
|
44
|
+
const appJSON = compiler.xhsData.appJSON;
|
|
45
|
+
const pathMap = [
|
|
46
|
+
(_b = appJSON.pages) === null || _b === void 0 ? void 0 : _b.map(({ path }) => path),
|
|
47
|
+
(_c = appJSON.subPackages) === null || _c === void 0 ? void 0 : _c.map(sub => { var _a; return (_a = sub.pages) === null || _a === void 0 ? void 0 : _a.map(({ path }) => path); })
|
|
48
|
+
].flat(4).filter(Boolean)
|
|
49
|
+
.reduce((ac, path) => {
|
|
50
|
+
ac[`v1/${path}.render.js`] = true;
|
|
51
|
+
ac[`v2/${path}.render.js`] = true;
|
|
52
|
+
return ac;
|
|
53
|
+
}, {});
|
|
54
|
+
// 将runtime 塞到render.js中去
|
|
55
|
+
Object.keys(assets).forEach(key => {
|
|
56
|
+
if (!pathMap[key])
|
|
57
|
+
return;
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
compilation.updateAsset(key, new webpack_sources_1.ConcatSource(injectCode, assets[key]));
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.default = RenderChunkPlugin;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Compiler } from 'webpack';
|
|
2
|
+
interface IRenderEntryPluginOptions {
|
|
3
|
+
enableV1?: boolean;
|
|
4
|
+
enableV2?: boolean;
|
|
5
|
+
}
|
|
6
|
+
declare class RenderEntryPlugin {
|
|
7
|
+
enableV1?: boolean;
|
|
8
|
+
enableV2?: boolean;
|
|
9
|
+
entriesCache: Map<string, boolean>;
|
|
10
|
+
constructor(options: IRenderEntryPluginOptions);
|
|
11
|
+
apply(compiler: Compiler): void;
|
|
12
|
+
makeEntry(compiler: Compiler, name: string, url: string): void;
|
|
13
|
+
}
|
|
14
|
+
export default RenderEntryPlugin;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const webpack_1 = require("webpack");
|
|
7
|
+
const XhsMpJsonPlugin_1 = __importDefault(require("../../plugins/XhsMpJsonPlugin"));
|
|
8
|
+
class RenderEntryPlugin {
|
|
9
|
+
constructor(options) {
|
|
10
|
+
const { enableV1, enableV2 } = options;
|
|
11
|
+
this.enableV1 = enableV1;
|
|
12
|
+
this.enableV2 = enableV2;
|
|
13
|
+
this.entriesCache = new Map();
|
|
14
|
+
}
|
|
15
|
+
apply(compiler) {
|
|
16
|
+
const hooks = XhsMpJsonPlugin_1.default.getHooks();
|
|
17
|
+
hooks.collected.tap('RenderEntryPlugin', ({ xhsData }) => {
|
|
18
|
+
const { appJSON } = xhsData;
|
|
19
|
+
new webpack_1.library.EnableLibraryPlugin('umd').apply(compiler);
|
|
20
|
+
for (const { path } of appJSON.pages) {
|
|
21
|
+
this.enableV1 && this.makeEntry(compiler, `v1/${path}`, `render-entry-loader?mode=v1&path=${path}!`);
|
|
22
|
+
this.enableV2 && this.makeEntry(compiler, `v2/${path}`, `render-entry-loader?mode=v2&path=${path}!`);
|
|
23
|
+
}
|
|
24
|
+
for (const subPackage of appJSON.subPackages) {
|
|
25
|
+
const { pages } = subPackage;
|
|
26
|
+
for (const { path } of pages) {
|
|
27
|
+
// subPackages 的 pages
|
|
28
|
+
this.enableV1 && this.makeEntry(compiler, `v1/${path}`, `render-entry-loader?mode=v1&path=${path}!`);
|
|
29
|
+
this.enableV2 && this.makeEntry(compiler, `v2/${path}`, `render-entry-loader?mode=v2&path=${path}!`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
makeEntry(compiler, name, url) {
|
|
35
|
+
if (this.entriesCache.get(name))
|
|
36
|
+
return;
|
|
37
|
+
const entryOption = webpack_1.EntryOptionPlugin.entryDescriptionToOptions(compiler, name, { import: [url] });
|
|
38
|
+
new webpack_1.EntryPlugin(compiler.context, url, entryOption).apply(compiler);
|
|
39
|
+
this.entriesCache.set(name, true);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.default = RenderEntryPlugin;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Compilation, Compiler } from 'webpack';
|
|
2
|
+
/**
|
|
3
|
+
* @NOTE 分包中使用 SJS 的规则
|
|
4
|
+
*
|
|
5
|
+
* - 整包情况下,可以在所有页面中引用整包内的任意SJS模块。
|
|
6
|
+
* - 分包情况下:
|
|
7
|
+
* - 主包不能引入分包的 SJS 模块。
|
|
8
|
+
* - 分包内部可以引用主分包内的SJS模块。
|
|
9
|
+
* - 分包A 和 分包B 之间不可以互相引用SJS模块。
|
|
10
|
+
* - 独立分包内的SJS模块只能在独立分包内使用,不能跨分包引用。
|
|
11
|
+
*/
|
|
12
|
+
interface IRenderEntryPluginOptions {
|
|
13
|
+
enableV1?: boolean;
|
|
14
|
+
enableV2?: boolean;
|
|
15
|
+
miniprogramDir: string;
|
|
16
|
+
}
|
|
17
|
+
declare class SjsEntryPlugin {
|
|
18
|
+
enableV1?: boolean;
|
|
19
|
+
enableV2?: boolean;
|
|
20
|
+
entriesCache: Map<string, boolean>;
|
|
21
|
+
mainpkgPaths: string[];
|
|
22
|
+
subPackagePaths: Map<string, string[]>;
|
|
23
|
+
miniprogramDir: string;
|
|
24
|
+
subPackageRoots: string[];
|
|
25
|
+
constructor(options: IRenderEntryPluginOptions);
|
|
26
|
+
isFileInMainPkg(filePath: any): boolean;
|
|
27
|
+
isFileInSubpackage(filePath: any): boolean;
|
|
28
|
+
apply(compiler: Compiler): void;
|
|
29
|
+
makeSjsFileContent(compilation: Compilation, chunkName: string, sjsFiles: string[] | undefined, sjsModuleName: string, pkgRoot?: string): void;
|
|
30
|
+
}
|
|
31
|
+
export default SjsEntryPlugin;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
7
|
+
const glob_1 = __importDefault(require("glob"));
|
|
8
|
+
const webpack_sources_1 = require("webpack-sources");
|
|
9
|
+
const webpack_1 = require("webpack");
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
const sjs_loader_1 = __importDefault(require("../../loaders/sjs-loader"));
|
|
12
|
+
const common_1 = require("../../../utils/common");
|
|
13
|
+
function formatSJSPath(i) {
|
|
14
|
+
if (/\.(sjs|wxs)$/.test(i)) {
|
|
15
|
+
return (0, common_1.toUnixPath)(i);
|
|
16
|
+
}
|
|
17
|
+
const suffix = ['sjs', 'wxs'].find(n => fs_extra_1.default.existsSync(`${i}.${n}`));
|
|
18
|
+
if (!suffix) {
|
|
19
|
+
throw new webpack_1.WebpackError(`[SJS文件编译错误] ${i}.sjs 不存在`);
|
|
20
|
+
}
|
|
21
|
+
return (0, common_1.toUnixPath)(suffix ? `${i}.${suffix}` : i);
|
|
22
|
+
}
|
|
23
|
+
class SjsEntryPlugin {
|
|
24
|
+
constructor(options) {
|
|
25
|
+
const { enableV1, enableV2, miniprogramDir } = options;
|
|
26
|
+
this.miniprogramDir = miniprogramDir;
|
|
27
|
+
this.enableV1 = enableV1;
|
|
28
|
+
this.enableV2 = enableV2;
|
|
29
|
+
this.entriesCache = new Map();
|
|
30
|
+
this.mainpkgPaths = [];
|
|
31
|
+
this.subPackagePaths = new Map();
|
|
32
|
+
this.subPackageRoots = [];
|
|
33
|
+
}
|
|
34
|
+
isFileInMainPkg(filePath) {
|
|
35
|
+
return this.subPackageRoots.every(root => !filePath.startsWith(`${root}/`));
|
|
36
|
+
}
|
|
37
|
+
isFileInSubpackage(filePath) {
|
|
38
|
+
return this.subPackageRoots.some(root => filePath.startsWith(`${root}/`));
|
|
39
|
+
}
|
|
40
|
+
apply(compiler) {
|
|
41
|
+
new webpack_1.library.EnableLibraryPlugin('umd').apply(compiler);
|
|
42
|
+
compiler.hooks.watchRun.tap('SjsEntryPlugin', () => {
|
|
43
|
+
this.subPackagePaths.clear();
|
|
44
|
+
this.mainpkgPaths = [];
|
|
45
|
+
});
|
|
46
|
+
compiler.hooks.emit.tapAsync('SjsEntryPlugin', (compilation, callback) => {
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
const { appJSON, miniprogramDir } = (compiler === null || compiler === void 0 ? void 0 : compiler.xhsData) || {};
|
|
49
|
+
this.subPackageRoots = appJSON.subPackages.map(pkg => pkg.root);
|
|
50
|
+
// 默认输出一个空的sjs文件
|
|
51
|
+
this.subPackageRoots.forEach(root => {
|
|
52
|
+
this.subPackagePaths.has(root) || this.subPackagePaths.set(root, []);
|
|
53
|
+
});
|
|
54
|
+
const relativePaths = glob_1.default.sync('**/*.sjs', { cwd: miniprogramDir });
|
|
55
|
+
relativePaths.forEach(relativePath => {
|
|
56
|
+
var _a;
|
|
57
|
+
const sjsAbsPath = (0, common_1.unixJoin)(miniprogramDir, relativePath);
|
|
58
|
+
// 如果是主包内的文件
|
|
59
|
+
if (this.isFileInMainPkg(relativePath)) {
|
|
60
|
+
this.mainpkgPaths.push(sjsAbsPath);
|
|
61
|
+
}
|
|
62
|
+
// 如果命中了分包内的文件
|
|
63
|
+
if (this.isFileInSubpackage(relativePath)) {
|
|
64
|
+
const root = this.subPackageRoots.find(root => relativePath.startsWith(`${root}/`));
|
|
65
|
+
if (root) {
|
|
66
|
+
(_a = this.subPackagePaths.get(root)) === null || _a === void 0 ? void 0 : _a.push(sjsAbsPath);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
// 主包
|
|
71
|
+
this.makeSjsFileContent(compilation, 'sjs.js', [...this.mainpkgPaths], 'XHS_SJS');
|
|
72
|
+
// 分包
|
|
73
|
+
Array.from(this.subPackagePaths.keys()).forEach(pkgRoot => {
|
|
74
|
+
// eslint-disable-next-line
|
|
75
|
+
const paths = this.subPackagePaths.get(pkgRoot);
|
|
76
|
+
this.makeSjsFileContent(compilation, `${pkgRoot}/sjs.js`, [...paths], `XHS_SJS_${pkgRoot}`, pkgRoot);
|
|
77
|
+
});
|
|
78
|
+
callback();
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
makeSjsFileContent(compilation, chunkName, sjsFiles = [], sjsModuleName, pkgRoot) {
|
|
82
|
+
const sjsModules = [];
|
|
83
|
+
// 用于去除重复引入
|
|
84
|
+
const sjsPathCache = new Set();
|
|
85
|
+
/**
|
|
86
|
+
* @NOTE
|
|
87
|
+
* 在这里校验 sjs 模块引入的路径是否符合规则,分包的规则见上方
|
|
88
|
+
*/
|
|
89
|
+
let sjsPath;
|
|
90
|
+
// @ts-ignore
|
|
91
|
+
while ((sjsPath = sjsFiles.shift())) {
|
|
92
|
+
// eslint-disable-line
|
|
93
|
+
if (sjsPathCache.has(sjsPath)) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const sjsAbsPath = formatSJSPath(sjsPath);
|
|
97
|
+
let content = fs_extra_1.default.readFileSync(sjsAbsPath, 'utf8');
|
|
98
|
+
content = sjs_loader_1.default.call(compilation, content, sjsAbsPath, this.miniprogramDir, requirePath => {
|
|
99
|
+
requirePath = (0, common_1.toUnixPath)(requirePath);
|
|
100
|
+
const relativePath = requirePath.replace(`${this.miniprogramDir}/`, '');
|
|
101
|
+
/**
|
|
102
|
+
* 不是当前分包的 sjs 文件不处理
|
|
103
|
+
*/
|
|
104
|
+
if (pkgRoot && !relativePath.startsWith(pkgRoot)) {
|
|
105
|
+
throw new webpack_1.WebpackError(`[SJS 文件编译错误] ${sjsAbsPath},请检测引入路径是否正确或符合分包规则!`);
|
|
106
|
+
}
|
|
107
|
+
sjsFiles.push(requirePath);
|
|
108
|
+
});
|
|
109
|
+
sjsModules.push(`'${sjsPath.replace(`${this.miniprogramDir}/`, '')}': \`${content}\``);
|
|
110
|
+
// 处理后的加入缓存
|
|
111
|
+
sjsPathCache.add(sjsPath);
|
|
112
|
+
}
|
|
113
|
+
const source = new webpack_sources_1.ConcatSource(`globalThis['${sjsModuleName}'] = {`, `${sjsModules.join(',')}`, '}');
|
|
114
|
+
if (this.enableV1) {
|
|
115
|
+
// @ts-ignore
|
|
116
|
+
compilation.assets[`v1/${chunkName}`] = source;
|
|
117
|
+
}
|
|
118
|
+
if (this.enableV2) {
|
|
119
|
+
// @ts-ignore
|
|
120
|
+
compilation.assets[`v2/${chunkName}`] = source;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
exports.default = SjsEntryPlugin;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const webpack_1 = __importDefault(require("webpack"));
|
|
7
|
+
const VueLoaderPlugin_1 = __importDefault(require("../../plugins/VueLoaderPlugin"));
|
|
8
|
+
const XhsMpJsonPlugin_1 = __importDefault(require("../../plugins/XhsMpJsonPlugin"));
|
|
9
|
+
const RenderEntryPlugin_1 = __importDefault(require("./RenderEntryPlugin"));
|
|
10
|
+
const ComponentEntryPlugin_1 = __importDefault(require("./ComponentEntryPlugin"));
|
|
11
|
+
const XhsMpErrorTransformPlugin_1 = __importDefault(require("../../plugins/XhsMpErrorTransformPlugin"));
|
|
12
|
+
const css_1 = __importDefault(require("../../lib/css"));
|
|
13
|
+
const types_1 = require("../../../types");
|
|
14
|
+
const getMlSuffixName_1 = __importDefault(require("../../../utils/getMlSuffixName"));
|
|
15
|
+
const getCssSuffixName_1 = __importDefault(require("../../../utils/getCssSuffixName"));
|
|
16
|
+
const SjsEntryPlugin_1 = __importDefault(require("./SjsEntryPlugin"));
|
|
17
|
+
const RenderChunkPlugin_1 = __importDefault(require("./RenderChunkPlugin"));
|
|
18
|
+
const getBaseConfig = (chain, options) => {
|
|
19
|
+
const { extJsonPath, env, enableV1, enableV2, enableVDom, mpDir, miniprogramDir } = options;
|
|
20
|
+
const isProd = env === types_1.ENV.production;
|
|
21
|
+
const mlReg = new RegExp(`.${(0, getMlSuffixName_1.default)()}$`);
|
|
22
|
+
const cssReg = new RegExp(`.${(0, getCssSuffixName_1.default)()}$`);
|
|
23
|
+
chain.merge({
|
|
24
|
+
externals: { vue: 'vue' },
|
|
25
|
+
output: {
|
|
26
|
+
path: options.distDir,
|
|
27
|
+
filename: '[name].render.js',
|
|
28
|
+
globalObject: 'globalThis',
|
|
29
|
+
},
|
|
30
|
+
module: {
|
|
31
|
+
rule: {
|
|
32
|
+
ml: !options.liteCompiler
|
|
33
|
+
? {
|
|
34
|
+
test: mlReg,
|
|
35
|
+
use: {
|
|
36
|
+
'vue-loader': {
|
|
37
|
+
loader: require.resolve('vue-loader'),
|
|
38
|
+
// 资源路径由组件层处理
|
|
39
|
+
options: {
|
|
40
|
+
transformAssetUrls: { tags: {} },
|
|
41
|
+
compilerOptions: {
|
|
42
|
+
isCustomElement: tag => ['xhs-page', 'xhs-template'].includes(tag),
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
'ml-loader': {
|
|
47
|
+
loader: require.resolve('../../loaders/ml-loader'),
|
|
48
|
+
options,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
}
|
|
52
|
+
: {
|
|
53
|
+
test: mlReg,
|
|
54
|
+
use: {
|
|
55
|
+
'ml-loader': {
|
|
56
|
+
loader: require.resolve('xhs-mp-compiler-ml-loader'),
|
|
57
|
+
options: {
|
|
58
|
+
removeComentNode: isProd,
|
|
59
|
+
vdom: enableVDom,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
[(0, getCssSuffixName_1.default)()]: {
|
|
65
|
+
test: cssReg,
|
|
66
|
+
use: (0, css_1.default)(options, [
|
|
67
|
+
"mini-style-loader",
|
|
68
|
+
'postcss-loader',
|
|
69
|
+
'wxss-loader',
|
|
70
|
+
].filter(Boolean)),
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
chain.plugin('XhsMpJsonPlugin').use(XhsMpJsonPlugin_1.default, [{ mpDir, miniprogramDir, extJsonPath }]);
|
|
76
|
+
// 组件层
|
|
77
|
+
chain.plugin('ComponentEntryPlugin').use(ComponentEntryPlugin_1.default, [{ enableV1, enableV2 }]);
|
|
78
|
+
// 渲染层
|
|
79
|
+
chain.plugin('XhsMpEntryPlugin').use(RenderEntryPlugin_1.default, [{ enableV1, enableV2 }]);
|
|
80
|
+
chain.plugin('SjsEntryPlugin').use(SjsEntryPlugin_1.default, [{ miniprogramDir, enableV1, enableV2 }]);
|
|
81
|
+
if (!options.liteCompiler) {
|
|
82
|
+
chain.plugin('vue').use(VueLoaderPlugin_1.default);
|
|
83
|
+
chain.plugin('XhsMpErrorTransformPlugin').use(XhsMpErrorTransformPlugin_1.default);
|
|
84
|
+
chain.plugin('DefinePlugin').use(webpack_1.default.DefinePlugin, [
|
|
85
|
+
{
|
|
86
|
+
__VUE_PROD_DEVTOOLS__: JSON.stringify(false),
|
|
87
|
+
__VUE_OPTIONS_API__: JSON.stringify(true),
|
|
88
|
+
},
|
|
89
|
+
]);
|
|
90
|
+
}
|
|
91
|
+
if (!enableVDom) {
|
|
92
|
+
// 抽取runtime
|
|
93
|
+
chain.optimization.runtimeChunk({
|
|
94
|
+
name: 'runtime', // runtime.render.js
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
chain.plugin("RenderChunkPlugin").use(RenderChunkPlugin_1.default, [{ enableVDom }]);
|
|
98
|
+
};
|
|
99
|
+
exports.default = getBaseConfig;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Compiler } from 'webpack';
|
|
2
|
+
declare class ServiceEntryPlugin {
|
|
3
|
+
entriesCache: Map<string, boolean>;
|
|
4
|
+
constructor();
|
|
5
|
+
apply(compiler: Compiler): void;
|
|
6
|
+
makeUmdEntry(compiler: Compiler, filename: string, url: string, libraryName: string): void;
|
|
7
|
+
}
|
|
8
|
+
export default ServiceEntryPlugin;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const webpack_1 = require("webpack");
|
|
7
|
+
const XhsMpJsonPlugin_1 = __importDefault(require("../../plugins/XhsMpJsonPlugin"));
|
|
8
|
+
const common_1 = require("../../../utils/common");
|
|
9
|
+
class ServiceEntryPlugin {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.entriesCache = new Map();
|
|
12
|
+
}
|
|
13
|
+
apply(compiler) {
|
|
14
|
+
new webpack_1.library.EnableLibraryPlugin('umd').apply(compiler);
|
|
15
|
+
const hooks = XhsMpJsonPlugin_1.default.getHooks();
|
|
16
|
+
hooks.collected.tap('ServiceEntryPlugin', ({ xhsData }) => {
|
|
17
|
+
const { appJSON } = xhsData;
|
|
18
|
+
this.makeUmdEntry(compiler, 'v1/service.js', 'service-entry-loader?pkg=main!', 'XHS_SERVICE');
|
|
19
|
+
for (const { root } of appJSON.subPackages) {
|
|
20
|
+
this.makeUmdEntry(compiler, (0, common_1.unixJoin)('v1', root, 'service.js'), `service-entry-loader?pkg=sub&root=${root}!`, `XHS_SERVICE_${root}`);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
makeUmdEntry(compiler, filename, url, libraryName) {
|
|
25
|
+
if (this.entriesCache.get(filename))
|
|
26
|
+
return;
|
|
27
|
+
const entryOption = webpack_1.EntryOptionPlugin.entryDescriptionToOptions(compiler, filename, {
|
|
28
|
+
import: [url],
|
|
29
|
+
filename,
|
|
30
|
+
library: { name: libraryName, type: 'umd', },
|
|
31
|
+
});
|
|
32
|
+
new webpack_1.EntryPlugin(compiler.context, url, entryOption).apply(compiler);
|
|
33
|
+
this.entriesCache.set(filename, true);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.default = ServiceEntryPlugin;
|