xhs-mp-compiler-cli 1.1.1 → 1.1.3

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 (110) hide show
  1. package/package.json +11 -5
  2. package/dist/bin/xhs-mp-cli-build.d.ts +0 -2
  3. package/dist/bin/xhs-mp-cli-build.js +0 -40
  4. package/dist/bin/xhs-mp-cli-dev.d.ts +0 -2
  5. package/dist/bin/xhs-mp-cli-dev.js +0 -59
  6. package/dist/bin/xhs-mp-cli.d.ts +0 -2
  7. package/dist/bin/xhs-mp-cli.js +0 -16
  8. package/dist/compiler.d.ts +0 -76
  9. package/dist/compiler.js +0 -361
  10. package/dist/compilerCP.d.ts +0 -1
  11. package/dist/compilerCP.js +0 -175
  12. package/dist/config/constant.config.d.ts +0 -7
  13. package/dist/config/constant.config.js +0 -10
  14. package/dist/dev-server/index.d.ts +0 -3
  15. package/dist/dev-server/index.js +0 -64
  16. package/dist/dev-server/lib/ensurePort.d.ts +0 -2
  17. package/dist/dev-server/lib/ensurePort.js +0 -32
  18. package/dist/dev-server/lib/openBrowser.d.ts +0 -2
  19. package/dist/dev-server/lib/openBrowser.js +0 -23
  20. package/dist/dev-server/lib/openChrome.applescript +0 -78
  21. package/dist/index.d.ts +0 -1
  22. package/dist/index.js +0 -5
  23. package/dist/packs/index.d.ts +0 -14
  24. package/dist/packs/index.js +0 -31
  25. package/dist/packs/mp-pack/index.d.ts +0 -3
  26. package/dist/packs/mp-pack/index.js +0 -32
  27. package/dist/packs/webpack/index.d.ts +0 -3
  28. package/dist/packs/webpack/index.js +0 -92
  29. package/dist/packs/webpack/webpack.d.ts +0 -21
  30. package/dist/packs/webpack/webpack.js +0 -79
  31. package/dist/presets/babel.d.ts +0 -8
  32. package/dist/presets/babel.js +0 -59
  33. package/dist/presets/common.d.ts +0 -4
  34. package/dist/presets/common.js +0 -46
  35. package/dist/presets/configs/minigame/assets/assetsEntryPlugin.d.ts +0 -10
  36. package/dist/presets/configs/minigame/assets/assetsEntryPlugin.js +0 -46
  37. package/dist/presets/configs/minigame/assets/index.d.ts +0 -2
  38. package/dist/presets/configs/minigame/assets/index.js +0 -65
  39. package/dist/presets/configs/minigame/service/index.d.ts +0 -3
  40. package/dist/presets/configs/minigame/service/index.js +0 -34
  41. package/dist/presets/configs/minigame/service/resolveLimitPlugin.d.ts +0 -8
  42. package/dist/presets/configs/minigame/service/resolveLimitPlugin.js +0 -35
  43. package/dist/presets/configs/minigame/service/serviceChunkPlugin.d.ts +0 -9
  44. package/dist/presets/configs/minigame/service/serviceChunkPlugin.js +0 -69
  45. package/dist/presets/configs/minigame/service/serviceEntryPlugin.d.ts +0 -10
  46. package/dist/presets/configs/minigame/service/serviceEntryPlugin.js +0 -32
  47. package/dist/presets/configs/miniprogram/assets/assetsEntryPlugin.d.ts +0 -12
  48. package/dist/presets/configs/miniprogram/assets/assetsEntryPlugin.js +0 -132
  49. package/dist/presets/configs/miniprogram/assets/index.d.ts +0 -4
  50. package/dist/presets/configs/miniprogram/assets/index.js +0 -47
  51. package/dist/presets/configs/miniprogram/render/component.d.ts +0 -3
  52. package/dist/presets/configs/miniprogram/render/component.js +0 -47
  53. package/dist/presets/configs/miniprogram/render/index.d.ts +0 -5
  54. package/dist/presets/configs/miniprogram/render/index.js +0 -70
  55. package/dist/presets/configs/miniprogram/render/render.d.ts +0 -3
  56. package/dist/presets/configs/miniprogram/render/render.js +0 -49
  57. package/dist/presets/configs/miniprogram/render/renderChunkPlugin.d.ts +0 -8
  58. package/dist/presets/configs/miniprogram/render/renderChunkPlugin.js +0 -55
  59. package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.d.ts +0 -15
  60. package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.js +0 -163
  61. package/dist/presets/configs/miniprogram/service/index.d.ts +0 -5
  62. package/dist/presets/configs/miniprogram/service/index.js +0 -72
  63. package/dist/presets/configs/miniprogram/service/resolveLimitPlugin.d.ts +0 -8
  64. package/dist/presets/configs/miniprogram/service/resolveLimitPlugin.js +0 -66
  65. package/dist/presets/configs/miniprogram/service/serviceChunkPlugin.d.ts +0 -9
  66. package/dist/presets/configs/miniprogram/service/serviceChunkPlugin.js +0 -65
  67. package/dist/presets/index.d.ts +0 -2
  68. package/dist/presets/index.js +0 -95
  69. package/dist/presets/loaders/mg-entry-loader.d.ts +0 -1
  70. package/dist/presets/loaders/mg-entry-loader.js +0 -27
  71. package/dist/presets/loaders/mini-style-loader.d.ts +0 -1
  72. package/dist/presets/loaders/mini-style-loader.js +0 -72
  73. package/dist/presets/loaders/mp-entry-loader.d.ts +0 -1
  74. package/dist/presets/loaders/mp-entry-loader.js +0 -196
  75. package/dist/presets/loaders/sjs-loader/index.d.ts +0 -12
  76. package/dist/presets/loaders/sjs-loader/index.js +0 -605
  77. package/dist/presets/loaders/sjs-loader/scope.d.ts +0 -36
  78. package/dist/presets/loaders/sjs-loader/scope.js +0 -122
  79. package/dist/presets/loaders/sjs-loader/tranform.d.ts +0 -2
  80. package/dist/presets/loaders/sjs-loader/tranform.js +0 -31
  81. package/dist/presets/loaders/wxss-loader.d.ts +0 -1
  82. package/dist/presets/loaders/wxss-loader.js +0 -77
  83. package/dist/presets/plugins/InjectorPlugin.d.ts +0 -7
  84. package/dist/presets/plugins/InjectorPlugin.js +0 -14
  85. package/dist/presets/prod.d.ts +0 -4
  86. package/dist/presets/prod.js +0 -80
  87. package/dist/types/index.d.ts +0 -118
  88. package/dist/types/index.js +0 -13
  89. package/dist/utils/asyncWebpack.d.ts +0 -3
  90. package/dist/utils/asyncWebpack.js +0 -38
  91. package/dist/utils/common.d.ts +0 -8
  92. package/dist/utils/common.js +0 -36
  93. package/dist/utils/const.d.ts +0 -27
  94. package/dist/utils/const.js +0 -47
  95. package/dist/utils/css.d.ts +0 -2
  96. package/dist/utils/css.js +0 -41
  97. package/dist/utils/depenedHelper.d.ts +0 -31
  98. package/dist/utils/depenedHelper.js +0 -89
  99. package/dist/utils/getSuffixName.d.ts +0 -3
  100. package/dist/utils/getSuffixName.js +0 -18
  101. package/dist/utils/loader-utils.d.ts +0 -15
  102. package/dist/utils/loader-utils.js +0 -59
  103. package/dist/utils/postcssRpx2Vw.d.ts +0 -12
  104. package/dist/utils/postcssRpx2Vw.js +0 -35
  105. package/dist/utils/projectConfig.d.ts +0 -1
  106. package/dist/utils/projectConfig.js +0 -20
  107. package/dist/utils/tagTransformMap.d.ts +0 -35
  108. package/dist/utils/tagTransformMap.js +0 -38
  109. package/dist/utils/utils.d.ts +0 -5
  110. package/dist/utils/utils.js +0 -37
