xhs-mp-compiler-cli 2.0.2 → 2.0.4-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/constant.config.d.ts +4 -1
- package/dist/config/constant.config.js +6 -2
- package/dist/index.d.ts +47 -38
- package/dist/index.js +260 -167
- package/dist/packs/webpack/index.js +4 -3
- package/dist/presets/configs/minigame/assets/assetsEntryPlugin.js +3 -3
- package/dist/presets/configs/minigame/service/serviceChunkPlugin.js +4 -4
- package/dist/presets/configs/minigame/service/serviceEntryPlugin.js +3 -2
- package/dist/presets/configs/miniprogram/assets/index.js +20 -7
- package/dist/presets/configs/miniprogram/render/index.js +58 -29
- package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.js +7 -7
- package/dist/presets/configs/miniprogram/render/sketch.d.ts +3 -0
- package/dist/presets/configs/miniprogram/render/sketch.js +45 -0
- package/dist/presets/loaders/mg-entry-loader.js +3 -3
- package/dist/presets/loaders/mini-style-loader.js +14 -60
- package/dist/presets/loaders/mp-entry-loader.js +49 -46
- package/dist/presets/loaders/string-loader.d.ts +0 -0
- package/dist/presets/loaders/string-loader.js +6 -0
- package/dist/presets/loaders/wxss-loader.js +63 -42
- package/dist/utils/common.d.ts +0 -4
- package/dist/utils/common.js +2 -18
- package/dist/utils/loader-utils.d.ts +0 -2
- package/dist/utils/loader-utils.js +2 -20
- package/dist/utils/postcssRpx2Vw.d.ts +2 -1
- package/dist/utils/postcssRpx2Vw.js +7 -4
- package/package.json +16 -22
- package/dist/utils/css.d.ts +0 -2
- package/dist/utils/css.js +0 -49
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
if (v !== undefined) module.exports = v;
|
|
5
5
|
}
|
|
6
6
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "../../../../packs", "lodash", "
|
|
7
|
+
define(["require", "exports", "../../../../packs", "lodash", "xhs-mp-project", "xhs-mp-compiler-utils"], factory);
|
|
8
8
|
}
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const packs_1 = require("../../../../packs");
|
|
13
13
|
const lodash_1 = require("lodash");
|
|
14
|
-
const common_1 = require("../../../../utils/common");
|
|
15
14
|
const xhs_mp_project_1 = require("xhs-mp-project");
|
|
15
|
+
const xhs_mp_compiler_utils_1 = require("xhs-mp-compiler-utils");
|
|
16
16
|
class MpEntryPlugin {
|
|
17
17
|
constructor(options) {
|
|
18
18
|
this.options = options;
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
assets['v1/app.json'] = appJsonSource;
|
|
42
42
|
for (const subpackage of appJSON.subPackages) {
|
|
43
43
|
if (subpackage.independent) {
|
|
44
|
-
assets[(0,
|
|
44
|
+
assets[(0, xhs_mp_compiler_utils_1.unixJoin)("v1", subpackage.dirname, "app.json")] = appJsonSource;
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
return assets;
|
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
if (v !== undefined) module.exports = v;
|
|
5
5
|
}
|
|
6
6
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "
|
|
7
|
+
define(["require", "exports", "xhs-mp-compiler-utils", "../../../../packs", "../../../../packs"], factory);
|
|
8
8
|
}
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const xhs_mp_compiler_utils_1 = require("xhs-mp-compiler-utils");
|
|
12
13
|
const packs_1 = require("../../../../packs");
|
|
13
14
|
const packs_2 = require("../../../../packs");
|
|
14
|
-
const common_1 = require("../../../../utils/common");
|
|
15
15
|
class ServiceChunkPlugin {
|
|
16
16
|
constructor(options) {
|
|
17
17
|
this.options = options;
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
const services = [
|
|
46
46
|
"v1/service.js",
|
|
47
47
|
// @ts-ignore
|
|
48
|
-
...(_a = project.appJSON.subPackages) === null || _a === void 0 ? void 0 : _a.map(i => (0,
|
|
48
|
+
...(_a = project.appJSON.subPackages) === null || _a === void 0 ? void 0 : _a.map(i => (0, xhs_mp_compiler_utils_1.unixJoin)('v1', `${i.entry}.js`))
|
|
49
49
|
];
|
|
50
50
|
services.forEach(servicePath => {
|
|
51
51
|
if (servicePath in assets) {
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
const independent = (_a = project.appJSON.subPackages) === null || _a === void 0 ? void 0 : _a.filter(sub => sub.independent);
|
|
64
64
|
const services = [
|
|
65
65
|
"v1/service.js",
|
|
66
|
-
...independent === null || independent === void 0 ? void 0 : independent.map(i => (0,
|
|
66
|
+
...independent === null || independent === void 0 ? void 0 : independent.map(i => (0, xhs_mp_compiler_utils_1.unixJoin)('v1', `${i.entry}.js`))
|
|
67
67
|
];
|
|
68
68
|
services.forEach(servicePath => {
|
|
69
69
|
var _a;
|
|
@@ -4,13 +4,14 @@
|
|
|
4
4
|
if (v !== undefined) module.exports = v;
|
|
5
5
|
}
|
|
6
6
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "../../../../packs", "../../../../utils/common"], factory);
|
|
7
|
+
define(["require", "exports", "../../../../packs", "../../../../utils/common", "xhs-mp-compiler-utils"], factory);
|
|
8
8
|
}
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const packs_1 = require("../../../../packs");
|
|
13
13
|
const common_1 = require("../../../../utils/common");
|
|
14
|
+
const xhs_mp_compiler_utils_1 = require("xhs-mp-compiler-utils");
|
|
14
15
|
class ServiceEntryPlugin {
|
|
15
16
|
constructor(options) {
|
|
16
17
|
this.options = options;
|
|
@@ -23,7 +24,7 @@
|
|
|
23
24
|
const subPackages = appJSON.subPackages || [];
|
|
24
25
|
this.makeUmdEntry(compiler, 'v1/service.js', `mg-entry-loader?entry=${common_1.DEFAULT_ENTRY}!`, `XHS_SERVICE_${common_1.DEFAULT_ENTRY}`);
|
|
25
26
|
for (const { entry } of subPackages) {
|
|
26
|
-
this.makeUmdEntry(compiler, (0,
|
|
27
|
+
this.makeUmdEntry(compiler, (0, xhs_mp_compiler_utils_1.unixJoin)('v1', `${entry}.js`), `mg-entry-loader?entry=${entry}!`, `XHS_SERVICE_${entry}`);
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
makeUmdEntry(compiler, filename, url, libraryName) {
|
|
@@ -7,13 +7,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
7
7
|
if (v !== undefined) module.exports = v;
|
|
8
8
|
}
|
|
9
9
|
else if (typeof define === "function" && define.amd) {
|
|
10
|
-
define(["require", "exports", "
|
|
10
|
+
define(["require", "exports", "xhs-mp-compiler-utils", "./assetsEntryPlugin", "../../../../config/constant.config", "../../../plugins/InjectorPlugin", "path", "../../../../utils/cache"], factory);
|
|
11
11
|
}
|
|
12
12
|
})(function (require, exports) {
|
|
13
13
|
"use strict";
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.presetAssets = exports.getAssetsEntry = void 0;
|
|
16
|
-
const css_1 = __importDefault(require("../../../../utils/css"));
|
|
17
16
|
const xhs_mp_compiler_utils_1 = require("xhs-mp-compiler-utils");
|
|
18
17
|
const assetsEntryPlugin_1 = __importDefault(require("./assetsEntryPlugin"));
|
|
19
18
|
const constant_config_1 = require("../../../../config/constant.config");
|
|
@@ -28,17 +27,31 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
27
|
};
|
|
29
28
|
exports.getAssetsEntry = getAssetsEntry;
|
|
30
29
|
const presetAssets = (chain, options) => {
|
|
31
|
-
const { packSetting
|
|
30
|
+
const { packSetting } = options;
|
|
32
31
|
const { distDir, cacheDirectory } = packSetting;
|
|
33
32
|
const absCacheDirectory = path_1.default.join(cacheDirectory, 'assets');
|
|
34
|
-
const cssReg = new RegExp(`.${(0, xhs_mp_compiler_utils_1.getCssSuffixName)()}$`);
|
|
35
33
|
chain.merge(Object.assign(Object.assign({ output: {
|
|
36
34
|
path: distDir
|
|
37
35
|
} }, (0, cache_1.getCacheConfig)(absCacheDirectory, options)), { module: {
|
|
38
36
|
rule: {
|
|
39
|
-
|
|
40
|
-
test:
|
|
41
|
-
use:
|
|
37
|
+
style: {
|
|
38
|
+
test: constant_config_1.CSS_REG,
|
|
39
|
+
use: {
|
|
40
|
+
"mini-style-loader": {
|
|
41
|
+
loader: "mini-style-loader",
|
|
42
|
+
options: {
|
|
43
|
+
// app.css 独立加载
|
|
44
|
+
independentFile: true,
|
|
45
|
+
emitDirs: [
|
|
46
|
+
packSetting.enableV1 && 'v1',
|
|
47
|
+
packSetting.enableV2 && 'v2',
|
|
48
|
+
].filter(Boolean),
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"wxss-loader": {
|
|
52
|
+
loader: "wxss-loader",
|
|
53
|
+
}
|
|
54
|
+
}
|
|
42
55
|
}
|
|
43
56
|
}
|
|
44
57
|
} }));
|
|
@@ -7,35 +7,46 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
7
7
|
if (v !== undefined) module.exports = v;
|
|
8
8
|
}
|
|
9
9
|
else if (typeof define === "function" && define.amd) {
|
|
10
|
-
define(["require", "exports", "
|
|
10
|
+
define(["require", "exports", "path", "./sjsEntryPlugin", "./render", "./component", "./sketch", "./renderChunkPlugin", "../../../../types", "../../../plugins/InjectorPlugin", "../../../plugins/SourceMapDevToolPlugin", "../../../../utils/cache", "../../../../config/constant.config"], factory);
|
|
11
11
|
}
|
|
12
12
|
})(function (require, exports) {
|
|
13
13
|
"use strict";
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.presetRender = exports.getRenderEntry = void 0;
|
|
16
|
-
const
|
|
17
|
-
const xhs_mp_compiler_utils_1 = require("xhs-mp-compiler-utils");
|
|
16
|
+
const path_1 = __importDefault(require("path"));
|
|
18
17
|
const sjsEntryPlugin_1 = __importDefault(require("./sjsEntryPlugin"));
|
|
19
18
|
const render_1 = require("./render");
|
|
20
19
|
const component_1 = require("./component");
|
|
20
|
+
const sketch_1 = require("./sketch");
|
|
21
21
|
const renderChunkPlugin_1 = __importDefault(require("./renderChunkPlugin"));
|
|
22
22
|
const types_1 = require("../../../../types");
|
|
23
23
|
const InjectorPlugin_1 = require("../../../plugins/InjectorPlugin");
|
|
24
24
|
const SourceMapDevToolPlugin_1 = require("../../../plugins/SourceMapDevToolPlugin");
|
|
25
25
|
const cache_1 = require("../../../../utils/cache");
|
|
26
|
-
const
|
|
26
|
+
const constant_config_1 = require("../../../../config/constant.config");
|
|
27
27
|
const getRenderEntry = (options) => () => {
|
|
28
|
-
const entries = Object.assign(Object.assign({}, (0, render_1.getRenderEntry)(options)), (0, component_1.getComponentEntry)(options));
|
|
28
|
+
const entries = Object.assign(Object.assign(Object.assign({}, (0, render_1.getRenderEntry)(options)), (0, component_1.getComponentEntry)(options)), (0, sketch_1.getSketchEntry)(options));
|
|
29
29
|
return entries;
|
|
30
30
|
};
|
|
31
31
|
exports.getRenderEntry = getRenderEntry;
|
|
32
32
|
const presetRender = (chain, options) => {
|
|
33
33
|
const { packSetting } = options;
|
|
34
34
|
const { enableVDom, env, distDir, cacheDirectory, enableSourcemap, appendSourcemapComment } = packSetting;
|
|
35
|
-
const mlReg = new RegExp(`.${(0, xhs_mp_compiler_utils_1.getMlSuffixName)()}$`);
|
|
36
|
-
const cssReg = new RegExp(`.${(0, xhs_mp_compiler_utils_1.getCssSuffixName)()}$`);
|
|
37
35
|
const isProd = env === types_1.ENV.production;
|
|
38
36
|
const absCacheDirectory = path_1.default.join(cacheDirectory, 'render');
|
|
37
|
+
const transfomLoader = isProd ?
|
|
38
|
+
{
|
|
39
|
+
'swc-loader': {
|
|
40
|
+
loader: require.resolve('swc-loader'),
|
|
41
|
+
options: {
|
|
42
|
+
jsc: {
|
|
43
|
+
// ?. ?? 运算符号从 es2020支持
|
|
44
|
+
target: 'es2019',
|
|
45
|
+
externalHelpers: false
|
|
46
|
+
},
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
} : {};
|
|
39
50
|
chain.merge(Object.assign(Object.assign({ externals: { vue: 'vue' }, output: {
|
|
40
51
|
path: distDir,
|
|
41
52
|
globalObject: 'globalThis',
|
|
@@ -44,34 +55,52 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
44
55
|
} }, (0, cache_1.getCacheConfig)(absCacheDirectory, options)), { module: {
|
|
45
56
|
rule: {
|
|
46
57
|
ml: {
|
|
47
|
-
test:
|
|
48
|
-
use: Object.assign(Object.assign({},
|
|
49
|
-
{
|
|
50
|
-
'swc-loader': {
|
|
51
|
-
loader: require.resolve('swc-loader'),
|
|
52
|
-
options: {
|
|
53
|
-
jsc: {
|
|
54
|
-
// ?. ?? 运算符号从 es2020支持
|
|
55
|
-
target: 'es2019',
|
|
56
|
-
externalHelpers: false
|
|
57
|
-
},
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
} : {})), { 'ml-loader': {
|
|
58
|
+
test: constant_config_1.ML_REG,
|
|
59
|
+
use: Object.assign(Object.assign({}, transfomLoader), { 'ml-loader': {
|
|
61
60
|
loader: require.resolve('xhs-mp-ml-loader'),
|
|
62
61
|
options: {
|
|
63
62
|
removeComentNode: isProd,
|
|
64
|
-
vdom: enableVDom,
|
|
65
63
|
},
|
|
66
64
|
} }),
|
|
67
65
|
},
|
|
68
|
-
|
|
69
|
-
test:
|
|
70
|
-
use: (
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
66
|
+
sketchMl: {
|
|
67
|
+
test: constant_config_1.SKETCH_ML_REG,
|
|
68
|
+
use: Object.assign(Object.assign({}, transfomLoader), { 'sketch-loader': {
|
|
69
|
+
loader: require.resolve('xhs-mp-sketch-loader'),
|
|
70
|
+
options: {
|
|
71
|
+
removeComentNode: isProd,
|
|
72
|
+
},
|
|
73
|
+
} }),
|
|
74
|
+
},
|
|
75
|
+
style: {
|
|
76
|
+
test: constant_config_1.CSS_REG,
|
|
77
|
+
use: {
|
|
78
|
+
"mini-style-loader": {
|
|
79
|
+
loader: "mini-style-loader",
|
|
80
|
+
options: {
|
|
81
|
+
// vdom 模式下 页面或者组件 css 独立加载
|
|
82
|
+
independentFile: enableVDom,
|
|
83
|
+
emitDirs: [
|
|
84
|
+
packSetting.enableV1 && 'v1',
|
|
85
|
+
packSetting.enableV2 && 'v2',
|
|
86
|
+
].filter(Boolean),
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
"wxss-loader": {
|
|
90
|
+
loader: "wxss-loader",
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
sketchStyle: {
|
|
95
|
+
test: constant_config_1.SKETCH_CSS_REG,
|
|
96
|
+
use: {
|
|
97
|
+
"string-loader": {
|
|
98
|
+
loader: "string-loader"
|
|
99
|
+
},
|
|
100
|
+
"wxss-loader": {
|
|
101
|
+
loader: "wxss-loader",
|
|
102
|
+
}
|
|
103
|
+
}
|
|
75
104
|
},
|
|
76
105
|
},
|
|
77
106
|
} }));
|
|
@@ -30,7 +30,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
30
30
|
if (v !== undefined) module.exports = v;
|
|
31
31
|
}
|
|
32
32
|
else if (typeof define === "function" && define.amd) {
|
|
33
|
-
define(["require", "exports", "fs-extra", "glob", "path", "../../../../packs", "xhs-mp-sjs-loader", "
|
|
33
|
+
define(["require", "exports", "fs-extra", "glob", "path", "../../../../packs", "xhs-mp-sjs-loader", "xhs-mp-compiler-utils"], factory);
|
|
34
34
|
}
|
|
35
35
|
})(function (require, exports) {
|
|
36
36
|
"use strict";
|
|
@@ -40,7 +40,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
40
40
|
const path_1 = __importDefault(require("path"));
|
|
41
41
|
const packs_1 = require("../../../../packs");
|
|
42
42
|
const xhs_mp_sjs_loader_1 = __importStar(require("xhs-mp-sjs-loader"));
|
|
43
|
-
const
|
|
43
|
+
const xhs_mp_compiler_utils_1 = require("xhs-mp-compiler-utils");
|
|
44
44
|
/**
|
|
45
45
|
* @NOTE 分包中使用 SJS 的规则
|
|
46
46
|
*
|
|
@@ -102,7 +102,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
102
102
|
.concat(glob_1.default.sync('**/*.wxs', { cwd: miniprogramDir }));
|
|
103
103
|
relativePaths.forEach(relativePath => {
|
|
104
104
|
var _a;
|
|
105
|
-
const sjsAbsPath = (0,
|
|
105
|
+
const sjsAbsPath = (0, xhs_mp_compiler_utils_1.unixJoin)(miniprogramDir, relativePath);
|
|
106
106
|
// 如果是主包内的文件
|
|
107
107
|
if (this.isFileInMainPkg(relativePath)) {
|
|
108
108
|
this.mainpkgPaths.push(sjsAbsPath);
|
|
@@ -142,7 +142,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
142
142
|
}
|
|
143
143
|
let sjsAbsPath = '';
|
|
144
144
|
if (/\.(sjs|wxs)$/.test(sjsPath)) {
|
|
145
|
-
sjsAbsPath = (0,
|
|
145
|
+
sjsAbsPath = (0, xhs_mp_compiler_utils_1.toUnixPath)(sjsPath);
|
|
146
146
|
}
|
|
147
147
|
else {
|
|
148
148
|
this.emitError(this.generateMessage(`文件后缀不正确 ${sjsPath}`));
|
|
@@ -150,8 +150,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
150
150
|
const content = fs_extra_1.default.readFileSync(sjsAbsPath, 'utf8');
|
|
151
151
|
try {
|
|
152
152
|
const result = xhs_mp_sjs_loader_1.default.call(compilation, content, requirePath => {
|
|
153
|
-
const realPath = (0,
|
|
154
|
-
const relativePath = (0,
|
|
153
|
+
const realPath = (0, xhs_mp_compiler_utils_1.unixResolve)(path_1.default.dirname(sjsAbsPath), requirePath);
|
|
154
|
+
const relativePath = (0, xhs_mp_compiler_utils_1.getShortPath)(project.miniprogramDir, realPath);
|
|
155
155
|
/**
|
|
156
156
|
* 不是当前分包的 sjs 文件不处理
|
|
157
157
|
*/
|
|
@@ -172,7 +172,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
172
172
|
if ((_a = result.errors) === null || _a === void 0 ? void 0 : _a.length) {
|
|
173
173
|
this.emitError(this.generateMessage(result.errors.map(i => i.message).join("\n"), sjsAbsPath));
|
|
174
174
|
}
|
|
175
|
-
const moduleName = (0,
|
|
175
|
+
const moduleName = (0, xhs_mp_compiler_utils_1.getShortPath)(project.miniprogramDir, sjsAbsPath);
|
|
176
176
|
// 老版本兼容代码
|
|
177
177
|
sjsModules.push(`"${moduleName}": ${JSON.stringify(result.legacyCode)}`);
|
|
178
178
|
// 模块化代码
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "xhs-mp-pack"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getSketchEntry = void 0;
|
|
13
|
+
const xhs_mp_pack_1 = require("xhs-mp-pack");
|
|
14
|
+
const getSketchEntry = (options) => {
|
|
15
|
+
const entries = {};
|
|
16
|
+
const { packSetting } = options;
|
|
17
|
+
if (packSetting.enableV2) {
|
|
18
|
+
appendSketchEntry(options, entries, 'v2');
|
|
19
|
+
}
|
|
20
|
+
if (packSetting.enableV1) {
|
|
21
|
+
appendSketchEntry(options, entries, 'v1');
|
|
22
|
+
}
|
|
23
|
+
return entries;
|
|
24
|
+
};
|
|
25
|
+
exports.getSketchEntry = getSketchEntry;
|
|
26
|
+
const appendSketchEntry = (options, entries, mode) => {
|
|
27
|
+
const { project, packSetting } = options;
|
|
28
|
+
const { mainPkg, subPkgs } = packSetting.getCompilePkgsForEntries();
|
|
29
|
+
if (mainPkg) {
|
|
30
|
+
const pages = project.getPages();
|
|
31
|
+
for (const { skeleton } of pages) {
|
|
32
|
+
if (skeleton === null || skeleton === void 0 ? void 0 : skeleton.path) {
|
|
33
|
+
entries[`${mode}/${skeleton === null || skeleton === void 0 ? void 0 : skeleton.path}`] = `mp-entry-loader?type=sketch&mode=${mode}&pkg=${xhs_mp_pack_1.CONSTANTS.MAIN_PKG}&path=${skeleton === null || skeleton === void 0 ? void 0 : skeleton.path}!`;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
for (const { pages, root } of subPkgs) {
|
|
38
|
+
for (const { skeleton } of pages) {
|
|
39
|
+
if (skeleton === null || skeleton === void 0 ? void 0 : skeleton.path) {
|
|
40
|
+
entries[`${mode}/${skeleton === null || skeleton === void 0 ? void 0 : skeleton.path}`] = `mp-entry-loader?type=sketch&mode=${mode}&pkg=${xhs_mp_pack_1.CONSTANTS.SUB_PKG}&root=${root}&path=${skeleton === null || skeleton === void 0 ? void 0 : skeleton.path}!`;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
});
|
|
@@ -7,20 +7,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
7
7
|
if (v !== undefined) module.exports = v;
|
|
8
8
|
}
|
|
9
9
|
else if (typeof define === "function" && define.amd) {
|
|
10
|
-
define(["require", "exports", "fs-extra", "
|
|
10
|
+
define(["require", "exports", "fs-extra", "xhs-mp-project", "xhs-mp-compiler-utils"], factory);
|
|
11
11
|
}
|
|
12
12
|
})(function (require, exports) {
|
|
13
13
|
"use strict";
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
16
|
-
const common_1 = require("../../utils/common");
|
|
17
16
|
const xhs_mp_project_1 = require("xhs-mp-project");
|
|
17
|
+
const xhs_mp_compiler_utils_1 = require("xhs-mp-compiler-utils");
|
|
18
18
|
function entryLoader() {
|
|
19
19
|
// @ts-ignore
|
|
20
20
|
const { appJSON, projectPath } = this._compiler.project;
|
|
21
21
|
const { entry } = this.getOptions();
|
|
22
22
|
const addAppJs = () => {
|
|
23
|
-
const absolutePath = (0,
|
|
23
|
+
const absolutePath = (0, xhs_mp_compiler_utils_1.unixJoin)(projectPath, entry);
|
|
24
24
|
if (fs_extra_1.default.existsSync(`${absolutePath}.js`)) {
|
|
25
25
|
return `require('${absolutePath}.js')`;
|
|
26
26
|
}
|
|
@@ -1,65 +1,32 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
|
-
};
|
|
13
1
|
(function (factory) {
|
|
14
2
|
if (typeof module === "object" && typeof module.exports === "object") {
|
|
15
3
|
var v = factory(require, exports);
|
|
16
4
|
if (v !== undefined) module.exports = v;
|
|
17
5
|
}
|
|
18
6
|
else if (typeof define === "function" && define.amd) {
|
|
19
|
-
define(["require", "exports", "
|
|
7
|
+
define(["require", "exports", "xhs-mp-compiler-utils", "../../packs", "../../config/constant.config"], factory);
|
|
20
8
|
}
|
|
21
9
|
})(function (require, exports) {
|
|
22
10
|
"use strict";
|
|
23
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const xhs_mp_compiler_utils_1 = require("xhs-mp-compiler-utils");
|
|
24
13
|
const packs_1 = require("../../packs");
|
|
25
|
-
const
|
|
26
|
-
const common_1 = require("../../utils/common");
|
|
27
|
-
const CSS_MINIMIZER_OPTIONS = {
|
|
28
|
-
preset: ['default', { normalizeUrl: false, calc: false }]
|
|
29
|
-
};
|
|
30
|
-
const minify = (source, name) => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
-
var _a, _b;
|
|
32
|
-
const postcssOptions = {
|
|
33
|
-
to: name,
|
|
34
|
-
from: name
|
|
35
|
-
};
|
|
36
|
-
try {
|
|
37
|
-
const result = yield cssnano_1.default.process(source, postcssOptions, CSS_MINIMIZER_OPTIONS);
|
|
38
|
-
return {
|
|
39
|
-
code: result.css,
|
|
40
|
-
warnings: (_b = (_a = result.warnings()) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.call(_a, i => i.toString())
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
catch (error) {
|
|
44
|
-
return {
|
|
45
|
-
code: source
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
});
|
|
14
|
+
const constant_config_1 = require("../../config/constant.config");
|
|
49
15
|
function miniStyleLoader(source) {
|
|
50
16
|
var _a;
|
|
51
17
|
const callback = this.async();
|
|
52
18
|
const { resourcePath } = this;
|
|
53
|
-
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
const { project } = this._compiler;
|
|
21
|
+
const { independentFile, emitDirs = [] } = this.getOptions();
|
|
54
22
|
const { miniprogramDir } = project;
|
|
55
|
-
const
|
|
56
|
-
const shortPath = (0, common_1.getShortPath)(miniprogramDir, resourcePath).replace(/\.wxss$/, '.css');
|
|
23
|
+
const shortPath = (0, xhs_mp_compiler_utils_1.getShortPath)(miniprogramDir, resourcePath).replace(constant_config_1.CSS_REG, '.css');
|
|
57
24
|
source = (_a = source === null || source === void 0 ? void 0 : source.trim) === null || _a === void 0 ? void 0 : _a.call(source);
|
|
58
25
|
const emitFiles = (code) => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
26
|
+
if ((independentFile) && code) {
|
|
27
|
+
emitDirs.forEach((dir) => {
|
|
28
|
+
this.emitFile(`${dir}/${shortPath}`, code);
|
|
29
|
+
});
|
|
63
30
|
}
|
|
64
31
|
};
|
|
65
32
|
const result = (code) => {
|
|
@@ -67,7 +34,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
67
34
|
return `export default void 0;`;
|
|
68
35
|
}
|
|
69
36
|
// 判断浏览器环境,注入css添加逻辑
|
|
70
|
-
if (
|
|
37
|
+
if (independentFile) {
|
|
71
38
|
return new packs_1.RawSource(`globalThis.__XHS_ADD_LINK(${JSON.stringify(shortPath)});` +
|
|
72
39
|
`export default ${JSON.stringify(shortPath)};`).source();
|
|
73
40
|
}
|
|
@@ -76,21 +43,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
76
43
|
`export default ${JSON.stringify(shortPath)};`).source();
|
|
77
44
|
}
|
|
78
45
|
};
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
minify(source, shortPath)
|
|
82
|
-
.then(({ code, warnings }) => {
|
|
83
|
-
emitFiles(code);
|
|
84
|
-
callback(null, result(code));
|
|
85
|
-
})
|
|
86
|
-
.catch(error => {
|
|
87
|
-
callback(error);
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
emitFiles(source);
|
|
92
|
-
callback(null, result(source));
|
|
93
|
-
}
|
|
46
|
+
emitFiles(source);
|
|
47
|
+
callback(null, result(source));
|
|
94
48
|
}
|
|
95
49
|
module.exports = miniStyleLoader;
|
|
96
50
|
});
|