@dcloudio/uni-cli-shared 3.0.0-alpha-3021020211012004 → 3.0.0-alpha-3021020211027001

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/dist/constants.d.ts +1 -0
  2. package/dist/constants.js +2 -1
  3. package/dist/easycom.d.ts +3 -0
  4. package/dist/easycom.js +22 -2
  5. package/dist/env/define.d.ts +1 -0
  6. package/dist/env/define.js +4 -0
  7. package/dist/exports.d.ts +1 -0
  8. package/dist/exports.js +8 -0
  9. package/dist/filter.d.ts +16 -0
  10. package/dist/filter.js +60 -0
  11. package/dist/hbx/log.d.ts +1 -0
  12. package/dist/hbx/log.js +10 -1
  13. package/dist/index.d.ts +4 -1
  14. package/dist/index.js +4 -1
  15. package/dist/json/app/pages/nvue.js +1 -1
  16. package/dist/json/manifest.d.ts +1 -1
  17. package/dist/json/manifest.js +9 -3
  18. package/dist/json/mp/index.d.ts +1 -0
  19. package/dist/json/mp/index.js +11 -0
  20. package/dist/json/mp/jsonFile.d.ts +7 -6
  21. package/dist/json/mp/jsonFile.js +56 -13
  22. package/dist/json/mp/pages.d.ts +1 -0
  23. package/dist/json/mp/pages.js +8 -0
  24. package/dist/json/mp/types.d.ts +1 -0
  25. package/dist/json/mp/utils.js +6 -2
  26. package/dist/logs/format.d.ts +1 -0
  27. package/dist/logs/format.js +14 -1
  28. package/dist/logs/index.d.ts +1 -1
  29. package/dist/logs/index.js +2 -1
  30. package/dist/messages/index.d.ts +2 -0
  31. package/dist/messages/index.js +2 -0
  32. package/dist/mp/event.d.ts +5 -0
  33. package/dist/mp/event.js +30 -0
  34. package/dist/mp/imports.d.ts +5 -0
  35. package/dist/mp/imports.js +63 -0
  36. package/dist/mp/index.d.ts +5 -0
  37. package/dist/mp/index.js +19 -0
  38. package/dist/mp/nvue.d.ts +1 -0
  39. package/dist/mp/nvue.js +18 -0
  40. package/dist/mp/style.d.ts +1 -0
  41. package/dist/mp/style.js +10 -0
  42. package/dist/mp/template.d.ts +25 -0
  43. package/dist/mp/template.js +73 -0
  44. package/dist/mp/transformImports.d.ts +14 -0
  45. package/dist/mp/transformImports.js +175 -0
  46. package/dist/postcss/plugins/uniapp.js +1 -1
  47. package/dist/utils.d.ts +4 -1
  48. package/dist/utils.js +31 -7
  49. package/dist/vite/index.d.ts +2 -2
  50. package/dist/vite/plugins/vitejs/plugins/asset.d.ts +1 -1
  51. package/dist/vite/plugins/vitejs/plugins/asset.js +28 -21
  52. package/dist/vite/plugins/vitejs/plugins/css.d.ts +3 -3
  53. package/dist/vite/plugins/vitejs/plugins/css.js +12 -21
  54. package/dist/vite/utils/plugin.d.ts +3 -3
  55. package/dist/vite/utils/plugin.js +2 -2
  56. package/dist/vue/transforms/index.d.ts +2 -0
  57. package/dist/vue/transforms/index.js +14 -0
  58. package/dist/vue/transforms/transformComponent.d.ts +2 -0
  59. package/dist/vue/transforms/transformComponent.js +25 -0
  60. package/dist/vue/transforms/transformPageHead.d.ts +2 -0
  61. package/dist/vue/transforms/transformPageHead.js +7 -0
  62. package/lib/nvue.css +1 -0
  63. package/package.json +6 -4
  64. package/dist/renderjs.d.ts +0 -16
  65. package/dist/renderjs.js +0 -44
