xhs-mp-compiler-cli 2.0.0-beta.4 → 2.0.1

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.
Files changed (94) hide show
  1. package/dist/bin/xhs-mp-cli-build.js +48 -34
  2. package/dist/bin/xhs-mp-cli-dev.js +44 -44
  3. package/dist/bin/xhs-mp-cli.js +22 -12
  4. package/dist/compiler.d.ts +21 -28
  5. package/dist/compiler.js +327 -327
  6. package/dist/compilerImpl.d.ts +19 -0
  7. package/dist/compilerImpl.js +173 -0
  8. package/dist/config/constant.config.d.ts +24 -0
  9. package/dist/config/constant.config.js +82 -30
  10. package/dist/config/dir.config.js +23 -13
  11. package/dist/index.d.ts +9 -9
  12. package/dist/index.js +454 -408
  13. package/dist/packs/index.d.ts +4 -4
  14. package/dist/packs/index.js +38 -30
  15. package/dist/packs/mp-pack/index.js +38 -30
  16. package/dist/packs/webpack/dev-server/index.js +61 -50
  17. package/dist/packs/webpack/dev-server/lib/ensurePort.js +33 -23
  18. package/dist/packs/webpack/dev-server/lib/openBrowser.js +28 -18
  19. package/dist/packs/webpack/index.d.ts +1 -1
  20. package/dist/packs/webpack/index.js +99 -90
  21. package/dist/packs/webpack/webpack.d.ts +2 -1
  22. package/dist/packs/webpack/webpack.js +81 -63
  23. package/dist/presets/babel.d.ts +0 -1
  24. package/dist/presets/babel.js +64 -58
  25. package/dist/presets/common.js +42 -45
  26. package/dist/presets/configs/minigame/assets/assetsEntryPlugin.js +50 -40
  27. package/dist/presets/configs/minigame/assets/index.js +62 -52
  28. package/dist/presets/configs/minigame/service/index.js +49 -30
  29. package/dist/presets/configs/minigame/service/resolveLimitPlugin.js +33 -23
  30. package/dist/presets/configs/minigame/service/serviceChunkPlugin.d.ts +2 -2
  31. package/dist/presets/configs/minigame/service/serviceChunkPlugin.js +69 -60
  32. package/dist/presets/configs/minigame/service/serviceEntryPlugin.d.ts +3 -3
  33. package/dist/presets/configs/minigame/service/serviceEntryPlugin.js +39 -29
  34. package/dist/presets/configs/miniprogram/assets/assetsEntryPlugin.js +120 -113
  35. package/dist/presets/configs/miniprogram/assets/index.js +45 -43
  36. package/dist/presets/configs/miniprogram/render/component.js +51 -41
  37. package/dist/presets/configs/miniprogram/render/index.d.ts +2 -3
  38. package/dist/presets/configs/miniprogram/render/index.js +85 -68
  39. package/dist/presets/configs/miniprogram/render/render.js +53 -43
  40. package/dist/presets/configs/miniprogram/render/renderChunkPlugin.js +84 -49
  41. package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.d.ts +15 -0
  42. package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.js +164 -126
  43. package/dist/presets/configs/miniprogram/service/index.js +82 -65
  44. package/dist/presets/configs/miniprogram/service/resolveLimitPlugin.js +60 -50
  45. package/dist/presets/configs/miniprogram/service/serviceChunkPlugin.js +93 -55
  46. package/dist/presets/index.js +100 -90
  47. package/dist/presets/loaders/mg-entry-loader.js +32 -22
  48. package/dist/presets/loaders/mini-style-loader.js +79 -55
  49. package/dist/presets/loaders/mp-entry-loader.js +149 -140
  50. package/dist/presets/loaders/wxss-loader.js +73 -63
  51. package/dist/presets/plugins/InjectorPlugin.js +23 -13
  52. package/dist/presets/plugins/SourceMapDevToolPlugin.d.ts +1 -0
  53. package/dist/presets/plugins/SourceMapDevToolPlugin.js +23 -0
  54. package/dist/presets/prod.js +88 -78
  55. package/dist/sharedFs.d.ts +2 -0
  56. package/dist/sharedFs.js +24 -0
  57. package/dist/types/index.d.ts +11 -37
  58. package/dist/types/index.js +23 -13
  59. package/dist/utils/{apm/index.d.ts → apm.d.ts} +5 -3
  60. package/dist/utils/apm.js +245 -0
  61. package/dist/utils/cache.d.ts +28 -0
  62. package/dist/utils/cache.js +49 -0
  63. package/dist/utils/common.js +42 -32
  64. package/dist/utils/css.d.ts +1 -1
  65. package/dist/utils/css.js +43 -35
  66. package/dist/utils/depenedHelper.js +95 -85
  67. package/dist/utils/file.js +39 -29
  68. package/dist/utils/loader-utils.js +63 -53
  69. package/dist/utils/postcssRpx2Vw.js +43 -33
  70. package/dist/utils/project.d.ts +3 -2
  71. package/dist/utils/project.js +129 -119
  72. package/dist/utils/projectConfig.js +24 -15
  73. package/dist/utils/utils.js +51 -42
  74. package/dist/utils/workerPool.d.ts +29 -0
  75. package/dist/utils/workerPool.js +125 -0
  76. package/dist/utils/zip.js +239 -229
  77. package/package.json +33 -14
  78. package/dist/compilerCP.d.ts +0 -1
  79. package/dist/compilerCP.js +0 -175
  80. package/dist/presets/loaders/sjs-loader/index.d.ts +0 -12
  81. package/dist/presets/loaders/sjs-loader/index.js +0 -605
  82. package/dist/presets/loaders/sjs-loader/scope.d.ts +0 -36
  83. package/dist/presets/loaders/sjs-loader/scope.js +0 -122
  84. package/dist/presets/loaders/sjs-loader/tranform.d.ts +0 -2
  85. package/dist/presets/loaders/sjs-loader/tranform.js +0 -31
  86. package/dist/utils/apm/index.js +0 -198
  87. package/dist/utils/asyncWebpack.d.ts +0 -3
  88. package/dist/utils/asyncWebpack.js +0 -38
  89. package/dist/utils/const.d.ts +0 -27
  90. package/dist/utils/const.js +0 -47
  91. package/dist/utils/getSuffixName.d.ts +0 -3
  92. package/dist/utils/getSuffixName.js +0 -18
  93. package/dist/utils/tagTransformMap.d.ts +0 -36
  94. package/dist/utils/tagTransformMap.js +0 -39
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,72 +7,91 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.WebPack = void 0;
13
- const xhs_mp_pack_1 = require("xhs-mp-pack");
14
- const webpack_1 = require("webpack");
15
- const watchOptions = {
16
- aggregateTimeout: 300,
17
- poll: false,
18
- ignored: ['**/node_modules', 'project.config.json', 'project.private.config.json']
19
- };
20
- // 对webpack进行一层包装,和mp-pack对齐
21
- class WebPack extends xhs_mp_pack_1.AbstractMPPack {
22
- constructor(configs, options) {
23
- super();
24
- this.callbacks = [];
25
- this.compiler = null;
26
- this.watcher = null;
27
- this.hadWatch = false;
28
- this.handleProgress = progress => {
29
- this.emit('progress', progress);
30
- };
31
- this.project = options.project;
32
- this.packSetting = options.packSetting;
33
- this.compiler = (0, webpack_1.webpack)(configs);
34
- new webpack_1.ProgressPlugin(this.handleProgress).apply(this.compiler);
10
+ (function (factory) {
11
+ if (typeof module === "object" && typeof module.exports === "object") {
12
+ var v = factory(require, exports);
13
+ if (v !== undefined) module.exports = v;
35
14
  }
36
- get hooks() {
37
- return this.compiler.hooks;
15
+ else if (typeof define === "function" && define.amd) {
16
+ define(["require", "exports", "xhs-mp-pack", "webpack"], factory);
38
17
  }
39
- watch(config, callback) {
40
- return new Promise(resolve => {
41
- if (this.watcher) {
42
- this.watcher.close(() => { });
43
- this.watcher = null;
44
- }
45
- if (config.scene === 'reWatch') {
46
- this.hadWatch = false;
47
- }
48
- this.watcher = this.compiler.watch(Object.assign(Object.assign({}, watchOptions), config), (err, stats) => {
49
- if (!this.hadWatch) {
50
- this.hadWatch = true;
51
- resolve({
52
- err, stats
53
- });
18
+ })(function (require, exports) {
19
+ "use strict";
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.WebPack = void 0;
22
+ const xhs_mp_pack_1 = require("xhs-mp-pack");
23
+ const webpack_1 = require("webpack");
24
+ const watchOptions = {
25
+ aggregateTimeout: 300,
26
+ poll: false,
27
+ ignored: ['**/node_modules', 'project.config.json', 'project.private.config.json']
28
+ };
29
+ // 对webpack进行一层包装,和mp-pack对齐
30
+ class WebPack extends xhs_mp_pack_1.AbstractMPPack {
31
+ constructor(configs, options) {
32
+ super();
33
+ this.callbacks = [];
34
+ this.compiler = null;
35
+ this.watcher = null;
36
+ this.hadWatch = false;
37
+ this.handleProgress = (percentage, status, info) => {
38
+ this.emit('progress', {
39
+ percentage,
40
+ status,
41
+ info
42
+ });
43
+ };
44
+ this.handleBuildInfo = (info) => {
45
+ this.emit('buildInfo', info);
46
+ };
47
+ this.project = options.project;
48
+ this.packSetting = options.packSetting;
49
+ this.compiler = (0, webpack_1.webpack)(configs);
50
+ new webpack_1.ProgressPlugin(this.handleProgress).apply(this.compiler);
51
+ new xhs_mp_pack_1.BuildInfoPlugin({ handler: this.handleBuildInfo }).apply(this.compiler);
52
+ }
53
+ get hooks() {
54
+ return this.compiler.hooks;
55
+ }
56
+ watch(config, callback) {
57
+ return new Promise(resolve => {
58
+ if (this.watcher) {
59
+ this.watcher.close(() => { });
60
+ this.watcher = null;
54
61
  }
55
- else {
56
- callback === null || callback === void 0 ? void 0 : callback(err, stats);
62
+ if (config.scene === 'reWatch') {
63
+ this.hadWatch = false;
57
64
  }
65
+ this.watcher = this.compiler.watch(Object.assign(Object.assign({}, watchOptions), config), (err, stats) => {
66
+ if (!this.hadWatch) {
67
+ this.hadWatch = true;
68
+ resolve({
69
+ err, stats
70
+ });
71
+ }
72
+ else {
73
+ callback === null || callback === void 0 ? void 0 : callback(err, stats);
74
+ }
75
+ });
58
76
  });
59
- });
60
- }
61
- changeCompileOptions(config) {
62
- // 空实现
63
- }
64
- activatePkgs(compilePkgs) {
65
- // 空实现
66
- }
67
- reCompilePkgs(config, callback) {
68
- return __awaiter(this, void 0, void 0, function* () {
77
+ }
78
+ changeCompileOptions(config) {
69
79
  // 空实现
70
- });
71
- }
72
- build(callback) {
73
- this.compiler.run(callback);
74
- }
75
- close(callback) {
76
- this.compiler.close(callback);
80
+ }
81
+ activatePkgs(compilePkgs) {
82
+ // 空实现
83
+ }
84
+ reCompilePkgs(config, callback) {
85
+ return __awaiter(this, void 0, void 0, function* () {
86
+ // 空实现
87
+ });
88
+ }
89
+ build(callback) {
90
+ this.compiler.run(callback);
91
+ }
92
+ close(callback) {
93
+ this.compiler.close(callback);
94
+ }
77
95
  }
78
- }
79
- exports.WebPack = WebPack;
96
+ exports.WebPack = WebPack;
97
+ });
@@ -2,7 +2,6 @@ import { Config } from '../packs';
2
2
  import { IPresetOptions } from '../types';
3
3
  /**
4
4
  * babel 仅关注语法转换,polyfill 在 js-core 中已经内置
5
- * 目前 polyfill 仅支持到 'ios_saf >= 10', 'chrome >= 83'。语法构建中,会默认支持。
6
5
  */
7
6
  declare const getBaseConfig: (chain: Config, options: IPresetOptions) => void;
8
7
  export default getBaseConfig;
@@ -1,59 +1,65 @@
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("../utils/const"));
7
- const types_1 = require("../types");
8
- /**
9
- * babel 仅关注语法转换,polyfill 在 js-core 中已经内置
10
- * 目前 polyfill 仅支持到 'ios_saf >= 10', 'chrome >= 83'。语法构建中,会默认支持。
11
- */
12
- const getBaseConfig = (chain, options) => {
13
- const { packSetting } = options;
14
- const { env, tsConfigPath } = packSetting;
15
- const swcTargets = env === types_1.ENV.development ? const_1.default.DEV_TARGETS : const_1.default.PROD_TARGETS;
16
- chain.module
17
- .rule('js')
18
- .test(/\.js$/)
19
- .exclude.add(/node_modules/)
20
- .end()
21
- .use('js-loader')
22
- .loader(require.resolve('swc-loader'))
23
- .options({
24
- jsc: { externalHelpers: true },
25
- env: {
26
- targets: swcTargets,
27
- coreJS: 3
28
- }
29
- });
30
- chain.module
31
- .rule('ts')
32
- .test(/\.ts$/)
33
- .exclude.add(/node_modules/)
34
- .end()
35
- .use('ts-loader')
36
- .loader(require.resolve('swc-loader'))
37
- .options({
38
- jsc: {
39
- externalHelpers: true,
40
- parser: { syntax: 'typescript' }
41
- },
42
- env: {
43
- targets: swcTargets,
44
- coreJS: 3
45
- }
46
- });
47
- if (tsConfigPath) {
48
- chain.resolve.extensions.add('.ts');
49
- chain.plugin('ts-checker').use(require.resolve('fork-ts-checker-webpack-plugin'), [
50
- {
51
- async: true,
52
- typescript: {
53
- configFile: tsConfigPath
54
- }
55
- }
56
- ]);
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "../config/constant.config", "../types"], factory);
57
8
  }
58
- };
59
- exports.default = getBaseConfig;
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const constant_config_1 = require("../config/constant.config");
13
+ const types_1 = require("../types");
14
+ /**
15
+ * babel 仅关注语法转换,polyfill 在 js-core 中已经内置
16
+ */
17
+ const getBaseConfig = (chain, options) => {
18
+ const { packSetting } = options;
19
+ const { env, tsConfigPath } = packSetting;
20
+ const swcTargets = env === types_1.ENV.development ? constant_config_1.DEV_TARGETS : constant_config_1.PROD_TARGETS;
21
+ chain.module
22
+ .rule('js')
23
+ .test(/\.js$/)
24
+ .exclude.add(/node_modules/)
25
+ .end()
26
+ .use('js-loader')
27
+ .loader(require.resolve('swc-loader'))
28
+ .options({
29
+ jsc: { externalHelpers: true },
30
+ env: {
31
+ targets: swcTargets,
32
+ coreJS: 3
33
+ }
34
+ });
35
+ chain.module
36
+ .rule('ts')
37
+ .test(/\.ts$/)
38
+ .exclude.add(/node_modules/)
39
+ .end()
40
+ .use('ts-loader')
41
+ .loader(require.resolve('swc-loader'))
42
+ .options({
43
+ jsc: {
44
+ externalHelpers: true,
45
+ parser: { syntax: 'typescript' }
46
+ },
47
+ env: {
48
+ targets: swcTargets,
49
+ coreJS: 3
50
+ }
51
+ });
52
+ if (tsConfigPath) {
53
+ chain.resolve.extensions.add('.ts');
54
+ chain.plugin('ts-checker').use(require.resolve('fork-ts-checker-webpack-plugin'), [
55
+ {
56
+ async: true,
57
+ typescript: {
58
+ configFile: tsConfigPath
59
+ }
60
+ }
61
+ ]);
62
+ }
63
+ };
64
+ exports.default = getBaseConfig;
65
+ });
@@ -1,48 +1,45 @@
1
- "use strict";
2
1
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
2
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
3
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const path_1 = __importDefault(require("path"));
7
- const presetCommon = (chain, options) => {
8
- const { packSetting, project } = options;
9
- const { env, watch, enableSourcemap, cacheDirectory } = packSetting;
10
- chain.merge({
11
- stats: 'errors-only',
12
- output: {
13
- pathinfo: false,
14
- },
15
- resolve: {
16
- roots: [project.miniprogramDir],
17
- extensions: ['.js'],
18
- modules: [
19
- path_1.default.join(project.projectPath, 'node_modules'),
20
- project.projectPath,
21
- path_1.default.join(__dirname, '../../node_modules/')
22
- ],
23
- },
24
- resolveLoader: {
25
- modules: [path_1.default.join(__dirname, './loaders')],
26
- extensions: ['.js', '.ts'],
27
- },
28
- });
29
- chain.watch(!!watch);
30
- chain.mode('development');
31
- chain.devtool(enableSourcemap ? 'source-map' : false);
32
- // @ts-ignore
33
- chain.target(['web', 'es5']);
34
- // chain.cache(
35
- // env === ENV.production
36
- // ? false
37
- // : {
38
- // type: 'filesystem',
39
- // cacheDirectory:
40
- // cacheDirectory || path.join(__dirname, '../../node_modules/.cache'),
41
- // version: project.miniprogramDir,
42
- // buildDependencies: {
43
- // config: [path.join(project.miniprogramDir, 'app.json')],
44
- // },
45
- // },
46
- // )
47
- };
48
- exports.default = presetCommon;
4
+ (function (factory) {
5
+ if (typeof module === "object" && typeof module.exports === "object") {
6
+ var v = factory(require, exports);
7
+ if (v !== undefined) module.exports = v;
8
+ }
9
+ else if (typeof define === "function" && define.amd) {
10
+ define(["require", "exports", "path"], factory);
11
+ }
12
+ })(function (require, exports) {
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const path_1 = __importDefault(require("path"));
16
+ const presetCommon = (chain, options) => {
17
+ const { packSetting, project } = options;
18
+ const { action, enableSourcemap } = packSetting;
19
+ chain.merge({
20
+ stats: 'errors-only',
21
+ output: {
22
+ pathinfo: false,
23
+ },
24
+ resolve: {
25
+ roots: [project.miniprogramDir],
26
+ extensions: ['.js'],
27
+ modules: [
28
+ path_1.default.join(project.projectPath, 'node_modules'),
29
+ project.projectPath,
30
+ path_1.default.join(__dirname, '../../node_modules/')
31
+ ],
32
+ },
33
+ resolveLoader: {
34
+ modules: [path_1.default.join(__dirname, './loaders')],
35
+ extensions: ['.js', '.ts'],
36
+ },
37
+ });
38
+ chain.watch(action === 'dev');
39
+ chain.mode('development');
40
+ chain.devtool(enableSourcemap ? 'source-map' : false);
41
+ // @ts-ignore
42
+ chain.target(['web', 'es5']);
43
+ };
44
+ exports.default = presetCommon;
45
+ });
@@ -1,46 +1,56 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const packs_1 = require("../../../../packs");
4
- const lodash_1 = require("lodash");
5
- const common_1 = require("../../../../utils/common");
6
- const xhs_mp_project_1 = require("xhs-mp-project");
7
- class MpEntryPlugin {
8
- constructor(options) {
9
- this.options = options;
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
10
5
  }
11
- apply(compiler) {
12
- // 在资源优化阶段处理app.json
13
- compiler.hooks.compilation.tap(MpEntryPlugin.name, compilation => {
14
- // @ts-ignore
15
- compilation.hooks.processAssets.tap({
16
- name: MpEntryPlugin.name,
17
- stage: packs_1.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_COMPATIBILITY, // see below for more stages
18
- }, (assets) => {
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "../../../../packs", "lodash", "../../../../utils/common", "xhs-mp-project"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const packs_1 = require("../../../../packs");
13
+ const lodash_1 = require("lodash");
14
+ const common_1 = require("../../../../utils/common");
15
+ const xhs_mp_project_1 = require("xhs-mp-project");
16
+ class MpEntryPlugin {
17
+ constructor(options) {
18
+ this.options = options;
19
+ }
20
+ apply(compiler) {
21
+ // 在资源优化阶段处理app.json
22
+ compiler.hooks.compilation.tap(MpEntryPlugin.name, compilation => {
19
23
  // @ts-ignore
20
- const { appJSON } = this.options.project;
21
- if (assets) {
22
- Object.assign(assets, this.getAppJson((0, lodash_1.cloneDeep)(appJSON)));
23
- // 兼容服务端,始终创建 v0/app.json
24
- assets['v0/app.json'] = this.getLegacyAppJSON((0, lodash_1.cloneDeep)(appJSON));
25
- }
24
+ compilation.hooks.processAssets.tap({
25
+ name: MpEntryPlugin.name,
26
+ stage: packs_1.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_COMPATIBILITY, // see below for more stages
27
+ }, (assets) => {
28
+ // @ts-ignore
29
+ const { appJSON } = this.options.project;
30
+ if (assets) {
31
+ Object.assign(assets, this.getAppJson((0, lodash_1.cloneDeep)(appJSON)));
32
+ // 兼容服务端,始终创建 v0/app.json
33
+ assets['v0/app.json'] = this.getLegacyAppJSON((0, lodash_1.cloneDeep)(appJSON));
34
+ }
35
+ });
26
36
  });
27
- });
28
- }
29
- getAppJson(appJSON) {
30
- const assets = {};
31
- const appJsonSource = new packs_1.RawSource(JSON.stringify(xhs_mp_project_1.utils.pureAppJSON(appJSON)));
32
- assets['v1/app.json'] = appJsonSource;
33
- for (const subpackage of appJSON.subPackages) {
34
- if (subpackage.independent) {
35
- assets[(0, common_1.unixJoin)("v1", subpackage.dirname, "app.json")] = appJsonSource;
37
+ }
38
+ getAppJson(appJSON) {
39
+ const assets = {};
40
+ const appJsonSource = new packs_1.RawSource(JSON.stringify(xhs_mp_project_1.utils.pureAppJSON(appJSON)));
41
+ assets['v1/app.json'] = appJsonSource;
42
+ for (const subpackage of appJSON.subPackages) {
43
+ if (subpackage.independent) {
44
+ assets[(0, common_1.unixJoin)("v1", subpackage.dirname, "app.json")] = appJsonSource;
45
+ }
36
46
  }
47
+ return assets;
48
+ }
49
+ getLegacyAppJSON(appJSON) {
50
+ // 兼容的整包,将 subPackages 合并到 pages 内
51
+ appJSON = xhs_mp_project_1.utils.pureAppJSON(appJSON, 'v0');
52
+ return new packs_1.RawSource(JSON.stringify(appJSON));
37
53
  }
38
- return assets;
39
- }
40
- getLegacyAppJSON(appJSON) {
41
- // 兼容的整包,将 subPackages 合并到 pages 内
42
- appJSON = xhs_mp_project_1.utils.pureAppJSON(appJSON, 'v0');
43
- return new packs_1.RawSource(JSON.stringify(appJSON));
44
54
  }
45
- }
46
- exports.default = MpEntryPlugin;
55
+ exports.default = MpEntryPlugin;
56
+ });
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -11,55 +10,66 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
10
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
11
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
12
  };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.presetAssets = void 0;
16
- const path_1 = __importDefault(require("path"));
17
- const assetsEntryPlugin_1 = __importDefault(require("./assetsEntryPlugin"));
18
- const copy_webpack_plugin_1 = __importDefault(require("copy-webpack-plugin"));
19
- const const_1 = __importDefault(require("../../../../utils/const"));
20
- const InjectorPlugin_1 = require("../../../plugins/InjectorPlugin");
21
- const ASSETS_EXTS = const_1.default.ASSETS_EXTS
22
- .map(i => `.${i}`);
23
- const presetAssets = (chain, options) => {
24
- const { packSetting, project } = options;
25
- const { distDir } = packSetting;
26
- chain.merge({
27
- output: {
28
- path: distDir,
29
- },
30
- });
31
- const projectJsons = [
32
- 'game.json',
33
- 'package.json',
34
- 'package-lock.json',
35
- 'pkgInfo.json',
36
- 'project.config.json',
37
- 'project.private.config.json',
38
- ].map(i => path_1.default.resolve(project.projectPath, i));
39
- const copyPatterns = [
40
- {
41
- noErrorOnMissing: true,
42
- from: `${project.projectPath}/**/*`,
43
- filter: (resourcePath) => __awaiter(void 0, void 0, void 0, function* () {
44
- if (resourcePath.includes('node_modules')) {
13
+ (function (factory) {
14
+ if (typeof module === "object" && typeof module.exports === "object") {
15
+ var v = factory(require, exports);
16
+ if (v !== undefined) module.exports = v;
17
+ }
18
+ else if (typeof define === "function" && define.amd) {
19
+ define(["require", "exports", "path", "./assetsEntryPlugin", "copy-webpack-plugin", "../../../../config/constant.config", "../../../plugins/InjectorPlugin", "../../../../utils/cache"], factory);
20
+ }
21
+ })(function (require, exports) {
22
+ "use strict";
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.presetAssets = void 0;
25
+ const path_1 = __importDefault(require("path"));
26
+ const assetsEntryPlugin_1 = __importDefault(require("./assetsEntryPlugin"));
27
+ const copy_webpack_plugin_1 = __importDefault(require("copy-webpack-plugin"));
28
+ const constant_config_1 = require("../../../../config/constant.config");
29
+ const InjectorPlugin_1 = require("../../../plugins/InjectorPlugin");
30
+ const cache_1 = require("../../../../utils/cache");
31
+ let FIXED_ASSETS_EXTS = constant_config_1.ASSETS_EXTS
32
+ .map(i => `.${i}`);
33
+ const presetAssets = (chain, options) => {
34
+ const { packSetting, project } = options;
35
+ const { distDir, cacheDirectory } = packSetting;
36
+ const absCacheDirectory = path_1.default.join(cacheDirectory, 'assets');
37
+ chain.merge(Object.assign(Object.assign({}, (0, cache_1.getCacheConfig)(absCacheDirectory, options)), { output: {
38
+ path: distDir,
39
+ } }));
40
+ const projectJsons = [
41
+ 'game.json',
42
+ 'package.json',
43
+ 'package-lock.json',
44
+ 'pkgInfo.json',
45
+ 'project.config.json',
46
+ 'project.private.config.json',
47
+ ].map(i => path_1.default.resolve(project.projectPath, i));
48
+ const copyPatterns = [
49
+ {
50
+ noErrorOnMissing: true,
51
+ from: `${project.projectPath}/**/*`,
52
+ filter: (resourcePath) => __awaiter(void 0, void 0, void 0, function* () {
53
+ if (resourcePath.includes('node_modules')) {
54
+ return false;
55
+ }
56
+ const extname = path_1.default.extname(resourcePath);
57
+ if (FIXED_ASSETS_EXTS.includes(extname)) {
58
+ return true;
59
+ }
60
+ if (extname === '.json' && !projectJsons.includes(resourcePath)) {
61
+ return true;
62
+ }
45
63
  return false;
46
- }
47
- const extname = path_1.default.extname(resourcePath);
48
- if (ASSETS_EXTS.includes(extname)) {
49
- return true;
50
- }
51
- if (extname === '.json' && !projectJsons.includes(resourcePath)) {
52
- return true;
53
- }
54
- return false;
55
- }),
56
- to: 'v1',
57
- context: project.projectPath,
58
- globOptions: { gitignore: true },
59
- },
60
- ];
61
- chain.plugin('InjectorPlugin').use(InjectorPlugin_1.InjectorPlugin, [options]);
62
- chain.plugin('CopyPlugin').use(copy_webpack_plugin_1.default, [{ patterns: copyPatterns }]);
63
- chain.plugin('AssetsEntryPlugin').use(assetsEntryPlugin_1.default, [options]);
64
- };
65
- exports.presetAssets = presetAssets;
64
+ }),
65
+ to: 'v1',
66
+ context: project.projectPath,
67
+ globOptions: { gitignore: true },
68
+ },
69
+ ];
70
+ chain.plugin('InjectorPlugin').use(InjectorPlugin_1.InjectorPlugin, [options]);
71
+ chain.plugin('CopyPlugin').use(copy_webpack_plugin_1.default, [{ patterns: copyPatterns }]);
72
+ chain.plugin('AssetsEntryPlugin').use(assetsEntryPlugin_1.default, [options]);
73
+ };
74
+ exports.presetAssets = presetAssets;
75
+ });