@dcloudio/uni-cli-shared 3.0.0-alpha-3021320211109002 → 3.0.0-alpha-3021320211115001
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/constants.d.ts +3 -0
- package/dist/constants.js +4 -1
- package/dist/easycom.d.ts +7 -1
- package/dist/easycom.js +25 -6
- package/dist/env/define.d.ts +3 -0
- package/dist/env/define.js +6 -0
- package/dist/exports.d.ts +1 -0
- package/dist/exports.js +8 -0
- package/dist/filter.d.ts +16 -0
- package/dist/filter.js +60 -0
- package/dist/hbx/alias.js +9 -1
- package/dist/hbx/env.js +4 -1
- package/dist/hbx/index.js +0 -7
- package/dist/hbx/log.d.ts +2 -0
- package/dist/hbx/log.js +36 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/json/app/manifest/confusion.d.ts +3 -0
- package/dist/json/app/manifest/confusion.js +56 -14
- package/dist/json/app/manifest/env.d.ts +1 -1
- package/dist/json/app/manifest/index.d.ts +1 -0
- package/dist/json/app/manifest/index.js +5 -1
- package/dist/json/app/manifest/nvue.d.ts +3 -3
- package/dist/json/app/pages/index.d.ts +0 -1
- package/dist/json/app/pages/index.js +0 -11
- package/dist/json/manifest.d.ts +1 -1
- package/dist/json/manifest.js +9 -3
- package/dist/json/mp/index.d.ts +1 -0
- package/dist/json/mp/index.js +11 -0
- package/dist/json/mp/jsonFile.d.ts +8 -6
- package/dist/json/mp/jsonFile.js +68 -16
- package/dist/json/mp/pages.d.ts +1 -0
- package/dist/json/mp/pages.js +17 -3
- package/dist/json/mp/types.d.ts +1 -0
- package/dist/json/pages.js +0 -4
- package/dist/logs/console.js +5 -2
- package/dist/logs/format.js +6 -0
- package/dist/messages/index.d.ts +3 -0
- package/dist/messages/index.js +3 -0
- package/dist/mp/constants.d.ts +2 -0
- package/dist/mp/constants.js +5 -0
- package/dist/mp/event.d.ts +2 -1
- package/dist/mp/event.js +18 -3
- package/dist/mp/imports.d.ts +5 -0
- package/dist/mp/imports.js +63 -0
- package/dist/mp/index.d.ts +5 -0
- package/dist/mp/index.js +7 -0
- package/dist/mp/nvue.d.ts +1 -0
- package/dist/mp/nvue.js +18 -0
- package/dist/mp/style.d.ts +1 -0
- package/dist/mp/style.js +9 -0
- package/dist/mp/template.d.ts +55 -0
- package/dist/mp/template.js +73 -0
- package/dist/mp/transformImports.d.ts +14 -0
- package/dist/mp/transformImports.js +175 -0
- package/dist/postcss/plugins/stylePluginScoped.d.ts +1 -1
- package/dist/postcss/plugins/uniapp.d.ts +1 -1
- package/dist/postcss/plugins/uniapp.js +51 -21
- package/dist/preprocess/context.js +1 -0
- package/dist/utils.d.ts +9 -1
- package/dist/utils.js +93 -8
- package/dist/vite/features.d.ts +1 -1
- package/dist/vite/index.d.ts +2 -3
- package/dist/vite/plugins/copy.d.ts +1 -1
- package/dist/vite/plugins/cssScoped.d.ts +1 -1
- package/dist/vite/plugins/inject.d.ts +1 -1
- package/dist/vite/plugins/inject.js +2 -2
- package/dist/vite/plugins/vitejs/config.d.ts +1 -1
- package/dist/vite/plugins/vitejs/index.d.ts +1 -1
- package/dist/vite/plugins/vitejs/plugin.d.ts +1 -1
- package/dist/vite/plugins/vitejs/plugins/asset.d.ts +1 -1
- package/dist/vite/plugins/vitejs/plugins/asset.js +28 -21
- package/dist/vite/plugins/vitejs/plugins/css.d.ts +4 -4
- package/dist/vite/plugins/vitejs/plugins/css.js +15 -24
- package/dist/vite/plugins/vitejs/server/moduleGraph.d.ts +1 -1
- package/dist/vite/plugins/vitejs/server/moduleGraph.js +0 -3
- package/dist/vite/utils/ast.d.ts +1 -1
- package/dist/vite/utils/index.d.ts +1 -1
- package/dist/vite/utils/plugin.d.ts +4 -4
- package/dist/vite/utils/plugin.js +2 -2
- package/dist/vue/index.d.ts +2 -0
- package/dist/vue/index.js +14 -0
- package/dist/vue/transforms/index.d.ts +10 -0
- package/dist/vue/transforms/index.js +36 -0
- package/dist/vue/transforms/transformComponent.d.ts +3 -0
- package/dist/vue/transforms/transformComponent.js +26 -0
- package/dist/vue/transforms/transformEvent.d.ts +2 -0
- package/dist/vue/transforms/transformEvent.js +22 -0
- package/dist/vue/transforms/transformPageHead.d.ts +2 -0
- package/dist/vue/transforms/transformPageHead.js +11 -0
- package/dist/vue/transforms/transformRef.d.ts +2 -0
- package/dist/vue/transforms/transformRef.js +32 -0
- package/dist/vue/transforms/transformTag.d.ts +2 -0
- package/dist/vue/transforms/transformTag.js +18 -0
- package/dist/vue/transforms/vModel.d.ts +12 -0
- package/dist/vue/transforms/vModel.js +33 -0
- package/dist/vue/transforms/vOn.d.ts +15 -0
- package/dist/vue/transforms/vOn.js +88 -0
- package/dist/vue/utils.d.ts +9 -0
- package/dist/vue/utils.js +66 -0
- package/lib/nvue.css +34 -0
- package/package.json +27 -6
- package/LICENSE +0 -202
- package/dist/json/app/pages/nvue.d.ts +0 -1
- package/dist/json/app/pages/nvue.js +0 -88
- package/dist/renderjs.d.ts +0 -16
- package/dist/renderjs.js +0 -44
|
@@ -0,0 +1,175 @@
|
|
|
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.transformVueComponentImports = void 0;
|
|
7
|
+
const parser_1 = require("@babel/parser");
|
|
8
|
+
const types_1 = require("@babel/types");
|
|
9
|
+
const shared_1 = require("@vue/shared");
|
|
10
|
+
const estree_walker_1 = require("estree-walker");
|
|
11
|
+
const magic_string_1 = __importDefault(require("magic-string"));
|
|
12
|
+
const messages_1 = require("../messages");
|
|
13
|
+
const constants_1 = require("../constants");
|
|
14
|
+
const utils_1 = require("../utils");
|
|
15
|
+
async function transformVueComponentImports(code, importer, { root, resolve, global, dynamicImport, babelParserPlugins, }) {
|
|
16
|
+
if (!global && !code.includes(constants_1.BINDING_COMPONENTS)) {
|
|
17
|
+
return { code, usingComponents: {} };
|
|
18
|
+
}
|
|
19
|
+
const s = new magic_string_1.default(code);
|
|
20
|
+
const scriptAst = (0, parser_1.parse)(code, {
|
|
21
|
+
plugins: [...(babelParserPlugins || [])],
|
|
22
|
+
sourceType: 'module',
|
|
23
|
+
}).program;
|
|
24
|
+
const imports = findVueComponentImports(scriptAst.body, global
|
|
25
|
+
? parseGlobalComponents(scriptAst)
|
|
26
|
+
: parseComponents(scriptAst, findBindingComponents(scriptAst.body)));
|
|
27
|
+
const usingComponents = {};
|
|
28
|
+
for (let i = 0; i < imports.length; i++) {
|
|
29
|
+
const { tag, import: { start, end, specifiers: [specifier], source, }, } = imports[i];
|
|
30
|
+
const resolveId = await resolve(source.value, importer);
|
|
31
|
+
if (resolveId) {
|
|
32
|
+
s.overwrite(start, end, dynamicImport(specifier.local.name, resolveId.id) + ';');
|
|
33
|
+
const componentName = (0, shared_1.hyphenate)(tag);
|
|
34
|
+
if (!usingComponents[componentName]) {
|
|
35
|
+
usingComponents[componentName] =
|
|
36
|
+
'/' + (0, utils_1.removeExt)((0, utils_1.normalizeMiniProgramFilename)(resolveId.id, root));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return { code: s.toString(), usingComponents };
|
|
41
|
+
}
|
|
42
|
+
exports.transformVueComponentImports = transformVueComponentImports;
|
|
43
|
+
/**
|
|
44
|
+
* 解析编译器生成的 bindingComponents
|
|
45
|
+
* @param ast
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
function findBindingComponents(ast) {
|
|
49
|
+
for (const node of ast) {
|
|
50
|
+
if (!(0, types_1.isVariableDeclaration)(node)) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const declarator = node.declarations[0];
|
|
54
|
+
if ((0, types_1.isIdentifier)(declarator.id) &&
|
|
55
|
+
declarator.id.name === constants_1.BINDING_COMPONENTS) {
|
|
56
|
+
const bindingComponents = JSON.parse(declarator.init.value);
|
|
57
|
+
return Object.keys(bindingComponents).reduce((bindings, tag) => {
|
|
58
|
+
const binding = bindingComponents[tag];
|
|
59
|
+
bindings[binding.name] = {
|
|
60
|
+
tag,
|
|
61
|
+
type: binding.type,
|
|
62
|
+
};
|
|
63
|
+
return bindings;
|
|
64
|
+
}, {});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return {};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* 查找全局组件定义:app.component('component-a',{})
|
|
71
|
+
* @param ast
|
|
72
|
+
* @returns
|
|
73
|
+
*/
|
|
74
|
+
function parseGlobalComponents(ast) {
|
|
75
|
+
const bindingComponents = {};
|
|
76
|
+
estree_walker_1.walk(ast, {
|
|
77
|
+
enter(child) {
|
|
78
|
+
if (!(0, types_1.isCallExpression)(child)) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const { callee } = child;
|
|
82
|
+
// .component
|
|
83
|
+
if (!(0, types_1.isMemberExpression)(callee) ||
|
|
84
|
+
!(0, types_1.isIdentifier)(callee.property) ||
|
|
85
|
+
callee.property.name !== 'component') {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
// .component('component-a',{})
|
|
89
|
+
const args = child.arguments;
|
|
90
|
+
if (args.length !== 2) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const [name, value] = args;
|
|
94
|
+
if (!(0, types_1.isStringLiteral)(name)) {
|
|
95
|
+
return console.warn(messages_1.M['mp.component.args[0]']);
|
|
96
|
+
}
|
|
97
|
+
if (!(0, types_1.isIdentifier)(value)) {
|
|
98
|
+
return console.warn(messages_1.M['mp.component.args[1]']);
|
|
99
|
+
}
|
|
100
|
+
bindingComponents[value.name] = {
|
|
101
|
+
tag: name.value,
|
|
102
|
+
type: 'unknown',
|
|
103
|
+
};
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
return bindingComponents;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* 从 components 中查找定义的组件,修改 bindingComponents
|
|
110
|
+
* @param ast
|
|
111
|
+
* @param bindingComponents
|
|
112
|
+
*/
|
|
113
|
+
function parseComponents(ast, bindingComponents) {
|
|
114
|
+
;
|
|
115
|
+
estree_walker_1.walk(ast, {
|
|
116
|
+
enter(child) {
|
|
117
|
+
if (!(0, types_1.isObjectExpression)(child)) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const componentsProp = child.properties.find((prop) => (0, types_1.isObjectProperty)(prop) &&
|
|
121
|
+
(0, types_1.isIdentifier)(prop.key) &&
|
|
122
|
+
prop.key.name === 'components');
|
|
123
|
+
if (!componentsProp) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const componentsExpr = componentsProp.value;
|
|
127
|
+
if (!(0, types_1.isObjectExpression)(componentsExpr)) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
componentsExpr.properties.forEach((prop) => {
|
|
131
|
+
if (!(0, types_1.isObjectProperty)(prop)) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (!(0, types_1.isIdentifier)(prop.key) && !(0, types_1.isStringLiteral)(prop.key)) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (!(0, types_1.isIdentifier)(prop.value)) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const tag = (0, types_1.isIdentifier)(prop.key) ? prop.key.name : prop.key.value;
|
|
141
|
+
const name = findBindingComponent(tag, bindingComponents);
|
|
142
|
+
if (name) {
|
|
143
|
+
bindingComponents[prop.value.name] = bindingComponents[name];
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
return bindingComponents;
|
|
149
|
+
}
|
|
150
|
+
function findBindingComponent(tag, bindingComponents) {
|
|
151
|
+
return Object.keys(bindingComponents).find((name) => {
|
|
152
|
+
const componentTag = bindingComponents[name].tag;
|
|
153
|
+
const camelName = (0, shared_1.camelize)(componentTag);
|
|
154
|
+
const PascalName = (0, shared_1.capitalize)(camelName);
|
|
155
|
+
return tag === componentTag || tag === camelName || tag === PascalName;
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
function findVueComponentImports(ast, bindingComponents) {
|
|
159
|
+
const imports = [];
|
|
160
|
+
for (let i = 0; i < ast.length; i++) {
|
|
161
|
+
const node = ast[i];
|
|
162
|
+
if (!(0, types_1.isImportDeclaration)(node)) {
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (node.specifiers.length !== 1) {
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
const { name } = node.specifiers[0].local;
|
|
169
|
+
if (!bindingComponents[name]) {
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
imports.push({ tag: bindingComponents[name].tag, import: node });
|
|
173
|
+
}
|
|
174
|
+
return imports;
|
|
175
|
+
}
|
|
@@ -4,12 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const shared_1 = require("@vue/shared");
|
|
7
|
-
const postcss_1 = require("postcss");
|
|
8
7
|
const postcss_selector_parser_1 = __importDefault(require("postcss-selector-parser"));
|
|
9
8
|
const uni_shared_1 = require("@dcloudio/uni-shared");
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
}, uni_shared_1.defaultRpx2Unit);
|
|
9
|
+
const manifest_1 = require("../../json/manifest");
|
|
10
|
+
const defaultUniAppCssProcessorOptions = (0, shared_1.extend)({}, uni_shared_1.defaultRpx2Unit);
|
|
13
11
|
const BG_PROPS = [
|
|
14
12
|
'background',
|
|
15
13
|
'background-clip',
|
|
@@ -21,22 +19,14 @@ const BG_PROPS = [
|
|
|
21
19
|
'background-size',
|
|
22
20
|
'background-attachment',
|
|
23
21
|
];
|
|
24
|
-
function transform(selector,
|
|
22
|
+
function transform(selector, state, { rewriteTag }) {
|
|
25
23
|
if (selector.type !== 'tag') {
|
|
26
24
|
return;
|
|
27
25
|
}
|
|
28
26
|
const { value } = selector;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
else if (value === 'page') {
|
|
33
|
-
if (!page) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
selector.value = page;
|
|
37
|
-
if (page !== 'body') {
|
|
38
|
-
state.bg = true;
|
|
39
|
-
}
|
|
27
|
+
selector.value = rewriteTag(value);
|
|
28
|
+
if (value === 'page' && selector.value === 'uni-page-body') {
|
|
29
|
+
state.bg = true;
|
|
40
30
|
}
|
|
41
31
|
}
|
|
42
32
|
function createBodyBackgroundRule(origRule) {
|
|
@@ -47,13 +37,14 @@ function createBodyBackgroundRule(origRule) {
|
|
|
47
37
|
}
|
|
48
38
|
});
|
|
49
39
|
if (bgDecls.length) {
|
|
50
|
-
|
|
40
|
+
const { rule } = require('postcss');
|
|
41
|
+
origRule.after(rule({ selector: 'body' }).append(bgDecls));
|
|
51
42
|
}
|
|
52
43
|
}
|
|
53
|
-
function walkRules(
|
|
44
|
+
function walkRules(options) {
|
|
54
45
|
return (rule) => {
|
|
55
46
|
const state = { bg: false };
|
|
56
|
-
rule.selector = (0, postcss_selector_parser_1.default)((selectors) => selectors.walk((selector) => transform(selector,
|
|
47
|
+
rule.selector = (0, postcss_selector_parser_1.default)((selectors) => selectors.walk((selector) => transform(selector, state, options))).processSync(rule.selector);
|
|
57
48
|
state.bg && createBodyBackgroundRule(rule);
|
|
58
49
|
};
|
|
59
50
|
}
|
|
@@ -66,8 +57,42 @@ function walkDecls(rpx2unit) {
|
|
|
66
57
|
decl.value = rpx2unit(decl.value);
|
|
67
58
|
};
|
|
68
59
|
}
|
|
60
|
+
const baiduTags = {
|
|
61
|
+
navigator: 'nav',
|
|
62
|
+
};
|
|
63
|
+
function rewriteBaiduTags(tag) {
|
|
64
|
+
return baiduTags[tag] || tag;
|
|
65
|
+
}
|
|
66
|
+
function rewriteUniH5Tags(tag) {
|
|
67
|
+
if (tag === 'page') {
|
|
68
|
+
return 'uni-page-body';
|
|
69
|
+
}
|
|
70
|
+
if ((0, uni_shared_1.isBuiltInComponent)(tag)) {
|
|
71
|
+
return uni_shared_1.COMPONENT_SELECTOR_PREFIX + tag;
|
|
72
|
+
}
|
|
73
|
+
return tag;
|
|
74
|
+
}
|
|
75
|
+
function rewriteUniAppTags(tag) {
|
|
76
|
+
if (tag === 'page') {
|
|
77
|
+
return 'body';
|
|
78
|
+
}
|
|
79
|
+
if ((0, uni_shared_1.isBuiltInComponent)(tag)) {
|
|
80
|
+
return uni_shared_1.COMPONENT_SELECTOR_PREFIX + tag;
|
|
81
|
+
}
|
|
82
|
+
return tag;
|
|
83
|
+
}
|
|
84
|
+
const transforms = {
|
|
85
|
+
h5: rewriteUniH5Tags,
|
|
86
|
+
app: rewriteUniAppTags,
|
|
87
|
+
'mp-baidu': rewriteBaiduTags,
|
|
88
|
+
};
|
|
69
89
|
const uniapp = (opts) => {
|
|
70
|
-
const
|
|
90
|
+
const platform = process.env.UNI_PLATFORM;
|
|
91
|
+
if (!opts) {
|
|
92
|
+
const inputDir = process.env.UNI_INPUT_DIR;
|
|
93
|
+
opts = (0, shared_1.extend)((0, manifest_1.parseRpx2UnitOnce)(inputDir, platform));
|
|
94
|
+
}
|
|
95
|
+
const { unit, unitRatio, unitPrecision } = (0, shared_1.extend)({}, defaultUniAppCssProcessorOptions, opts || {});
|
|
71
96
|
const rpx2unit = (0, uni_shared_1.createRpx2Unit)(unit, unitRatio, unitPrecision);
|
|
72
97
|
return {
|
|
73
98
|
postcssPlugin: 'uni-app',
|
|
@@ -75,7 +100,12 @@ const uniapp = (opts) => {
|
|
|
75
100
|
return {
|
|
76
101
|
OnceExit(root) {
|
|
77
102
|
root.walkDecls(walkDecls(rpx2unit));
|
|
78
|
-
|
|
103
|
+
const rewriteTag = transforms[platform];
|
|
104
|
+
if (rewriteTag) {
|
|
105
|
+
root.walkRules(walkRules({
|
|
106
|
+
rewriteTag,
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
79
109
|
},
|
|
80
110
|
};
|
|
81
111
|
},
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
export { default as hash } from 'hash-sum';
|
|
2
|
+
import type { SFCTemplateCompileOptions } from '@vue/compiler-sfc';
|
|
3
|
+
import { ElementNode, RootNode, TemplateChildNode } from '@vue/compiler-core';
|
|
2
4
|
export declare const isWindows: boolean;
|
|
3
5
|
export declare function normalizePath(id: string): string;
|
|
6
|
+
export declare function relativeFile(from: string, to: string): string;
|
|
7
|
+
export declare function checkElementNodeTag(node: RootNode | TemplateChildNode | null | undefined, tag: string): node is ElementNode;
|
|
4
8
|
export declare const resolveMainPathOnce: (inputDir: string) => string;
|
|
9
|
+
export declare function resolveComponentsLibPath(): string;
|
|
10
|
+
export declare function getBuiltInPaths(): string[];
|
|
5
11
|
export declare function resolveBuiltIn(path: string): string;
|
|
6
12
|
export declare function normalizeIdentifier(str: string): string;
|
|
7
13
|
export declare function normalizePagePath(pagePath: string, platform: UniApp.PLATFORM): string | undefined;
|
|
8
|
-
export declare function removeExt(str: string
|
|
14
|
+
export declare function removeExt(str: string): string;
|
|
9
15
|
export declare function normalizeNodeModules(str: string): string;
|
|
16
|
+
export declare function normalizeMiniProgramFilename(filename: string, inputDir?: string): string;
|
|
17
|
+
export declare function createUniVueTransformAssetUrls(base: string): SFCTemplateCompileOptions['transformAssetUrls'];
|
package/dist/utils.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.normalizeNodeModules = exports.removeExt = exports.normalizePagePath = exports.normalizeIdentifier = exports.resolveBuiltIn = exports.resolveMainPathOnce = exports.normalizePath = exports.isWindows = exports.hash = void 0;
|
|
6
|
+
exports.createUniVueTransformAssetUrls = exports.normalizeMiniProgramFilename = exports.normalizeNodeModules = exports.removeExt = exports.normalizePagePath = exports.normalizeIdentifier = exports.resolveBuiltIn = exports.getBuiltInPaths = exports.resolveComponentsLibPath = exports.resolveMainPathOnce = exports.checkElementNodeTag = exports.relativeFile = exports.normalizePath = exports.isWindows = exports.hash = void 0;
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const os_1 = __importDefault(require("os"));
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
@@ -11,12 +11,21 @@ const shared_1 = require("@vue/shared");
|
|
|
11
11
|
const uni_shared_1 = require("@dcloudio/uni-shared");
|
|
12
12
|
var hash_sum_1 = require("hash-sum");
|
|
13
13
|
Object.defineProperty(exports, "hash", { enumerable: true, get: function () { return __importDefault(hash_sum_1).default; } });
|
|
14
|
+
const debug_1 = __importDefault(require("debug"));
|
|
14
15
|
const constants_1 = require("./constants");
|
|
15
16
|
exports.isWindows = os_1.default.platform() === 'win32';
|
|
16
17
|
function normalizePath(id) {
|
|
17
18
|
return exports.isWindows ? id.replace(/\\/g, '/') : id;
|
|
18
19
|
}
|
|
19
20
|
exports.normalizePath = normalizePath;
|
|
21
|
+
function relativeFile(from, to) {
|
|
22
|
+
return normalizePath(path_1.default.relative(path_1.default.dirname(from), to));
|
|
23
|
+
}
|
|
24
|
+
exports.relativeFile = relativeFile;
|
|
25
|
+
function checkElementNodeTag(node, tag) {
|
|
26
|
+
return !!node && node.type === 1 /* ELEMENT */ && node.tag === tag;
|
|
27
|
+
}
|
|
28
|
+
exports.checkElementNodeTag = checkElementNodeTag;
|
|
20
29
|
exports.resolveMainPathOnce = (0, uni_shared_1.once)((inputDir) => {
|
|
21
30
|
const mainTsPath = path_1.default.resolve(inputDir, 'main.ts');
|
|
22
31
|
if (fs_1.default.existsSync(mainTsPath)) {
|
|
@@ -24,8 +33,60 @@ exports.resolveMainPathOnce = (0, uni_shared_1.once)((inputDir) => {
|
|
|
24
33
|
}
|
|
25
34
|
return normalizePath(path_1.default.resolve(inputDir, 'main.js'));
|
|
26
35
|
});
|
|
36
|
+
let componentsLibPath = '';
|
|
37
|
+
function resolveComponentsLibPath() {
|
|
38
|
+
if (!componentsLibPath) {
|
|
39
|
+
componentsLibPath = path_1.default.resolve(resolveBuiltIn('@dcloudio/uni-components/package.json'), '../lib');
|
|
40
|
+
}
|
|
41
|
+
return componentsLibPath;
|
|
42
|
+
}
|
|
43
|
+
exports.resolveComponentsLibPath = resolveComponentsLibPath;
|
|
44
|
+
const ownerModules = ['@dcloudio/uni-app', '@dcloudio/vite-plugin-uni'];
|
|
45
|
+
const paths = [];
|
|
46
|
+
function resolveNodeModulePath(modulePath) {
|
|
47
|
+
const nodeModulesPaths = [];
|
|
48
|
+
const nodeModulesPath = path_1.default.join(modulePath, 'node_modules');
|
|
49
|
+
if (fs_1.default.existsSync(nodeModulesPath)) {
|
|
50
|
+
nodeModulesPaths.push(nodeModulesPath);
|
|
51
|
+
}
|
|
52
|
+
const index = modulePath.lastIndexOf('node_modules');
|
|
53
|
+
if (index > -1) {
|
|
54
|
+
nodeModulesPaths.push(path_1.default.join(modulePath.substr(0, index), 'node_modules'));
|
|
55
|
+
}
|
|
56
|
+
return nodeModulesPaths;
|
|
57
|
+
}
|
|
58
|
+
function initPaths() {
|
|
59
|
+
const cliContext = process.env.UNI_CLI_CONTEXT;
|
|
60
|
+
if (cliContext) {
|
|
61
|
+
const pathSet = new Set();
|
|
62
|
+
pathSet.add(path_1.default.join(cliContext, 'node_modules'));
|
|
63
|
+
[`@dcloudio/uni-` + process.env.UNI_PLATFORM, ...ownerModules].forEach((ownerModule) => {
|
|
64
|
+
let pkgPath = '';
|
|
65
|
+
try {
|
|
66
|
+
pkgPath = require.resolve(ownerModule + '/package.json', {
|
|
67
|
+
paths: [cliContext],
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
catch (e) { }
|
|
71
|
+
if (pkgPath) {
|
|
72
|
+
resolveNodeModulePath(path_1.default.dirname(pkgPath)).forEach((nodeModulePath) => {
|
|
73
|
+
pathSet.add(nodeModulePath);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
paths.push(...pathSet);
|
|
78
|
+
(0, debug_1.default)('uni-paths')(paths);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function getBuiltInPaths() {
|
|
82
|
+
if (!paths.length) {
|
|
83
|
+
initPaths();
|
|
84
|
+
}
|
|
85
|
+
return paths;
|
|
86
|
+
}
|
|
87
|
+
exports.getBuiltInPaths = getBuiltInPaths;
|
|
27
88
|
function resolveBuiltIn(path) {
|
|
28
|
-
return require.resolve(path, { paths:
|
|
89
|
+
return require.resolve(path, { paths: getBuiltInPaths() });
|
|
29
90
|
}
|
|
30
91
|
exports.resolveBuiltIn = resolveBuiltIn;
|
|
31
92
|
function normalizeIdentifier(str) {
|
|
@@ -47,12 +108,8 @@ function normalizePagePath(pagePath, platform) {
|
|
|
47
108
|
console.error(`${pagePath} not found`);
|
|
48
109
|
}
|
|
49
110
|
exports.normalizePagePath = normalizePagePath;
|
|
50
|
-
function removeExt(str
|
|
51
|
-
|
|
52
|
-
const reg = new RegExp(ext.replace(/\./, '\\.') + '$');
|
|
53
|
-
return normalizePath(str.replace(reg, ''));
|
|
54
|
-
}
|
|
55
|
-
return normalizePath(str.replace(/\.\w+$/g, ''));
|
|
111
|
+
function removeExt(str) {
|
|
112
|
+
return str.split('?')[0].replace(/\.\w+$/g, '');
|
|
56
113
|
}
|
|
57
114
|
exports.removeExt = removeExt;
|
|
58
115
|
const NODE_MODULES_REGEX = /(\.\.\/)?node_modules/g;
|
|
@@ -66,3 +123,31 @@ function normalizeNodeModules(str) {
|
|
|
66
123
|
return str;
|
|
67
124
|
}
|
|
68
125
|
exports.normalizeNodeModules = normalizeNodeModules;
|
|
126
|
+
function normalizeMiniProgramFilename(filename, inputDir) {
|
|
127
|
+
if (!inputDir || !path_1.default.isAbsolute(filename)) {
|
|
128
|
+
return normalizeNodeModules(filename);
|
|
129
|
+
}
|
|
130
|
+
return normalizeNodeModules(path_1.default.relative(inputDir, filename));
|
|
131
|
+
}
|
|
132
|
+
exports.normalizeMiniProgramFilename = normalizeMiniProgramFilename;
|
|
133
|
+
function createUniVueTransformAssetUrls(base) {
|
|
134
|
+
return {
|
|
135
|
+
base,
|
|
136
|
+
tags: {
|
|
137
|
+
audio: ['src'],
|
|
138
|
+
video: ['src', 'poster'],
|
|
139
|
+
img: ['src'],
|
|
140
|
+
image: ['src'],
|
|
141
|
+
'cover-image': ['src'],
|
|
142
|
+
// h5
|
|
143
|
+
'v-uni-audio': ['src'],
|
|
144
|
+
'v-uni-video': ['src', 'poster'],
|
|
145
|
+
'v-uni-image': ['src'],
|
|
146
|
+
'v-uni-cover-image': ['src'],
|
|
147
|
+
// nvue
|
|
148
|
+
'u-image': ['src'],
|
|
149
|
+
'u-video': ['src', 'poster'],
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
exports.createUniVueTransformAssetUrls = createUniVueTransformAssetUrls;
|
package/dist/vite/features.d.ts
CHANGED
package/dist/vite/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Plugin } from 'vite';
|
|
2
|
-
import type {
|
|
2
|
+
import type { EmittedAsset } from 'rollup';
|
|
3
3
|
import type { ParserOptions } from '@vue/compiler-core';
|
|
4
4
|
import type { CompilerOptions, TemplateCompiler } from '@vue/compiler-sfc';
|
|
5
5
|
import { UniViteCopyPluginOptions } from './plugins/copy';
|
|
@@ -14,14 +14,13 @@ interface UniVitePluginUniOptions {
|
|
|
14
14
|
compiler?: TemplateCompiler;
|
|
15
15
|
compilerOptions?: {
|
|
16
16
|
miniProgram?: {
|
|
17
|
-
emitFile?: (emittedFile:
|
|
17
|
+
emitFile?: (emittedFile: EmittedAsset) => string;
|
|
18
18
|
};
|
|
19
19
|
isNativeTag: ParserOptions['isNativeTag'];
|
|
20
20
|
isCustomElement: ParserOptions['isCustomElement'];
|
|
21
21
|
directiveTransforms?: CompilerOptions['directiveTransforms'];
|
|
22
22
|
nodeTransforms?: CompilerOptions['nodeTransforms'];
|
|
23
23
|
};
|
|
24
|
-
transformEvent?: Record<string, string>;
|
|
25
24
|
copyOptions?: CopyOptions | (() => CopyOptions);
|
|
26
25
|
}
|
|
27
26
|
export interface UniVitePlugin extends Plugin {
|
|
@@ -9,7 +9,7 @@ const debug_1 = __importDefault(require("debug"));
|
|
|
9
9
|
const pluginutils_1 = require("@rollup/pluginutils");
|
|
10
10
|
const estree_walker_1 = require("estree-walker");
|
|
11
11
|
const shared_1 = require("@vue/shared");
|
|
12
|
-
const
|
|
12
|
+
const magic_string_1 = __importDefault(require("magic-string"));
|
|
13
13
|
const utils_1 = require("../utils");
|
|
14
14
|
const debugInject = (0, debug_1.default)('vite:uni:inject');
|
|
15
15
|
const debugInjectTry = (0, debug_1.default)('vite:uni:inject-try');
|
|
@@ -74,7 +74,7 @@ function uniViteInjectPlugin(options) {
|
|
|
74
74
|
});
|
|
75
75
|
// analyse scopes
|
|
76
76
|
let scope = (0, pluginutils_1.attachScopes)(ast, 'scope');
|
|
77
|
-
const magicString = new
|
|
77
|
+
const magicString = new magic_string_1.default(code);
|
|
78
78
|
const newImports = new Map();
|
|
79
79
|
function handleReference(node, name, keypath) {
|
|
80
80
|
let mod = modulesMap.get(keypath);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { ResolvedConfig } from 'vite';
|
|
1
|
+
export type { ResolvedConfig } from 'vite';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { ResolveFn, ViteDevServer } from 'vite';
|
|
1
|
+
export type { ResolveFn, ViteDevServer } from 'vite';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Plugin } from 'vite';
|
|
1
|
+
export type { Plugin } from 'vite';
|
|
@@ -10,7 +10,7 @@ export declare const chunkToEmittedAssetsMap: WeakMap<RenderedChunk, Set<string>
|
|
|
10
10
|
export declare function assetPlugin(config: ResolvedConfig): Plugin;
|
|
11
11
|
export declare function registerAssetToChunk(chunk: RenderedChunk, file: string): void;
|
|
12
12
|
export declare function checkPublicFile(url: string, { publicDir }: ResolvedConfig): string | undefined;
|
|
13
|
-
export declare function fileToUrl(id: string, config: ResolvedConfig, ctx: PluginContext): string;
|
|
13
|
+
export declare function fileToUrl(id: string, config: ResolvedConfig, ctx: PluginContext, canInline?: boolean): string;
|
|
14
14
|
export declare function getAssetFilename(hash: string, config: ResolvedConfig): string | undefined;
|
|
15
15
|
export declare function getAssetHash(content: Buffer): string;
|
|
16
16
|
export declare function urlToBuiltUrl(url: string, importer: string, config: ResolvedConfig, pluginContext: PluginContext): string;
|
|
@@ -25,6 +25,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
25
25
|
exports.urlToBuiltUrl = exports.getAssetHash = exports.getAssetFilename = exports.fileToUrl = exports.checkPublicFile = exports.registerAssetToChunk = exports.assetPlugin = exports.chunkToEmittedAssetsMap = exports.assetUrlRE = void 0;
|
|
26
26
|
const path_1 = __importDefault(require("path"));
|
|
27
27
|
const url_1 = require("url");
|
|
28
|
+
const lite_1 = __importDefault(require("mime/lite"));
|
|
28
29
|
const fs_1 = __importStar(require("fs"));
|
|
29
30
|
const utils_1 = require("../utils");
|
|
30
31
|
const magic_string_1 = __importDefault(require("magic-string"));
|
|
@@ -132,8 +133,8 @@ function checkPublicFile(url, { publicDir }) {
|
|
|
132
133
|
}
|
|
133
134
|
}
|
|
134
135
|
exports.checkPublicFile = checkPublicFile;
|
|
135
|
-
function fileToUrl(id, config, ctx) {
|
|
136
|
-
return fileToBuiltUrl(id, config, ctx);
|
|
136
|
+
function fileToUrl(id, config, ctx, canInline = false) {
|
|
137
|
+
return fileToBuiltUrl(id, config, ctx, false, canInline);
|
|
137
138
|
}
|
|
138
139
|
exports.fileToUrl = fileToUrl;
|
|
139
140
|
function getAssetFilename(hash, config) {
|
|
@@ -145,7 +146,7 @@ exports.getAssetFilename = getAssetFilename;
|
|
|
145
146
|
* Register an asset to be emitted as part of the bundle (if necessary)
|
|
146
147
|
* and returns the resolved public URL
|
|
147
148
|
*/
|
|
148
|
-
function fileToBuiltUrl(id, config, pluginContext, skipPublicCheck = false) {
|
|
149
|
+
function fileToBuiltUrl(id, config, pluginContext, skipPublicCheck = false, canInline = false) {
|
|
149
150
|
if (!skipPublicCheck && checkPublicFile(id, config)) {
|
|
150
151
|
return config.base + id.slice(1);
|
|
151
152
|
}
|
|
@@ -157,27 +158,33 @@ function fileToBuiltUrl(id, config, pluginContext, skipPublicCheck = false) {
|
|
|
157
158
|
const file = (0, utils_1.cleanUrl)(id);
|
|
158
159
|
const content = fs_1.default.readFileSync(file);
|
|
159
160
|
let url;
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const postfix = (search || '') + (hash || '');
|
|
164
|
-
const fileName = (0, utils_1.normalizePath)(path_1.default.posix.relative(process.env.UNI_INPUT_DIR, file));
|
|
165
|
-
if (!map.has(contentHash)) {
|
|
166
|
-
map.set(contentHash, fileName);
|
|
161
|
+
if (canInline && content.length < Number(config.build.assetsInlineLimit)) {
|
|
162
|
+
// base64 inlined as a string
|
|
163
|
+
url = `data:${lite_1.default.getType(file)};base64,${content.toString('base64')}`;
|
|
167
164
|
}
|
|
168
|
-
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
165
|
+
else {
|
|
166
|
+
const map = assetHashToFilenameMap.get(config);
|
|
167
|
+
const contentHash = getAssetHash(content);
|
|
168
|
+
const { search, hash } = (0, url_1.parse)(id);
|
|
169
|
+
const postfix = (search || '') + (hash || '');
|
|
170
|
+
const fileName = (0, utils_1.normalizePath)(path_1.default.posix.relative(process.env.UNI_INPUT_DIR, file));
|
|
171
|
+
if (!map.has(contentHash)) {
|
|
172
|
+
map.set(contentHash, fileName);
|
|
173
|
+
}
|
|
174
|
+
if (!fileName.includes('/static/')) {
|
|
175
|
+
const emittedSet = emittedHashMap.get(config);
|
|
176
|
+
if (!emittedSet.has(contentHash)) {
|
|
177
|
+
pluginContext.emitFile({
|
|
178
|
+
name: fileName,
|
|
179
|
+
fileName,
|
|
180
|
+
type: 'asset',
|
|
181
|
+
source: content,
|
|
182
|
+
});
|
|
183
|
+
emittedSet.add(contentHash);
|
|
184
|
+
}
|
|
178
185
|
}
|
|
186
|
+
url = `__VITE_ASSET__${contentHash}__${postfix ? `$_${postfix}__` : ``}`;
|
|
179
187
|
}
|
|
180
|
-
url = `__VITE_ASSET__${contentHash}__${postfix ? `$_${postfix}__` : ``}`;
|
|
181
188
|
cache.set(id, url);
|
|
182
189
|
return url;
|
|
183
190
|
}
|