@@ -0,0 +1,63 @@
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.findVueComponentImports = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const es_module_lexer_1 = require("es-module-lexer");
9
+ const shared_1 = require("@vue/shared");
10
+ const types_1 = require("@babel/types");
11
+ const parser_1 = require("@babel/parser");
12
+ const constants_1 = require("../constants");
13
+ async function findVueComponentImports(source, importer, resolve) {
14
+ await es_module_lexer_1.init;
15
+ let imports = [];
16
+ // strip UTF-8 BOM
17
+ if (source.charCodeAt(0) === 0xfeff) {
18
+ source = source.slice(1);
19
+ }
20
+ try {
21
+ imports = (0, es_module_lexer_1.parse)(source)[0];
22
+ }
23
+ catch (e) {
24
+ console.error(e);
25
+ }
26
+ if (!imports.length) {
27
+ return [];
28
+ }
29
+ const rewriteImports = [];
30
+ for (let i = 0; i < imports.length; i++) {
31
+ const importSpecifier = imports[i];
32
+ const { n } = importSpecifier;
33
+ if (!n) {
34
+ continue;
35
+ }
36
+ const extname = path_1.default.extname(n);
37
+ // 仅处理没有后缀,或后缀是.vue,.nvue的文件
38
+ if (extname && !constants_1.EXTNAME_VUE.includes(extname)) {
39
+ continue;
40
+ }
41
+ const res = await resolve(n, importer);
42
+ if (!res) {
43
+ continue;
44
+ }
45
+ if (constants_1.EXTNAME_VUE_RE.test(res.id)) {
46
+ const expr = (0, parser_1.parse)(source.slice(importSpecifier.ss, importSpecifier.se), {
47
+ sourceType: 'module',
48
+ }).program.body[0];
49
+ if ((0, types_1.isImportDeclaration)(expr) && expr.specifiers.length === 1) {
50
+ const importDefaultSpecifier = expr.specifiers[0];
51
+ if (!(0, types_1.isImportDefaultSpecifier)(importDefaultSpecifier)) {
52
+ continue;
53
+ }
54
+ rewriteImports.push((0, shared_1.extend)(importSpecifier, {
55
+ n: res.id,
56
+ i: importDefaultSpecifier.local.name,
57
+ }));
58
+ }
59
+ }
60
+ }
61
+ return rewriteImports;
62
+ }
63
+ exports.findVueComponentImports = findVueComponentImports;
@@ -0,0 +1,5 @@
1
+ export * from './nvue';
2
+ export * from './event';
3
+ export * from './style';
4
+ export * from './template';
5
+ export { transformVueComponentImports } from './transformImports';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.transformVueComponentImports = void 0;
14
+ __exportStar(require("./nvue"), exports);
15
+ __exportStar(require("./event"), exports);
16
+ __exportStar(require("./style"), exports);
17
+ __exportStar(require("./template"), exports);
18
+ var transformImports_1 = require("./transformImports");
19
+ Object.defineProperty(exports, "transformVueComponentImports", { enumerable: true, get: function () { return transformImports_1.transformVueComponentImports; } });
@@ -0,0 +1 @@
1
+ export declare function genNVueCssCode(manifestJson: Record<string, any>): string;
@@ -0,0 +1,18 @@
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.genNVueCssCode = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const nvue_1 = require("../json/app/manifest/nvue");
10
+ function genNVueCssCode(manifestJson) {
11
+ let nvueCssCode = fs_1.default.readFileSync(path_1.default.resolve(__dirname, '../../lib/nvue.css'), 'utf8');
12
+ const flexDirection = (0, nvue_1.getNVueFlexDirection)(manifestJson);
13
+ if (flexDirection !== 'column') {
14
+ nvueCssCode = nvueCssCode.replace('column', flexDirection);
15
+ }
16
+ return nvueCssCode;
17
+ }
18
+ exports.genNVueCssCode = genNVueCssCode;
@@ -0,0 +1 @@
1
+ export declare function transformScopedCss(cssCode: string): string;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformScopedCss = void 0;
4
+ const scopedRE = /\[(data-v-[a-f0-9]{8})\]/gi;
5
+ function transformScopedCss(cssCode) {
6
+ return cssCode.replace(scopedRE, (_, scopedId) => {
7
+ return '.' + scopedId;
8
+ });
9
+ }
10
+ exports.transformScopedCss = transformScopedCss;
@@ -0,0 +1,25 @@
1
+ import { EmittedAsset } from 'rollup';
2
+ export interface MiniProgramCompilerOptions {
3
+ slot: {
4
+ fallback: boolean;
5
+ };
6
+ filter?: {
7
+ lang: string;
8
+ };
9
+ directive: string;
10
+ emitFile?: (emittedFile: EmittedAsset) => string;
11
+ }
12
+ export interface MiniProgramFilterOptions {
13
+ id: string;
14
+ type: string;
15
+ name: string;
16
+ src?: string;
17
+ code: string;
18
+ }
19
+ declare type GenFilterFn = (filter: MiniProgramFilterOptions, filename: string) => string | void;
20
+ export declare function findMiniProgramTemplateFiles(genFilter?: GenFilterFn): Record<string, string>;
21
+ export declare function clearMiniProgramTemplateFiles(): void;
22
+ export declare function addMiniProgramTemplateFile(filename: string, code: string): void;
23
+ export declare function clearMiniProgramTemplateFilter(filename: string): void;
24
+ export declare function addMiniProgramTemplateFilter(filename: string, filter: MiniProgramFilterOptions): void;
25
+ export {};
@@ -0,0 +1,73 @@
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.addMiniProgramTemplateFilter = exports.clearMiniProgramTemplateFilter = exports.addMiniProgramTemplateFile = exports.clearMiniProgramTemplateFiles = exports.findMiniProgramTemplateFiles = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const uni_shared_1 = require("@dcloudio/uni-shared");
9
+ const utils_1 = require("../utils");
10
+ const templateFilesCache = new Map();
11
+ const templateFiltersCache = new Map();
12
+ function relativeFilterFilename(filename, filter) {
13
+ if (!filter.src) {
14
+ return '';
15
+ }
16
+ return ('./' +
17
+ (0, utils_1.normalizeMiniProgramFilename)(path_1.default.relative(path_1.default.dirname(filename), filter.src)));
18
+ }
19
+ function findMiniProgramTemplateFiles(genFilter) {
20
+ const files = Object.create(null);
21
+ templateFilesCache.forEach((code, filename) => {
22
+ if (!genFilter) {
23
+ files[filename] = code;
24
+ }
25
+ else {
26
+ const filters = getMiniProgramTemplateFilters(filename);
27
+ if (filters && filters.length) {
28
+ files[filename] =
29
+ filters
30
+ .map((filter) => genFilter(filter, relativeFilterFilename(filename, filter)))
31
+ .join(uni_shared_1.LINEFEED) +
32
+ uni_shared_1.LINEFEED +
33
+ code;
34
+ }
35
+ else {
36
+ files[filename] = code;
37
+ }
38
+ }
39
+ });
40
+ return files;
41
+ }
42
+ exports.findMiniProgramTemplateFiles = findMiniProgramTemplateFiles;
43
+ function clearMiniProgramTemplateFiles() {
44
+ templateFilesCache.clear();
45
+ }
46
+ exports.clearMiniProgramTemplateFiles = clearMiniProgramTemplateFiles;
47
+ function addMiniProgramTemplateFile(filename, code) {
48
+ templateFilesCache.set(filename, code);
49
+ }
50
+ exports.addMiniProgramTemplateFile = addMiniProgramTemplateFile;
51
+ function getMiniProgramTemplateFilters(filename) {
52
+ return templateFiltersCache.get(filename);
53
+ }
54
+ function clearMiniProgramTemplateFilter(filename) {
55
+ templateFiltersCache.delete(filename);
56
+ }
57
+ exports.clearMiniProgramTemplateFilter = clearMiniProgramTemplateFilter;
58
+ function addMiniProgramTemplateFilter(filename, filter) {
59
+ const filters = templateFiltersCache.get(filename);
60
+ if (filters) {
61
+ const filterIndex = filters.findIndex((f) => f.id === filter.id);
62
+ if (filterIndex > -1) {
63
+ filters.splice(filterIndex, 1, filter);
64
+ }
65
+ else {
66
+ filters.push(filter);
67
+ }
68
+ }
69
+ else {
70
+ templateFiltersCache.set(filename, [filter]);
71
+ }
72
+ }
73
+ exports.addMiniProgramTemplateFilter = addMiniProgramTemplateFilter;
@@ -0,0 +1,14 @@
1
+ import { ParserPlugin } from '@babel/parser';
2
+ import { PluginContext } from 'rollup';
3
+ interface TransformVueComponentImportsOptions {
4
+ root: string;
5
+ global?: boolean;
6
+ resolve: PluginContext['resolve'];
7
+ dynamicImport: (name: string, source: string) => string;
8
+ babelParserPlugins?: ParserPlugin[];
9
+ }
10
+ export declare function transformVueComponentImports(code: string, importer: string, { root, resolve, global, dynamicImport, babelParserPlugins, }: TransformVueComponentImportsOptions): Promise<{
11
+ code: string;
12
+ usingComponents: Record<string, string>;
13
+ }>;
14
+ export {};
@@ -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
+ }
@@ -75,7 +75,7 @@ const uniapp = (opts) => {
75
75
  return {
76
76
  OnceExit(root) {
77
77
  root.walkDecls(walkDecls(rpx2unit));
78
- root.walkRules(walkRules(page));
78
+ page && root.walkRules(walkRules(page));
79
79
  },
80
80
  };
81
81
  },
