xhs-mp-compiler-cli 1.1.3 → 1.1.4
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.d.ts +2 -0
- package/dist/bin/xhs-mp-cli-build.js +40 -0
- package/dist/bin/xhs-mp-cli-dev.d.ts +2 -0
- package/dist/bin/xhs-mp-cli-dev.js +59 -0
- package/dist/bin/xhs-mp-cli.d.ts +2 -0
- package/dist/bin/xhs-mp-cli.js +16 -0
- package/dist/compiler.d.ts +76 -0
- package/dist/compiler.js +361 -0
- package/dist/compilerCP.d.ts +1 -0
- package/dist/compilerCP.js +175 -0
- package/dist/config/constant.config.d.ts +27 -0
- package/dist/config/constant.config.js +30 -0
- package/dist/config/dir.config.d.ts +3 -0
- package/dist/config/dir.config.js +16 -0
- package/dist/index.d.ts +84 -0
- package/dist/index.js +454 -0
- package/dist/packs/index.d.ts +14 -0
- package/dist/packs/index.js +31 -0
- package/dist/packs/mp-pack/index.d.ts +3 -0
- package/dist/packs/mp-pack/index.js +32 -0
- package/dist/packs/webpack/dev-server/index.d.ts +3 -0
- package/dist/packs/webpack/dev-server/index.js +64 -0
- package/dist/packs/webpack/dev-server/lib/ensurePort.d.ts +2 -0
- package/dist/packs/webpack/dev-server/lib/ensurePort.js +32 -0
- package/dist/packs/webpack/dev-server/lib/openBrowser.d.ts +2 -0
- package/dist/packs/webpack/dev-server/lib/openBrowser.js +23 -0
- package/dist/packs/webpack/dev-server/lib/openChrome.applescript +78 -0
- package/dist/packs/webpack/index.d.ts +3 -0
- package/dist/packs/webpack/index.js +92 -0
- package/dist/packs/webpack/webpack.d.ts +21 -0
- package/dist/packs/webpack/webpack.js +79 -0
- package/dist/presets/babel.d.ts +8 -0
- package/dist/presets/babel.js +59 -0
- package/dist/presets/common.d.ts +4 -0
- package/dist/presets/common.js +48 -0
- package/dist/presets/configs/minigame/assets/assetsEntryPlugin.d.ts +10 -0
- package/dist/presets/configs/minigame/assets/assetsEntryPlugin.js +46 -0
- package/dist/presets/configs/minigame/assets/index.d.ts +3 -0
- package/dist/presets/configs/minigame/assets/index.js +65 -0
- package/dist/presets/configs/minigame/service/index.d.ts +3 -0
- package/dist/presets/configs/minigame/service/index.js +34 -0
- package/dist/presets/configs/minigame/service/resolveLimitPlugin.d.ts +8 -0
- package/dist/presets/configs/minigame/service/resolveLimitPlugin.js +35 -0
- package/dist/presets/configs/minigame/service/serviceChunkPlugin.d.ts +9 -0
- package/dist/presets/configs/minigame/service/serviceChunkPlugin.js +69 -0
- package/dist/presets/configs/minigame/service/serviceEntryPlugin.d.ts +10 -0
- package/dist/presets/configs/minigame/service/serviceEntryPlugin.js +32 -0
- package/dist/presets/configs/miniprogram/assets/assetsEntryPlugin.d.ts +12 -0
- package/dist/presets/configs/miniprogram/assets/assetsEntryPlugin.js +132 -0
- package/dist/presets/configs/miniprogram/assets/index.d.ts +4 -0
- package/dist/presets/configs/miniprogram/assets/index.js +47 -0
- package/dist/presets/configs/miniprogram/render/component.d.ts +3 -0
- package/dist/presets/configs/miniprogram/render/component.js +47 -0
- package/dist/presets/configs/miniprogram/render/index.d.ts +5 -0
- package/dist/presets/configs/miniprogram/render/index.js +71 -0
- package/dist/presets/configs/miniprogram/render/render.d.ts +3 -0
- package/dist/presets/configs/miniprogram/render/render.js +49 -0
- package/dist/presets/configs/miniprogram/render/renderChunkPlugin.d.ts +8 -0
- package/dist/presets/configs/miniprogram/render/renderChunkPlugin.js +55 -0
- package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.d.ts +15 -0
- package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.js +163 -0
- package/dist/presets/configs/miniprogram/service/index.d.ts +5 -0
- package/dist/presets/configs/miniprogram/service/index.js +72 -0
- package/dist/presets/configs/miniprogram/service/resolveLimitPlugin.d.ts +8 -0
- package/dist/presets/configs/miniprogram/service/resolveLimitPlugin.js +66 -0
- package/dist/presets/configs/miniprogram/service/serviceChunkPlugin.d.ts +9 -0
- package/dist/presets/configs/miniprogram/service/serviceChunkPlugin.js +65 -0
- package/dist/presets/index.d.ts +2 -0
- package/dist/presets/index.js +95 -0
- package/dist/presets/loaders/mg-entry-loader.d.ts +1 -0
- package/dist/presets/loaders/mg-entry-loader.js +27 -0
- package/dist/presets/loaders/mini-style-loader.d.ts +1 -0
- package/dist/presets/loaders/mini-style-loader.js +72 -0
- package/dist/presets/loaders/mp-entry-loader.d.ts +1 -0
- package/dist/presets/loaders/mp-entry-loader.js +196 -0
- package/dist/presets/loaders/sjs-loader/index.d.ts +12 -0
- package/dist/presets/loaders/sjs-loader/index.js +605 -0
- package/dist/presets/loaders/sjs-loader/scope.d.ts +36 -0
- package/dist/presets/loaders/sjs-loader/scope.js +122 -0
- package/dist/presets/loaders/sjs-loader/tranform.d.ts +2 -0
- package/dist/presets/loaders/sjs-loader/tranform.js +31 -0
- package/dist/presets/loaders/wxss-loader.d.ts +1 -0
- package/dist/presets/loaders/wxss-loader.js +77 -0
- package/dist/presets/plugins/InjectorPlugin.d.ts +7 -0
- package/dist/presets/plugins/InjectorPlugin.js +14 -0
- package/dist/presets/prod.d.ts +4 -0
- package/dist/presets/prod.js +80 -0
- package/dist/types/index.d.ts +118 -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/common.d.ts +8 -0
- package/dist/utils/common.js +36 -0
- package/dist/utils/const.d.ts +27 -0
- package/dist/utils/const.js +47 -0
- package/dist/utils/css.d.ts +2 -0
- package/dist/utils/css.js +41 -0
- package/dist/utils/depenedHelper.d.ts +31 -0
- package/dist/utils/depenedHelper.js +89 -0
- package/dist/utils/file.d.ts +2 -0
- package/dist/utils/file.js +67 -0
- package/dist/utils/getSuffixName.d.ts +3 -0
- package/dist/utils/getSuffixName.js +18 -0
- package/dist/utils/loader-utils.d.ts +15 -0
- package/dist/utils/loader-utils.js +59 -0
- package/dist/utils/postcssRpx2Vw.d.ts +12 -0
- package/dist/utils/postcssRpx2Vw.js +35 -0
- package/dist/utils/project.d.ts +27 -0
- package/dist/utils/project.js +164 -0
- package/dist/utils/projectConfig.d.ts +1 -0
- package/dist/utils/projectConfig.js +20 -0
- package/dist/utils/tagTransformMap.d.ts +35 -0
- package/dist/utils/tagTransformMap.js +38 -0
- package/dist/utils/utils.d.ts +7 -0
- package/dist/utils/utils.js +50 -0
- package/dist/utils/zip.d.ts +28 -0
- package/dist/utils/zip.js +287 -0
- package/package.json +6 -6
|
@@ -0,0 +1,78 @@
|
|
|
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
|
|
@@ -0,0 +1,92 @@
|
|
|
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;
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
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
|
+
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);
|
|
35
|
+
}
|
|
36
|
+
get hooks() {
|
|
37
|
+
return this.compiler.hooks;
|
|
38
|
+
}
|
|
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
|
+
});
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
callback === null || callback === void 0 ? void 0 : callback(err, stats);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
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* () {
|
|
69
|
+
// 空实现
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
build(callback) {
|
|
73
|
+
this.compiler.run(callback);
|
|
74
|
+
}
|
|
75
|
+
close(callback) {
|
|
76
|
+
this.compiler.close(callback);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.WebPack = WebPack;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Config } from '../packs';
|
|
2
|
+
import { IPresetOptions } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* babel 仅关注语法转换,polyfill 在 js-core 中已经内置
|
|
5
|
+
* 目前 polyfill 仅支持到 'ios_saf >= 10', 'chrome >= 83'。语法构建中,会默认支持。
|
|
6
|
+
*/
|
|
7
|
+
declare const getBaseConfig: (chain: Config, options: IPresetOptions) => void;
|
|
8
|
+
export default getBaseConfig;
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
]);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
exports.default = getBaseConfig;
|
|
@@ -0,0 +1,48 @@
|
|
|
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 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;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ICompiler, RawSource } from '../../../../packs';
|
|
2
|
+
import { IPresetOptions } from '../../../../types';
|
|
3
|
+
declare class MpEntryPlugin {
|
|
4
|
+
options: IPresetOptions;
|
|
5
|
+
constructor(options: IPresetOptions);
|
|
6
|
+
apply(compiler: ICompiler): void;
|
|
7
|
+
getAppJson(appJSON: any): Record<string, RawSource>;
|
|
8
|
+
getLegacyAppJSON(appJSON: any): RawSource;
|
|
9
|
+
}
|
|
10
|
+
export default MpEntryPlugin;
|
|
@@ -0,0 +1,46 @@
|
|
|
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;
|
|
10
|
+
}
|
|
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) => {
|
|
19
|
+
// @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
|
+
}
|
|
26
|
+
});
|
|
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;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
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
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.default = MpEntryPlugin;
|
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
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')) {
|
|
45
|
+
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;
|
|
@@ -0,0 +1,34 @@
|
|
|
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.presetService = void 0;
|
|
7
|
+
const serviceEntryPlugin_1 = __importDefault(require("./serviceEntryPlugin"));
|
|
8
|
+
const serviceChunkPlugin_1 = __importDefault(require("./serviceChunkPlugin"));
|
|
9
|
+
const resolveLimitPlugin_1 = __importDefault(require("./resolveLimitPlugin"));
|
|
10
|
+
const InjectorPlugin_1 = require("../../../plugins/InjectorPlugin");
|
|
11
|
+
const presetService = (chain, options) => {
|
|
12
|
+
const { packSetting } = options;
|
|
13
|
+
const { distDir } = packSetting;
|
|
14
|
+
chain.merge({
|
|
15
|
+
output: {
|
|
16
|
+
path: distDir,
|
|
17
|
+
globalObject: 'globalThis'
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
chain.plugin('InjectorPlugin').use(InjectorPlugin_1.InjectorPlugin, [options]);
|
|
21
|
+
chain.plugin('ServiceEntryPlugin').use(serviceEntryPlugin_1.default, [options]);
|
|
22
|
+
chain.plugin('ServiceChunkPlugin').use(serviceChunkPlugin_1.default, [options]);
|
|
23
|
+
chain.resolve.plugin('ResolveLimitPlugin').use(resolveLimitPlugin_1.default, [options]);
|
|
24
|
+
chain.optimization
|
|
25
|
+
.runtimeChunk({
|
|
26
|
+
name: 'runtime'
|
|
27
|
+
})
|
|
28
|
+
.splitChunks({
|
|
29
|
+
chunks: chunk => !chunk.name.startsWith('v0/'),
|
|
30
|
+
minSize: 0,
|
|
31
|
+
name: 'service-common'
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
exports.presetService = presetService;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Resolver } from 'enhanced-resolve';
|
|
2
|
+
import { IPresetOptions } from '../../../../types';
|
|
3
|
+
declare class XhsResolveLimitPlugin {
|
|
4
|
+
options: IPresetOptions;
|
|
5
|
+
constructor(options: IPresetOptions);
|
|
6
|
+
apply(resolver: Resolver): void;
|
|
7
|
+
}
|
|
8
|
+
export default XhsResolveLimitPlugin;
|
|
@@ -0,0 +1,35 @@
|
|
|
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 fs_extra_1 = require("fs-extra");
|
|
13
|
+
class XhsResolveLimitPlugin {
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.options = options;
|
|
16
|
+
}
|
|
17
|
+
apply(resolver) {
|
|
18
|
+
const target1 = resolver.ensureHook("resolve");
|
|
19
|
+
resolver.getHook('file')
|
|
20
|
+
.tapAsync('XhsResolveLimitPlugin', (request, contextResolver, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
var _a;
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
const issuer = ((_a = request.context) === null || _a === void 0 ? void 0 : _a.issuer) || '';
|
|
24
|
+
const target = request.path || '';
|
|
25
|
+
if ((target.includes('node_modules') && (0, fs_extra_1.existsSync)(target))) {
|
|
26
|
+
return callback();
|
|
27
|
+
}
|
|
28
|
+
// console.log(`issuer: ${issuer}`, `target: ${target}`)
|
|
29
|
+
// return resolver.doResolve(target1, request, null, contextResolver, callback);
|
|
30
|
+
// console.log(issuer, target)
|
|
31
|
+
return callback();
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.default = XhsResolveLimitPlugin;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Compiler } from 'webpack';
|
|
2
|
+
import { IPresetOptions } from '../../../../types';
|
|
3
|
+
declare class ServiceChunkPlugin {
|
|
4
|
+
options: IPresetOptions;
|
|
5
|
+
constructor(options: IPresetOptions);
|
|
6
|
+
apply(compiler: Compiler): void;
|
|
7
|
+
updateService(compiler: any, compilation: any, runtimeCode: any, commonSource: any): void;
|
|
8
|
+
}
|
|
9
|
+
export default ServiceChunkPlugin;
|