@@ -1,175 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const _1 = require("./");
13
- let globalConfig = JSON.parse(process.argv[2]);
14
- let hadWatchBuilt = false;
15
- let projectCompiler;
16
- /* 发送消息给父进程 */
17
- const sendToMaster = (method, data = {}) => {
18
- var _a;
19
- (_a = process.send) === null || _a === void 0 ? void 0 : _a.call(process, JSON.stringify(Object.assign({ method }, data)));
20
- };
21
- const tryGC = () => {
22
- if (global.gc) {
23
- global.gc();
24
- }
25
- };
26
- function formatWebpackMessages(err, stats) {
27
- if (err) {
28
- return { errors: [err.message], warnings: [] };
29
- }
30
- const json = stats.toJson({ warnings: true, errors: true, all: false });
31
- const formattedErrors = json.errors.map(item => item.message);
32
- const formattedWarnings = json.warnings.map(item => item.message);
33
- const result = { errors: formattedErrors, warnings: formattedWarnings };
34
- return result;
35
- }
36
- const handlers = {
37
- runWatch: (msg) => __awaiter(void 0, void 0, void 0, function* () {
38
- const { uuid, data } = msg;
39
- if (!projectCompiler) {
40
- projectCompiler = (0, _1.createCompiler)(data);
41
- }
42
- sendToMaster('run watch start');
43
- const { err, stats } = (yield projectCompiler.watch({
44
- scene: data.scene
45
- }, (err, stats) => {
46
- var _a;
47
- console.log('file change...');
48
- // 修改文件时构建
49
- const hasError = err || ((_a = stats === null || stats === void 0 ? void 0 : stats.hasErrors) === null || _a === void 0 ? void 0 : _a.call(stats));
50
- if (hasError) {
51
- sendToMaster('emitCompileStats', {
52
- stats: formatWebpackMessages(err, stats)
53
- });
54
- return;
55
- }
56
- sendToMaster('compileFinishWhenFileChange');
57
- }));
58
- console.log('it is watching...');
59
- const hasError = err || stats.hasErrors();
60
- if (hasError) {
61
- sendToMaster('callback', {
62
- uuid,
63
- success: false,
64
- stats: formatWebpackMessages(err, stats)
65
- });
66
- }
67
- else {
68
- hadWatchBuilt = true;
69
- sendToMaster('callback', {
70
- uuid,
71
- success: true
72
- });
73
- }
74
- }),
75
- changeCompileOptions(msg) {
76
- const { data } = msg;
77
- projectCompiler === null || projectCompiler === void 0 ? void 0 : projectCompiler.changeCompileOptions(data);
78
- },
79
- activatePkgs: (msg) => __awaiter(void 0, void 0, void 0, function* () {
80
- var _a, _b, _c;
81
- const { uuid, data: { compilePkgs } } = msg;
82
- console.log('run activate start', compilePkgs);
83
- const { err, stats } = (yield ((_b = (_a = projectCompiler).activatePkgs) === null || _b === void 0 ? void 0 : _b.call(_a, compilePkgs)));
84
- console.log('run activate finish', err, stats);
85
- const hasError = err || ((_c = stats === null || stats === void 0 ? void 0 : stats.hasErrors) === null || _c === void 0 ? void 0 : _c.call(stats));
86
- if (hasError) {
87
- sendToMaster('callback', {
88
- uuid,
89
- success: false,
90
- stats: formatWebpackMessages(err, stats)
91
- });
92
- }
93
- else {
94
- hadWatchBuilt = true;
95
- sendToMaster('callback', {
96
- uuid,
97
- success: true
98
- });
99
- }
100
- }),
101
- runBuild: msg => {
102
- console.log('sp run build', msg);
103
- const { uuid, data } = msg;
104
- if (!projectCompiler) {
105
- projectCompiler = (0, _1.createCompiler)(data);
106
- }
107
- projectCompiler.on('progress', progress => {
108
- sendToMaster('compilePercent', {
109
- percentage: progress
110
- });
111
- });
112
- projectCompiler.build((err, stats) => {
113
- var _a;
114
- const hasError = err || ((_a = stats === null || stats === void 0 ? void 0 : stats.hasErrors) === null || _a === void 0 ? void 0 : _a.call(stats));
115
- console.log('sp run build finish', stats);
116
- if (hasError) {
117
- const statsInfo = formatWebpackMessages(err, stats);
118
- sendToMaster('callback', {
119
- uuid,
120
- success: false,
121
- stats: statsInfo
122
- });
123
- return;
124
- }
125
- sendToMaster('callback', {
126
- uuid,
127
- success: true
128
- });
129
- tryGC();
130
- });
131
- },
132
- runTask: (msg) => {
133
- if (msg) {
134
- globalConfig = Object.assign(Object.assign({}, globalConfig), msg);
135
- }
136
- const { uuid, data } = globalConfig;
137
- if (data.action === 'dev') {
138
- handlers.runWatch({ uuid, data });
139
- }
140
- else {
141
- handlers.runBuild({ uuid, data });
142
- }
143
- },
144
- close() {
145
- var _a;
146
- console.log('close');
147
- (_a = projectCompiler === null || projectCompiler === void 0 ? void 0 : projectCompiler.close) === null || _a === void 0 ? void 0 : _a.call(projectCompiler, () => { });
148
- projectCompiler = null;
149
- }
150
- };
151
- process.on('message', (message) => {
152
- let objData = {};
153
- try {
154
- objData = JSON.parse(message);
155
- }
156
- catch (error) {
157
- // do something
158
- }
159
- const { uuid, method, data = {} } = objData;
160
- if (!handlers[method]) {
161
- return;
162
- }
163
- handlers[method](objData);
164
- });
165
- process.on('uncaughtException', error => {
166
- console.error(error);
167
- sendToMaster('emitCompileStats', {
168
- stats: {
169
- errors: [error.message]
170
- }
171
- });
172
- });
173
- process.on('disconnect', () => {
174
- process.exit(-1);
175
- });
@@ -1,7 +0,0 @@
1
- export declare const MAIN_PKG_ROOT = "xhs-main";
2
- export declare const COMPILER_TYPE: {
3
- dev: string;
4
- build: string;
5
- legacy_dev: string;
6
- legacy_build: string;
7
- };
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.COMPILER_TYPE = exports.MAIN_PKG_ROOT = void 0;
4
- exports.MAIN_PKG_ROOT = 'xhs-main';
5
- exports.COMPILER_TYPE = {
6
- 'dev': 'dev',
7
- 'build': 'build',
8
- 'legacy_dev': 'legacy_dev',
9
- 'legacy_build': 'legacy_build'
10
- };
@@ -1,3 +0,0 @@
1
- import { IPresetOptions } from '../types';
2
- declare const devServer: (config: IPresetOptions) => Promise<void>;
3
- export default devServer;
@@ -1,64 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const path_1 = __importDefault(require("path"));
16
- const webpack_1 = __importDefault(require("webpack"));
17
- const ensurePort_1 = __importDefault(require("./lib/ensurePort"));
18
- const openBrowser_1 = __importDefault(require("./lib/openBrowser"));
19
- const presets_1 = require("../presets");
20
- const devServer = (config) => __awaiter(void 0, void 0, void 0, function* () {
21
- const { packSetting } = config;
22
- const { devServerPort, distDir } = packSetting;
23
- const webpackConfigs = (0, presets_1.createConfigs)(config);
24
- const compiler = (0, webpack_1.default)(webpackConfigs);
25
- const host = 'localhost';
26
- const devServerConfig = {
27
- open: false,
28
- historyApiFallback: true,
29
- port: devServerPort || 1388,
30
- hot: false,
31
- static: [
32
- // emulator entry 地址
33
- path_1.default.resolve('node_modules/@xhs/mp-simulator/dist'),
34
- path_1.default.resolve('node_modules/@xhs/mp-js-core/dist'),
35
- ...JSON.parse(process.env.XHS_MP_LIB || '[]'), // 自定义地址
36
- distDir,
37
- ],
38
- client: {
39
- logging: 'error',
40
- overlay: false,
41
- progress: false,
42
- },
43
- // firewall: false,
44
- headers: {
45
- 'Access-Control-Allow-Origin': '*',
46
- },
47
- };
48
- // 检查端口是否被占用,若占用会修改 devServerConfig.port
49
- yield (0, ensurePort_1.default)(devServerConfig);
50
- const Server = require('webpack-dev-server');
51
- const server = new Server(compiler, Object.assign(Object.assign({}, devServerConfig), { open: false }));
52
- server.listen(devServerConfig.port, host, () => { });
53
- let isBrowserOpened = false;
54
- compiler.hooks.done.tap('xhs-mp-cli', stats => {
55
- if (stats.hasErrors()) {
56
- return;
57
- }
58
- if (devServerConfig.open && !isBrowserOpened) {
59
- isBrowserOpened = true;
60
- (0, openBrowser_1.default)(host, devServerConfig.port);
61
- }
62
- });
63
- });
64
- exports.default = devServer;
@@ -1,2 +0,0 @@
1
- declare const ensurePort: (devServerConfig: any) => Promise<unknown>;
2
- export default ensurePort;
@@ -1,32 +0,0 @@
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
- // @ts-nocheck
7
- const net_1 = __importDefault(require("net"));
8
- const ensurePort = (devServerConfig) => new Promise(res => {
9
- const checkPort = () => {
10
- const server = net_1.default.createServer().listen(devServerConfig.port, devServerConfig.client.host);
11
- server.on('listening', () => {
12
- server.close();
13
- res(1);
14
- });
15
- server.on('error', err => {
16
- if (err.code === 'EADDRINUSE') {
17
- devServerConfig.port += 1;
18
- checkPort(devServerConfig);
19
- }
20
- });
21
- };
22
- try {
23
- checkPort();
24
- }
25
- catch (err) {
26
- if (err.code === 'EADDRINUSE') {
27
- devServerConfig.port += 1;
28
- checkPort(devServerConfig);
29
- }
30
- }
31
- });
32
- exports.default = ensurePort;
@@ -1,2 +0,0 @@
1
- declare const openBrowser: (host: string, port: number) => true | undefined;
2
- export default openBrowser;
@@ -1,23 +0,0 @@
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 child_process_1 = require("child_process");
7
- const open_1 = __importDefault(require("open"));
8
- // eslint-disable-next-line consistent-return
9
- const openBrowser = (host, port) => {
10
- const url = `http://${host}:${port}`;
11
- try {
12
- (0, child_process_1.execSync)(`osascript ${__dirname}/openChrome.applescript ${encodeURI(url)}`, {
13
- stdio: 'ignore',
14
- });
15
- return true;
16
- }
17
- catch (error) {
18
- // Ignore errors.
19
- }
20
- // fallback to normal open
21
- (0, open_1.default)(url);
22
- };
23
- exports.default = openBrowser;
@@ -1,78 +0,0 @@
1
- property targetTab: null
2
- property targetTabIndex: -1
3
- property targetWindow: null
4
-
5
- on run argv
6
- set theURL to item 1 of argv
7
-
8
- with timeout of 2 seconds
9
- tell application "Chrome"
10
-
11
- if (count every window) = 0 then
12
- make new window
13
- end if
14
-
15
- -- 1: Looking for tab running debugger
16
- -- then, Reload debugging tab if found
17
- -- then return
18
- set found to my lookupTabWithUrl(theURL)
19
- if found then
20
- set targetWindow's active tab index to targetTabIndex
21
- tell targetTab to reload
22
- tell targetWindow to activate
23
- set index of targetWindow to 1
24
- return
25
- end if
26
-
27
- -- 2: Looking for Empty tab
28
- -- In case debugging tab was not found
29
- -- We try to find an empty tab instead
30
- set found to my lookupTabWithUrl("chrome://newtab/")
31
- if found then
32
- set targetWindow's active tab index to targetTabIndex
33
- set URL of targetTab to theURL
34
- tell targetWindow to activate
35
- return
36
- end if
37
-
38
- -- 3: Create new tab
39
- -- both debugging and empty tab were not found
40
- -- make a new tab with url
41
- tell window 1
42
- activate
43
- make new tab with properties {URL:theURL}
44
- end tell
45
- end tell
46
- end timeout
47
- end run
48
-
49
- -- Function:
50
- -- Lookup tab with given url
51
- -- if found, store tab, index, and window in properties
52
- -- (properties were declared on top of file)
53
- on lookupTabWithUrl(lookupUrl)
54
- tell application "Chrome"
55
- -- Find a tab with the given url
56
- set found to false
57
- set theTabIndex to -1
58
- repeat with theWindow in every window
59
- set theTabIndex to 0
60
- repeat with theTab in every tab of theWindow
61
- set theTabIndex to theTabIndex + 1
62
- if (theTab's URL as string) contains lookupUrl then
63
- -- assign tab, tab index, and window to properties
64
- set targetTab to theTab
65
- set targetTabIndex to theTabIndex
66
- set targetWindow to theWindow
67
- set found to true
68
- exit repeat
69
- end if
70
- end repeat
71
-
72
- if found then
73
- exit repeat
74
- end if
75
- end repeat
76
- end tell
77
- return found
78
- end lookupTabWithUrl
package/dist/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export { createCompiler } from './packs';
package/dist/index.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createCompiler = void 0;
4
- var packs_1 = require("./packs");
5
- Object.defineProperty(exports, "createCompiler", { enumerable: true, get: function () { return packs_1.createCompiler; } });
@@ -1,14 +0,0 @@
1
- import { Compilation, RawSource, CopyPatterns, Config, ConcatSource, MPPackSetting } from 'xhs-mp-pack';
2
- import { Configuration, WebpackError, library, LoaderContext } from 'webpack';
3
- import type { Project } from 'xhs-mp-project';
4
- import { IStart } from '../types';
5
- export type ICompilation = any;
6
- export type ICompiler = any;
7
- export type ILoaderContext = LoaderContext<any> & {
8
- _compiler: {
9
- project: Project;
10
- packSetting: MPPackSetting;
11
- };
12
- };
13
- export { Compilation, RawSource, ConcatSource, CopyPatterns, Config, Configuration, WebpackError, library, LoaderContext };
14
- export declare function createCompiler(startConfig: IStart): ICompiler;
@@ -1,31 +0,0 @@
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
- exports.createCompiler = exports.library = exports.WebpackError = exports.Config = exports.CopyPatterns = exports.ConcatSource = exports.RawSource = exports.Compilation = void 0;
7
- /**
8
- * 抹平差异:抹平webpack和mp-pack的差异
9
- * 统一收口,所有对webpack和mp-pack的调用都走这个出口,不可用直接调用
10
- */
11
- const webpack_1 = require("./webpack");
12
- const mp_pack_1 = require("./mp-pack");
13
- const xhs_mp_pack_1 = require("xhs-mp-pack");
14
- Object.defineProperty(exports, "Compilation", { enumerable: true, get: function () { return xhs_mp_pack_1.Compilation; } });
15
- Object.defineProperty(exports, "RawSource", { enumerable: true, get: function () { return xhs_mp_pack_1.RawSource; } });
16
- Object.defineProperty(exports, "CopyPatterns", { enumerable: true, get: function () { return xhs_mp_pack_1.CopyPatterns; } });
17
- Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return xhs_mp_pack_1.Config; } });
18
- Object.defineProperty(exports, "ConcatSource", { enumerable: true, get: function () { return xhs_mp_pack_1.ConcatSource; } });
19
- const webpack_2 = require("webpack");
20
- Object.defineProperty(exports, "WebpackError", { enumerable: true, get: function () { return webpack_2.WebpackError; } });
21
- Object.defineProperty(exports, "library", { enumerable: true, get: function () { return webpack_2.library; } });
22
- const const_1 = __importDefault(require("../utils/const"));
23
- const { PACK_MODE } = const_1.default;
24
- function createCompiler(startConfig) {
25
- const { packMode = PACK_MODE.MPPACK } = startConfig;
26
- if (packMode === PACK_MODE.WEBPACK) {
27
- return (0, webpack_1.createCompiler)(startConfig);
28
- }
29
- return (0, mp_pack_1.createCompiler)(startConfig);
30
- }
31
- exports.createCompiler = createCompiler;
@@ -1,3 +0,0 @@
1
- import { IStart } from '../../types';
2
- import { MPPack } from 'xhs-mp-pack';
3
- export declare const createCompiler: (startConfig: IStart) => Promise<void> | MPPack;
@@ -1,32 +0,0 @@
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
- exports.createCompiler = void 0;
7
- const presets_1 = require("../../presets");
8
- const path_1 = __importDefault(require("path"));
9
- const xhs_mp_pack_1 = require("xhs-mp-pack");
10
- const dev_server_1 = __importDefault(require("../../dev-server"));
11
- const createCompiler = (startConfig) => {
12
- const { action, enableDevServer } = startConfig;
13
- const mppack = new xhs_mp_pack_1.MPPack(startConfig);
14
- const compilerOptions = {
15
- project: mppack.project,
16
- packSetting: mppack.packSetting
17
- };
18
- const mpPackConfigs = (0, presets_1.createConfigs)(compilerOptions);
19
- mpPackConfigs.forEach(config => {
20
- var _a, _b, _c, _d;
21
- /* 修改在ide里的node_modules的路径 */
22
- (_b = (_a = config.resolve) === null || _a === void 0 ? void 0 : _a.modules) === null || _b === void 0 ? void 0 : _b.push(path_1.default.resolve(__dirname, '../../../'));
23
- // cli的node_modules路径
24
- (_d = (_c = config.resolve) === null || _c === void 0 ? void 0 : _c.modules) === null || _d === void 0 ? void 0 : _d.push(path_1.default.resolve(__dirname, '../../'));
25
- });
26
- if (action === 'dev' && enableDevServer) {
27
- return (0, dev_server_1.default)(compilerOptions);
28
- }
29
- mppack.createCompiler(mpPackConfigs);
30
- return mppack;
31
- };
32
- exports.createCompiler = createCompiler;
@@ -1,3 +0,0 @@
1
- import { IStart } from '../../types';
2
- import { WebPack } from './webpack';
3
- export declare const createCompiler: (startConfig: IStart) => WebPack | Promise<void>;
@@ -1,92 +0,0 @@
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
- exports.createCompiler = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const dev_server_1 = __importDefault(require("../../dev-server"));
10
- const projectConfig_1 = require("../../utils/projectConfig");
11
- const common_1 = require("../../utils/common");
12
- const types_1 = require("../../types");
13
- const presets_1 = require("../../presets");
14
- const xhs_mp_project_1 = require("xhs-mp-project");
15
- const xhs_mp_pack_1 = require("xhs-mp-pack");
16
- const webpack_1 = require("./webpack");
17
- // 防御编程
18
- const handleVersion = (startConfig) => {
19
- let { action, enableV1 = true, enableV2 = false, enableVDom = false } = startConfig;
20
- // 正式环境必须有v1 并且不允许并行编译
21
- if (action === 'build') {
22
- enableV1 = true;
23
- }
24
- if (!enableV1 && !enableV2) {
25
- enableV1 = true;
26
- enableV2 = false;
27
- }
28
- return {
29
- enableV1,
30
- enableV2,
31
- enableVDom
32
- };
33
- };
34
- const formatCompilerConfig = startConfig => {
35
- const { projectPath, action, tsConfigPath, platform, extJsonPath, compressJs = false, enableSourcemap = false } = startConfig;
36
- const { enableV1, enableV2, enableVDom } = handleVersion(startConfig);
37
- const distDir = startConfig.distDir || path_1.default.join(process.cwd(), 'dist');
38
- process.env.__platform = platform;
39
- try {
40
- if (fs_extra_1.default.existsSync(distDir)) {
41
- // eslint-disable-line
42
- fs_extra_1.default.rmSync(distDir, { recursive: true });
43
- }
44
- }
45
- catch (error) {
46
- // noop
47
- }
48
- const projectJson = (0, projectConfig_1.getProjectConfig)(projectPath);
49
- let miniprogramDir = path_1.default.join(projectPath, projectJson.miniprogramRoot || '');
50
- miniprogramDir = miniprogramDir.endsWith('/') ? miniprogramDir.slice(0, -1) : miniprogramDir;
51
- const config = {
52
- projectPath: (0, common_1.toUnixPath)(projectPath),
53
- miniprogramDir: (0, common_1.toUnixPath)(miniprogramDir).replace(/\/+$/, ''),
54
- extJsonPath,
55
- distDir,
56
- action,
57
- env: action === 'dev' ? types_1.ENV.development : types_1.ENV.production,
58
- tsConfigPath: tsConfigPath || (0, common_1.getTsConfigPath)(projectPath),
59
- cacheDirectory: startConfig.cacheDirectory,
60
- compressJs,
61
- enableSourcemap,
62
- enableV1,
63
- enableV2,
64
- enableVDom
65
- };
66
- return config;
67
- };
68
- const createCompiler = (startConfig) => {
69
- const { projectPath, action, enableDevServer, callback } = startConfig;
70
- startConfig = formatCompilerConfig(startConfig);
71
- const project = new xhs_mp_project_1.Project({
72
- projectPath,
73
- });
74
- const mppackSetting = new xhs_mp_pack_1.MPPackSetting(project, startConfig);
75
- const compilerOptions = {
76
- project: project,
77
- packSetting: mppackSetting
78
- };
79
- const webpackConfig = (0, presets_1.createConfigs)(compilerOptions);
80
- webpackConfig.forEach(config => {
81
- var _a, _b, _c, _d;
82
- /* 修改在ide里的node_modules的路径 */
83
- (_b = (_a = config.resolve) === null || _a === void 0 ? void 0 : _a.modules) === null || _b === void 0 ? void 0 : _b.push(path_1.default.resolve(__dirname, '../../../../'));
84
- // cli的node_modules路径
85
- (_d = (_c = config.resolve) === null || _c === void 0 ? void 0 : _c.modules) === null || _d === void 0 ? void 0 : _d.push(path_1.default.resolve(__dirname, '../../../'));
86
- });
87
- if (action === 'dev' && enableDevServer) {
88
- return (0, dev_server_1.default)(compilerOptions);
89
- }
90
- return new webpack_1.WebPack(webpackConfig, compilerOptions);
91
- };
92
- exports.createCompiler = createCompiler;
@@ -1,21 +0,0 @@
1
- import { AbstractMPPack, MPPackSetting } from 'xhs-mp-pack';
2
- import { Watching } from 'webpack';
3
- import { IPresetOptions } from '../../types';
4
- import { Project } from 'xhs-mp-project';
5
- export declare class WebPack extends AbstractMPPack {
6
- callbacks: any[];
7
- compiler: any;
8
- watcher: Watching | null;
9
- project: Project;
10
- packSetting: MPPackSetting;
11
- hadWatch: boolean;
12
- constructor(configs: any, options: IPresetOptions);
13
- handleProgress: (progress: any) => void;
14
- get hooks(): any;
15
- watch(config: any, callback?: any): Promise<unknown>;
16
- changeCompileOptions(config: any): void;
17
- activatePkgs(compilePkgs: any): void;
18
- reCompilePkgs(config: any, callback?: any): Promise<void>;
19
- build(callback?: any): void;
20
- close(callback: any): void;
21
- }