package/dist/utils.d.ts CHANGED
@@ -1,9 +1,12 @@
1
1
  export { default as hash } from 'hash-sum';
2
+ import { SFCTemplateCompileOptions } from '@vue/compiler-sfc';
2
3
  export declare const isWindows: boolean;
3
4
  export declare function normalizePath(id: string): string;
4
5
  export declare const resolveMainPathOnce: (inputDir: string) => string;
5
6
  export declare function resolveBuiltIn(path: string): string;
6
7
  export declare function normalizeIdentifier(str: string): string;
7
8
  export declare function normalizePagePath(pagePath: string, platform: UniApp.PLATFORM): string | undefined;
8
- export declare function removeExt(str: string, ext?: string): string;
9
+ export declare function removeExt(str: string): string;
9
10
  export declare function normalizeNodeModules(str: string): string;
11
+ export declare function normalizeMiniProgramFilename(filename: string, inputDir?: string): string;
12
+ 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.resolveMainPathOnce = 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"));
@@ -47,12 +47,8 @@ function normalizePagePath(pagePath, platform) {
47
47
  console.error(`${pagePath} not found`);
48
48
  }
49
49
  exports.normalizePagePath = normalizePagePath;
50
- function removeExt(str, ext) {
51
- if (ext) {
52
- const reg = new RegExp(ext.replace(/\./, '\\.') + '$');
53
- return normalizePath(str.replace(reg, ''));
54
- }
55
- return normalizePath(str.replace(/\.\w+$/g, ''));
50
+ function removeExt(str) {
51
+ return str.split('?')[0].replace(/\.\w+$/g, '');
56
52
  }
57
53
  exports.removeExt = removeExt;
58
54
  const NODE_MODULES_REGEX = /(\.\.\/)?node_modules/g;
@@ -66,3 +62,31 @@ function normalizeNodeModules(str) {
66
62
  return str;
67
63
  }
68
64
  exports.normalizeNodeModules = normalizeNodeModules;
65
+ function normalizeMiniProgramFilename(filename, inputDir) {
66
+ if (!inputDir || !path_1.default.isAbsolute(filename)) {
67
+ return normalizeNodeModules(filename);
68
+ }
69
+ return normalizeNodeModules(path_1.default.relative(inputDir, filename));
70
+ }
71
+ exports.normalizeMiniProgramFilename = normalizeMiniProgramFilename;
72
+ function createUniVueTransformAssetUrls(base) {
73
+ return {
74
+ base,
75
+ tags: {
76
+ audio: ['src'],
77
+ video: ['src', 'poster'],
78
+ img: ['src'],
79
+ image: ['src'],
80
+ 'cover-image': ['src'],
81
+ // h5
82
+ 'v-uni-audio': ['src'],
83
+ 'v-uni-video': ['src', 'poster'],
84
+ 'v-uni-image': ['src'],
85
+ 'v-uni-cover-image': ['src'],
86
+ // nvue
87
+ 'u-image': ['src'],
88
+ 'u-video': ['src', 'poster'],
89
+ },
90
+ };
91
+ }
92
+ exports.createUniVueTransformAssetUrls = createUniVueTransformAssetUrls;
@@ -1,5 +1,5 @@
1
1
  import type { Plugin } from 'vite';
2
- import type { EmittedFile } from 'rollup';
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,7 +14,7 @@ interface UniVitePluginUniOptions {
14
14
  compiler?: TemplateCompiler;
15
15
  compilerOptions?: {
16
16
  miniProgram?: {
17
- emitFile?: (emittedFile: EmittedFile) => string;
17
+ emitFile?: (emittedFile: EmittedAsset) => string;
18
18
  };
19
19
  isNativeTag: ParserOptions['isNativeTag'];
20
20
  isCustomElement: ParserOptions['isCustomElement'];
@@ -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
- const map = assetHashToFilenameMap.get(config);
161
- const contentHash = getAssetHash(content);
162
- const { search, hash } = (0, url_1.parse)(id);
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
- if (!fileName.includes('/static/')) {
169
- const emittedSet = emittedHashMap.get(config);
170
- if (!emittedSet.has(contentHash)) {
171
- pluginContext.emitFile({
172
- name: fileName,
173
- fileName,
174
- type: 'asset',
175
- source: content,
176
- });
177
- emittedSet.add(contentHash);
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
  }
@@ -33,9 +33,9 @@ export declare function cssPlugin(config: ResolvedConfig): Plugin;
33
33
  /**
34
34
  * Plugin applied after user plugins
35
35
  */
36
- export declare function cssPostPlugin(config: ResolvedConfig, { appCss, extname }: {
37
- appCss?: string;
38
- extname: string;
36
+ export declare function cssPostPlugin(config: ResolvedConfig, { chunkCssFilename, chunkCssCode, }: {
37
+ chunkCssFilename: (id: string) => string | void;
38
+ chunkCssCode: (filename: string, cssCode: string) => string;
39
39
  }): Plugin;
40
40
  export declare const cssUrlRE: RegExp;
41
41
  export interface StylePreprocessorResults {