xhs-mp-compiler-cli 2.0.0-beta.4 → 2.0.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/dist/bin/xhs-mp-cli-build.js +48 -34
- package/dist/bin/xhs-mp-cli-dev.js +44 -44
- package/dist/bin/xhs-mp-cli.js +22 -12
- package/dist/compiler.d.ts +21 -28
- package/dist/compiler.js +327 -327
- package/dist/compilerImpl.d.ts +19 -0
- package/dist/compilerImpl.js +173 -0
- package/dist/config/constant.config.d.ts +24 -0
- package/dist/config/constant.config.js +82 -30
- package/dist/config/dir.config.js +23 -13
- package/dist/index.d.ts +9 -9
- package/dist/index.js +454 -408
- package/dist/packs/index.d.ts +4 -4
- package/dist/packs/index.js +38 -30
- package/dist/packs/mp-pack/index.js +38 -30
- package/dist/packs/webpack/dev-server/index.js +61 -50
- package/dist/packs/webpack/dev-server/lib/ensurePort.js +33 -23
- package/dist/packs/webpack/dev-server/lib/openBrowser.js +28 -18
- package/dist/packs/webpack/index.d.ts +1 -1
- package/dist/packs/webpack/index.js +99 -90
- package/dist/packs/webpack/webpack.d.ts +2 -1
- package/dist/packs/webpack/webpack.js +81 -63
- package/dist/presets/babel.d.ts +0 -1
- package/dist/presets/babel.js +64 -58
- package/dist/presets/common.js +42 -45
- package/dist/presets/configs/minigame/assets/assetsEntryPlugin.js +50 -40
- package/dist/presets/configs/minigame/assets/index.js +62 -52
- package/dist/presets/configs/minigame/service/index.js +49 -30
- package/dist/presets/configs/minigame/service/resolveLimitPlugin.js +33 -23
- package/dist/presets/configs/minigame/service/serviceChunkPlugin.d.ts +2 -2
- package/dist/presets/configs/minigame/service/serviceChunkPlugin.js +69 -60
- package/dist/presets/configs/minigame/service/serviceEntryPlugin.d.ts +3 -3
- package/dist/presets/configs/minigame/service/serviceEntryPlugin.js +39 -29
- package/dist/presets/configs/miniprogram/assets/assetsEntryPlugin.js +120 -113
- package/dist/presets/configs/miniprogram/assets/index.js +45 -43
- package/dist/presets/configs/miniprogram/render/component.js +51 -41
- package/dist/presets/configs/miniprogram/render/index.d.ts +2 -3
- package/dist/presets/configs/miniprogram/render/index.js +85 -68
- package/dist/presets/configs/miniprogram/render/render.js +53 -43
- package/dist/presets/configs/miniprogram/render/renderChunkPlugin.js +84 -49
- package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.d.ts +15 -0
- package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.js +164 -126
- package/dist/presets/configs/miniprogram/service/index.js +82 -65
- package/dist/presets/configs/miniprogram/service/resolveLimitPlugin.js +60 -50
- package/dist/presets/configs/miniprogram/service/serviceChunkPlugin.js +93 -55
- package/dist/presets/index.js +100 -90
- package/dist/presets/loaders/mg-entry-loader.js +32 -22
- package/dist/presets/loaders/mini-style-loader.js +79 -55
- package/dist/presets/loaders/mp-entry-loader.js +149 -140
- package/dist/presets/loaders/wxss-loader.js +73 -63
- package/dist/presets/plugins/InjectorPlugin.js +23 -13
- package/dist/presets/plugins/SourceMapDevToolPlugin.d.ts +1 -0
- package/dist/presets/plugins/SourceMapDevToolPlugin.js +23 -0
- package/dist/presets/prod.js +88 -78
- package/dist/sharedFs.d.ts +2 -0
- package/dist/sharedFs.js +24 -0
- package/dist/types/index.d.ts +11 -37
- package/dist/types/index.js +23 -13
- package/dist/utils/{apm/index.d.ts → apm.d.ts} +5 -3
- package/dist/utils/apm.js +245 -0
- package/dist/utils/cache.d.ts +28 -0
- package/dist/utils/cache.js +49 -0
- package/dist/utils/common.js +42 -32
- package/dist/utils/css.d.ts +1 -1
- package/dist/utils/css.js +43 -35
- package/dist/utils/depenedHelper.js +95 -85
- package/dist/utils/file.js +39 -29
- package/dist/utils/loader-utils.js +63 -53
- package/dist/utils/postcssRpx2Vw.js +43 -33
- package/dist/utils/project.d.ts +3 -2
- package/dist/utils/project.js +129 -119
- package/dist/utils/projectConfig.js +24 -15
- package/dist/utils/utils.js +51 -42
- package/dist/utils/workerPool.d.ts +29 -0
- package/dist/utils/workerPool.js +125 -0
- package/dist/utils/zip.js +239 -229
- package/package.json +33 -14
- package/dist/compilerCP.d.ts +0 -1
- package/dist/compilerCP.js +0 -175
- package/dist/presets/loaders/sjs-loader/index.d.ts +0 -12
- package/dist/presets/loaders/sjs-loader/index.js +0 -605
- package/dist/presets/loaders/sjs-loader/scope.d.ts +0 -36
- package/dist/presets/loaders/sjs-loader/scope.js +0 -122
- package/dist/presets/loaders/sjs-loader/tranform.d.ts +0 -2
- package/dist/presets/loaders/sjs-loader/tranform.js +0 -31
- package/dist/utils/apm/index.js +0 -198
- package/dist/utils/asyncWebpack.d.ts +0 -3
- package/dist/utils/asyncWebpack.js +0 -38
- package/dist/utils/const.d.ts +0 -27
- package/dist/utils/const.js +0 -47
- package/dist/utils/getSuffixName.d.ts +0 -3
- package/dist/utils/getSuffixName.js +0 -18
- package/dist/utils/tagTransformMap.d.ts +0 -36
- package/dist/utils/tagTransformMap.js +0 -39
package/dist/packs/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Compilation, RawSource, CopyPatterns, Config, ConcatSource, MPPackSetting } from 'xhs-mp-pack';
|
|
2
|
-
import { Configuration, WebpackError, library, LoaderContext } from 'webpack';
|
|
2
|
+
import { Configuration, WebpackError, library, LoaderContext, EntryOptionPlugin, EntryPlugin } from 'webpack';
|
|
3
3
|
import type { Project } from 'xhs-mp-project';
|
|
4
4
|
import { IStart } from '../types';
|
|
5
|
-
import { FeatureReporter } from 'xhs-mp-
|
|
5
|
+
import { FeatureReporter } from 'xhs-mp-shared';
|
|
6
6
|
export type ICompilation = any;
|
|
7
7
|
export type ICompiler = any;
|
|
8
8
|
export type ILoaderContext = LoaderContext<any> & {
|
|
@@ -12,5 +12,5 @@ export type ILoaderContext = LoaderContext<any> & {
|
|
|
12
12
|
reporter: FeatureReporter.IReporter;
|
|
13
13
|
};
|
|
14
14
|
};
|
|
15
|
-
export { Compilation, RawSource, ConcatSource, CopyPatterns, Config, Configuration, WebpackError, library, LoaderContext };
|
|
16
|
-
export declare function
|
|
15
|
+
export { Compilation, RawSource, ConcatSource, CopyPatterns, Config, Configuration, WebpackError, library, LoaderContext, EntryOptionPlugin, EntryPlugin };
|
|
16
|
+
export declare function createPacker(startConfig: IStart): ICompiler;
|
package/dist/packs/index.js
CHANGED
|
@@ -1,31 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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);
|
|
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;
|
|
28
5
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "./webpack", "./mp-pack", "xhs-mp-pack", "webpack", "../config/constant.config"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.EntryPlugin = exports.EntryOptionPlugin = exports.library = exports.WebpackError = exports.Config = exports.CopyPatterns = exports.ConcatSource = exports.RawSource = exports.Compilation = void 0;
|
|
13
|
+
exports.createPacker = createPacker;
|
|
14
|
+
/**
|
|
15
|
+
* 抹平差异:抹平webpack和mp-pack的差异
|
|
16
|
+
* 统一收口,所有对webpack和mp-pack的调用都走这个出口,不可用直接调用
|
|
17
|
+
*/
|
|
18
|
+
const webpack_1 = require("./webpack");
|
|
19
|
+
const mp_pack_1 = require("./mp-pack");
|
|
20
|
+
const xhs_mp_pack_1 = require("xhs-mp-pack");
|
|
21
|
+
Object.defineProperty(exports, "Compilation", { enumerable: true, get: function () { return xhs_mp_pack_1.Compilation; } });
|
|
22
|
+
Object.defineProperty(exports, "RawSource", { enumerable: true, get: function () { return xhs_mp_pack_1.RawSource; } });
|
|
23
|
+
Object.defineProperty(exports, "CopyPatterns", { enumerable: true, get: function () { return xhs_mp_pack_1.CopyPatterns; } });
|
|
24
|
+
Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return xhs_mp_pack_1.Config; } });
|
|
25
|
+
Object.defineProperty(exports, "ConcatSource", { enumerable: true, get: function () { return xhs_mp_pack_1.ConcatSource; } });
|
|
26
|
+
const webpack_2 = require("webpack");
|
|
27
|
+
Object.defineProperty(exports, "WebpackError", { enumerable: true, get: function () { return webpack_2.WebpackError; } });
|
|
28
|
+
Object.defineProperty(exports, "library", { enumerable: true, get: function () { return webpack_2.library; } });
|
|
29
|
+
Object.defineProperty(exports, "EntryOptionPlugin", { enumerable: true, get: function () { return webpack_2.EntryOptionPlugin; } });
|
|
30
|
+
Object.defineProperty(exports, "EntryPlugin", { enumerable: true, get: function () { return webpack_2.EntryPlugin; } });
|
|
31
|
+
const constant_config_1 = require("../config/constant.config");
|
|
32
|
+
function createPacker(startConfig) {
|
|
33
|
+
const { packMode = constant_config_1.PACK_MODE.MPPACK } = startConfig;
|
|
34
|
+
if (packMode === constant_config_1.PACK_MODE.WEBPACK) {
|
|
35
|
+
return (0, webpack_1.createPacker)(startConfig);
|
|
36
|
+
}
|
|
37
|
+
return (0, mp_pack_1.createCompiler)(startConfig);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
@@ -1,34 +1,42 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
2
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
3
|
};
|
|
5
|
-
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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", "../../presets", "path", "xhs-mp-pack", "../../utils/apm", "../../config/constant.config"], factory);
|
|
11
|
+
}
|
|
12
|
+
})(function (require, exports) {
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.createCompiler = void 0;
|
|
16
|
+
const presets_1 = require("../../presets");
|
|
17
|
+
const path_1 = __importDefault(require("path"));
|
|
18
|
+
const xhs_mp_pack_1 = require("xhs-mp-pack");
|
|
19
|
+
const apm_1 = require("../../utils/apm");
|
|
20
|
+
const constant_config_1 = require("../../config/constant.config");
|
|
21
|
+
const createCompiler = (startConfig) => {
|
|
22
|
+
const mppack = new xhs_mp_pack_1.MPPack(startConfig);
|
|
23
|
+
const compilerOptions = {
|
|
24
|
+
project: mppack.project,
|
|
25
|
+
packSetting: mppack.packSetting,
|
|
26
|
+
packMode: constant_config_1.PACK_MODE.MPPACK,
|
|
27
|
+
// 注入apm模块
|
|
28
|
+
reporter: (0, apm_1.createReporter)(mppack.project, startConfig.mpUploadOptions)
|
|
29
|
+
};
|
|
30
|
+
const mpPackConfigs = (0, presets_1.createConfigs)(compilerOptions);
|
|
31
|
+
mpPackConfigs.forEach(config => {
|
|
32
|
+
var _a, _b, _c, _d;
|
|
33
|
+
/* 修改在ide里的node_modules的路径 */
|
|
34
|
+
(_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, '../../../../'));
|
|
35
|
+
// cli的node_modules路径
|
|
36
|
+
(_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, '../../'));
|
|
37
|
+
});
|
|
38
|
+
mppack.createCompiler(mpPackConfigs);
|
|
39
|
+
return mppack;
|
|
22
40
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
var _a, _b, _c, _d;
|
|
26
|
-
/* 修改在ide里的node_modules的路径 */
|
|
27
|
-
(_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, '../../../../'));
|
|
28
|
-
// cli的node_modules路径
|
|
29
|
-
(_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, '../../'));
|
|
30
|
-
});
|
|
31
|
-
mppack.createCompiler(mpPackConfigs);
|
|
32
|
-
return mppack;
|
|
33
|
-
};
|
|
34
|
-
exports.createCompiler = createCompiler;
|
|
41
|
+
exports.createCompiler = createCompiler;
|
|
42
|
+
});
|
|
@@ -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,54 +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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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", "./lib/ensurePort", "./lib/openBrowser", "../../../presets"], factory);
|
|
20
|
+
}
|
|
21
|
+
})(function (require, exports) {
|
|
22
|
+
"use strict";
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
const path_1 = __importDefault(require("path"));
|
|
25
|
+
const ensurePort_1 = __importDefault(require("./lib/ensurePort"));
|
|
26
|
+
const openBrowser_1 = __importDefault(require("./lib/openBrowser"));
|
|
27
|
+
const presets_1 = require("../../../presets");
|
|
28
|
+
const devServer = (config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
+
const { packSetting } = config;
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
const { distDir } = packSetting;
|
|
32
|
+
const webpackConfigs = (0, presets_1.createConfigs)(config);
|
|
33
|
+
const webpack = require('webpack');
|
|
34
|
+
const compiler = webpack(webpackConfigs);
|
|
35
|
+
const host = 'localhost';
|
|
36
|
+
const devServerConfig = {
|
|
37
|
+
open: false,
|
|
38
|
+
historyApiFallback: true,
|
|
39
|
+
port: 1388,
|
|
40
|
+
hot: false,
|
|
41
|
+
static: [
|
|
42
|
+
// emulator entry 地址
|
|
43
|
+
path_1.default.resolve('node_modules/@xhs/mp-simulator/dist'),
|
|
44
|
+
path_1.default.resolve('node_modules/@xhs/mp-js-core/dist'),
|
|
45
|
+
...JSON.parse(process.env.XHS_MP_LIB || '[]'), // 自定义地址
|
|
46
|
+
distDir,
|
|
47
|
+
],
|
|
48
|
+
client: {
|
|
49
|
+
logging: 'error',
|
|
50
|
+
overlay: false,
|
|
51
|
+
progress: false,
|
|
52
|
+
},
|
|
53
|
+
// firewall: false,
|
|
54
|
+
headers: {
|
|
55
|
+
'Access-Control-Allow-Origin': '*',
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
// 检查端口是否被占用,若占用会修改 devServerConfig.port
|
|
59
|
+
yield (0, ensurePort_1.default)(devServerConfig);
|
|
60
|
+
const Server = require('webpack-dev-server');
|
|
61
|
+
const server = new Server(compiler, Object.assign(Object.assign({}, devServerConfig), { open: false }));
|
|
62
|
+
server.listen(devServerConfig.port, host, () => { });
|
|
63
|
+
let isBrowserOpened = false;
|
|
64
|
+
compiler.hooks.done.tap('xhs-mp-cli', stats => {
|
|
65
|
+
if (stats.hasErrors()) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (devServerConfig.open && !isBrowserOpened) {
|
|
69
|
+
isBrowserOpened = true;
|
|
70
|
+
(0, openBrowser_1.default)(host, devServerConfig.port);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
62
73
|
});
|
|
74
|
+
exports.default = devServer;
|
|
63
75
|
});
|
|
64
|
-
exports.default = devServer;
|
|
@@ -1,32 +1,42 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
2
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
3
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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", "net"], factory);
|
|
11
|
+
}
|
|
12
|
+
})(function (require, exports) {
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
// @ts-nocheck
|
|
16
|
+
const net_1 = __importDefault(require("net"));
|
|
17
|
+
const ensurePort = (devServerConfig) => new Promise(res => {
|
|
18
|
+
const checkPort = () => {
|
|
19
|
+
const server = net_1.default.createServer().listen(devServerConfig.port, devServerConfig.client.host);
|
|
20
|
+
server.on('listening', () => {
|
|
21
|
+
server.close();
|
|
22
|
+
res(1);
|
|
23
|
+
});
|
|
24
|
+
server.on('error', err => {
|
|
25
|
+
if (err.code === 'EADDRINUSE') {
|
|
26
|
+
devServerConfig.port += 1;
|
|
27
|
+
checkPort(devServerConfig);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
try {
|
|
32
|
+
checkPort();
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
16
35
|
if (err.code === 'EADDRINUSE') {
|
|
17
36
|
devServerConfig.port += 1;
|
|
18
37
|
checkPort(devServerConfig);
|
|
19
38
|
}
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
try {
|
|
23
|
-
checkPort();
|
|
24
|
-
}
|
|
25
|
-
catch (err) {
|
|
26
|
-
if (err.code === 'EADDRINUSE') {
|
|
27
|
-
devServerConfig.port += 1;
|
|
28
|
-
checkPort(devServerConfig);
|
|
29
39
|
}
|
|
30
|
-
}
|
|
40
|
+
});
|
|
41
|
+
exports.default = ensurePort;
|
|
31
42
|
});
|
|
32
|
-
exports.default = ensurePort;
|
|
@@ -1,23 +1,33 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
2
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
3
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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;
|
|
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;
|
|
16
8
|
}
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
else if (typeof define === "function" && define.amd) {
|
|
10
|
+
define(["require", "exports", "child_process", "open"], factory);
|
|
19
11
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
23
|
-
|
|
12
|
+
})(function (require, exports) {
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const child_process_1 = require("child_process");
|
|
16
|
+
const open_1 = __importDefault(require("open"));
|
|
17
|
+
// eslint-disable-next-line consistent-return
|
|
18
|
+
const openBrowser = (host, port) => {
|
|
19
|
+
const url = `http://${host}:${port}`;
|
|
20
|
+
try {
|
|
21
|
+
(0, child_process_1.execSync)(`osascript ${__dirname}/openChrome.applescript ${encodeURI(url)}`, {
|
|
22
|
+
stdio: 'ignore',
|
|
23
|
+
});
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
// Ignore errors.
|
|
28
|
+
}
|
|
29
|
+
// fallback to normal open
|
|
30
|
+
(0, open_1.default)(url);
|
|
31
|
+
};
|
|
32
|
+
exports.default = openBrowser;
|
|
33
|
+
});
|
|
@@ -1,99 +1,108 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
2
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
3
|
};
|
|
5
|
-
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
const apm_1 = require("../../utils/apm");
|
|
18
|
-
const const_1 = __importDefault(require("../../utils/const"));
|
|
19
|
-
const { PACK_MODE } = const_1.default;
|
|
20
|
-
// 防御编程
|
|
21
|
-
const handleVersion = (startConfig) => {
|
|
22
|
-
let { action, enableV1 = true, enableV2 = false, enableVDom = false } = startConfig;
|
|
23
|
-
// 正式环境必须有v1 并且不允许并行编译
|
|
24
|
-
if (action === 'build') {
|
|
25
|
-
enableV1 = true;
|
|
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;
|
|
26
8
|
}
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
enableV2 = false;
|
|
9
|
+
else if (typeof define === "function" && define.amd) {
|
|
10
|
+
define(["require", "exports", "path", "fs-extra", "../../utils/projectConfig", "../../utils/common", "../../presets", "xhs-mp-project", "xhs-mp-pack", "./webpack", "../../utils/apm", "../../config/constant.config"], factory);
|
|
30
11
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
12
|
+
})(function (require, exports) {
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.createPacker = void 0;
|
|
16
|
+
const path_1 = __importDefault(require("path"));
|
|
17
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
18
|
+
const projectConfig_1 = require("../../utils/projectConfig");
|
|
19
|
+
const common_1 = require("../../utils/common");
|
|
20
|
+
const presets_1 = require("../../presets");
|
|
21
|
+
const xhs_mp_project_1 = require("xhs-mp-project");
|
|
22
|
+
const xhs_mp_pack_1 = require("xhs-mp-pack");
|
|
23
|
+
const webpack_1 = require("./webpack");
|
|
24
|
+
const apm_1 = require("../../utils/apm");
|
|
25
|
+
const constant_config_1 = require("../../config/constant.config");
|
|
26
|
+
// 防御编程
|
|
27
|
+
const handleVersion = (startConfig) => {
|
|
28
|
+
let { action, enableV1 = true, enableV2 = false, enableVDom = false } = startConfig;
|
|
29
|
+
// 正式环境必须有v1 并且不允许并行编译
|
|
30
|
+
if (action === 'build') {
|
|
31
|
+
enableV1 = true;
|
|
32
|
+
}
|
|
33
|
+
if (!enableV1 && !enableV2) {
|
|
34
|
+
enableV1 = true;
|
|
35
|
+
enableV2 = false;
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
enableV1,
|
|
39
|
+
enableV2,
|
|
40
|
+
enableVDom
|
|
41
|
+
};
|
|
35
42
|
};
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
const formatCompilerConfig = startConfig => {
|
|
44
|
+
const { projectPath, action, tsConfigPath, platform, compressCss = true, compressJs = true, enableSourcemap = true, appendSourcemapComment = true, runInServiceSandbox = false, mpUploadOptions = false } = startConfig;
|
|
45
|
+
const { enableV1, enableV2, enableVDom } = handleVersion(startConfig);
|
|
46
|
+
const distDir = startConfig.distDir || path_1.default.join(process.cwd(), 'dist');
|
|
47
|
+
process.env.__platform = platform;
|
|
48
|
+
try {
|
|
49
|
+
if (fs_extra_1.default.existsSync(distDir)) {
|
|
50
|
+
// eslint-disable-line
|
|
51
|
+
fs_extra_1.default.rmSync(distDir, { recursive: true });
|
|
52
|
+
}
|
|
46
53
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
54
|
+
catch (error) {
|
|
55
|
+
// noop
|
|
56
|
+
}
|
|
57
|
+
const projectJson = (0, projectConfig_1.getProjectConfig)(projectPath);
|
|
58
|
+
let miniprogramDir = path_1.default.join(projectPath, projectJson.miniprogramRoot || '');
|
|
59
|
+
miniprogramDir = miniprogramDir.endsWith('/') ? miniprogramDir.slice(0, -1) : miniprogramDir;
|
|
60
|
+
const config = {
|
|
61
|
+
projectPath: (0, common_1.toUnixPath)(projectPath),
|
|
62
|
+
miniprogramDir: (0, common_1.toUnixPath)(miniprogramDir).replace(/\/+$/, ''),
|
|
63
|
+
distDir,
|
|
64
|
+
action,
|
|
65
|
+
tsConfigPath: tsConfigPath || (0, common_1.getTsConfigPath)(projectPath),
|
|
66
|
+
cacheDirectory: startConfig.cacheDirectory,
|
|
67
|
+
compressCss,
|
|
68
|
+
compressJs,
|
|
69
|
+
enableSourcemap,
|
|
70
|
+
appendSourcemapComment,
|
|
71
|
+
runInServiceSandbox,
|
|
72
|
+
enableV1,
|
|
73
|
+
enableV2,
|
|
74
|
+
enableVDom,
|
|
75
|
+
mpUploadOptions,
|
|
76
|
+
};
|
|
77
|
+
return config;
|
|
69
78
|
};
|
|
70
|
-
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
const createPacker = (startConfig) => {
|
|
80
|
+
const { projectPath } = startConfig;
|
|
81
|
+
startConfig = formatCompilerConfig(startConfig);
|
|
82
|
+
const project = new xhs_mp_project_1.Project({
|
|
83
|
+
projectPath,
|
|
84
|
+
});
|
|
85
|
+
const mppackSetting = new xhs_mp_pack_1.MPPackSetting(project, startConfig);
|
|
86
|
+
const compilerOptions = {
|
|
87
|
+
project: project,
|
|
88
|
+
packSetting: mppackSetting,
|
|
89
|
+
packMode: constant_config_1.PACK_MODE.WEBPACK,
|
|
90
|
+
// 注入apm模块
|
|
91
|
+
reporter: (0, apm_1.createReporter)(project, startConfig.mpUploadOptions)
|
|
92
|
+
};
|
|
93
|
+
const webpackConfig = (0, presets_1.createConfigs)(compilerOptions);
|
|
94
|
+
webpackConfig.forEach(config => {
|
|
95
|
+
var _a, _b, _c, _d;
|
|
96
|
+
/* 修改在ide里的node_modules的路径 */
|
|
97
|
+
(_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, '../../../../'));
|
|
98
|
+
// cli的node_modules路径
|
|
99
|
+
(_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, '../../../'));
|
|
100
|
+
});
|
|
101
|
+
// if (action === 'dev' && enableDevServer) {
|
|
102
|
+
// const webpackDevServer = require('./dev-server').default
|
|
103
|
+
// return webpackDevServer(compilerOptions)
|
|
104
|
+
// }
|
|
105
|
+
return new webpack_1.WebPack(webpackConfig, compilerOptions);
|
|
85
106
|
};
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
var _a, _b, _c, _d;
|
|
89
|
-
/* 修改在ide里的node_modules的路径 */
|
|
90
|
-
(_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, '../../../../'));
|
|
91
|
-
// cli的node_modules路径
|
|
92
|
-
(_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, '../../../'));
|
|
93
|
-
});
|
|
94
|
-
if (action === 'dev' && enableDevServer) {
|
|
95
|
-
return (0, dev_server_1.default)(compilerOptions);
|
|
96
|
-
}
|
|
97
|
-
return new webpack_1.WebPack(webpackConfig, compilerOptions);
|
|
98
|
-
};
|
|
99
|
-
exports.createCompiler = createCompiler;
|
|
107
|
+
exports.createPacker = createPacker;
|
|
108
|
+
});
|
|
@@ -10,7 +10,8 @@ export declare class WebPack extends AbstractMPPack {
|
|
|
10
10
|
packSetting: MPPackSetting;
|
|
11
11
|
hadWatch: boolean;
|
|
12
12
|
constructor(configs: any, options: IPresetOptions);
|
|
13
|
-
handleProgress: (
|
|
13
|
+
handleProgress: (percentage: any, status: any, info: any) => void;
|
|
14
|
+
handleBuildInfo: (info: any) => void;
|
|
14
15
|
get hooks(): any;
|
|
15
16
|
watch(config: any, callback?: any): Promise<unknown>;
|
|
16
17
|
changeCompileOptions(config: any): void;
|