@dcloudio/uni-cli-shared 3.0.0-alpha-3021320211122001 → 3.0.0-alpha-3030020211125001
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/hbx/alias.js +1 -1
- package/dist/json/pages.js +1 -1
- package/dist/mp/constants.d.ts +2 -0
- package/dist/mp/constants.js +3 -1
- package/dist/mp/template.d.ts +6 -0
- package/dist/mp/transformImports.js +2 -2
- package/dist/utils.d.ts +0 -2
- package/dist/utils.js +1 -22
- package/dist/vite/plugins/inject.js +4 -1
- package/dist/vite/plugins/vitejs/plugins/css.d.ts +0 -1
- package/dist/vite/plugins/vitejs/plugins/css.js +1 -2
- package/dist/vite/utils/plugin.d.ts +0 -3
- package/dist/vite/utils/plugin.js +1 -15
- package/dist/vue/index.d.ts +1 -0
- package/dist/vue/index.js +3 -0
- package/dist/vue/transforms/index.d.ts +2 -0
- package/dist/vue/transforms/index.js +5 -1
- package/dist/vue/transforms/templateTransformAssetUrl.d.ts +33 -0
- package/dist/vue/transforms/templateTransformAssetUrl.js +150 -0
- package/dist/vue/transforms/templateTransformSrcset.d.ts +4 -0
- package/dist/vue/transforms/templateTransformSrcset.js +122 -0
- package/dist/vue/transforms/templateUtils.d.ts +9 -0
- package/dist/vue/transforms/templateUtils.js +41 -0
- package/dist/vue/utils.d.ts +21 -1
- package/dist/vue/utils.js +33 -1
- package/package.json +5 -5
- package/dist/vite/plugins/vitejs/plugins/h5Asset.d.ts +0 -40
- package/dist/vite/plugins/vitejs/plugins/h5Asset.js +0 -319
- package/dist/vite/plugins/vitejs/plugins/h5Css.d.ts +0 -67
- package/dist/vite/plugins/vitejs/plugins/h5Css.js +0 -922
package/dist/hbx/alias.js
CHANGED
|
@@ -23,7 +23,7 @@ function initModuleAlias() {
|
|
|
23
23
|
}
|
|
24
24
|
exports.initModuleAlias = initModuleAlias;
|
|
25
25
|
function supportAutoInstallPlugin() {
|
|
26
|
-
return
|
|
26
|
+
return !!process.env.HX_Version;
|
|
27
27
|
}
|
|
28
28
|
function installHBuilderXPlugin(plugin) {
|
|
29
29
|
if (!supportAutoInstallPlugin()) {
|
package/dist/json/pages.js
CHANGED
|
@@ -284,7 +284,7 @@ const DATA_RE = /^data:.*,.*/;
|
|
|
284
284
|
function normalizeFilepath(filepath) {
|
|
285
285
|
if (!(SCHEME_RE.test(filepath) || DATA_RE.test(filepath)) &&
|
|
286
286
|
filepath.indexOf('/') !== 0) {
|
|
287
|
-
return
|
|
287
|
+
return (0, uni_shared_1.addLeadingSlash)(filepath);
|
|
288
288
|
}
|
|
289
289
|
return filepath;
|
|
290
290
|
}
|
package/dist/mp/constants.d.ts
CHANGED
package/dist/mp/constants.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.COMPONENT_BIND_LINK = exports.COMPONENT_ON_LINK = void 0;
|
|
3
|
+
exports.COMPONENT_CUSTOM_HIDDEN_BIND = exports.COMPONENT_CUSTOM_HIDDEN = exports.COMPONENT_BIND_LINK = exports.COMPONENT_ON_LINK = void 0;
|
|
4
4
|
exports.COMPONENT_ON_LINK = 'onVI';
|
|
5
5
|
exports.COMPONENT_BIND_LINK = '__l';
|
|
6
|
+
exports.COMPONENT_CUSTOM_HIDDEN = 'data-c-h';
|
|
7
|
+
exports.COMPONENT_CUSTOM_HIDDEN_BIND = 'bind:-' + exports.COMPONENT_CUSTOM_HIDDEN;
|
package/dist/mp/template.d.ts
CHANGED
|
@@ -39,6 +39,12 @@ export interface MiniProgramCompilerOptions {
|
|
|
39
39
|
filter?: {
|
|
40
40
|
lang: string;
|
|
41
41
|
};
|
|
42
|
+
component?: {
|
|
43
|
+
/**
|
|
44
|
+
* 自定义组件自定义 hidden 属性用于实现 v-show
|
|
45
|
+
*/
|
|
46
|
+
vShow: string;
|
|
47
|
+
};
|
|
42
48
|
directive: string;
|
|
43
49
|
emitFile?: (emittedFile: EmittedAsset) => string;
|
|
44
50
|
}
|
|
@@ -12,6 +12,7 @@ const magic_string_1 = __importDefault(require("magic-string"));
|
|
|
12
12
|
const messages_1 = require("../messages");
|
|
13
13
|
const constants_1 = require("../constants");
|
|
14
14
|
const utils_1 = require("../utils");
|
|
15
|
+
const uni_shared_1 = require("@dcloudio/uni-shared");
|
|
15
16
|
async function transformVueComponentImports(code, importer, { root, resolve, global, dynamicImport, babelParserPlugins, }) {
|
|
16
17
|
if (!global && !code.includes(constants_1.BINDING_COMPONENTS)) {
|
|
17
18
|
return { code, usingComponents: {} };
|
|
@@ -32,8 +33,7 @@ async function transformVueComponentImports(code, importer, { root, resolve, glo
|
|
|
32
33
|
s.overwrite(start, end, dynamicImport(specifier.local.name, resolveId.id) + ';');
|
|
33
34
|
const componentName = (0, shared_1.hyphenate)(tag);
|
|
34
35
|
if (!usingComponents[componentName]) {
|
|
35
|
-
usingComponents[componentName] =
|
|
36
|
-
'/' + (0, utils_1.removeExt)((0, utils_1.normalizeMiniProgramFilename)(resolveId.id, root));
|
|
36
|
+
usingComponents[componentName] = (0, uni_shared_1.addLeadingSlash)((0, utils_1.removeExt)((0, utils_1.normalizeMiniProgramFilename)(resolveId.id, root)));
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { default as hash } from 'hash-sum';
|
|
2
|
-
import type { SFCTemplateCompileOptions } from '@vue/compiler-sfc';
|
|
3
2
|
import { ElementNode, RootNode, TemplateChildNode } from '@vue/compiler-core';
|
|
4
3
|
export declare let isRunningWithYarnPnp: boolean;
|
|
5
4
|
export declare const isWindows: boolean;
|
|
@@ -10,4 +9,3 @@ export declare function normalizePagePath(pagePath: string, platform: UniApp.PLA
|
|
|
10
9
|
export declare function removeExt(str: string): string;
|
|
11
10
|
export declare function normalizeNodeModules(str: string): string;
|
|
12
11
|
export declare function normalizeMiniProgramFilename(filename: string, inputDir?: string): string;
|
|
13
|
-
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.
|
|
6
|
+
exports.normalizeMiniProgramFilename = exports.normalizeNodeModules = exports.removeExt = exports.normalizePagePath = exports.normalizeIdentifier = exports.checkElementNodeTag = exports.normalizePath = exports.isWindows = exports.isRunningWithYarnPnp = 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"));
|
|
@@ -65,24 +65,3 @@ function normalizeMiniProgramFilename(filename, inputDir) {
|
|
|
65
65
|
return normalizeNodeModules(path_1.default.relative(inputDir, filename));
|
|
66
66
|
}
|
|
67
67
|
exports.normalizeMiniProgramFilename = normalizeMiniProgramFilename;
|
|
68
|
-
function createUniVueTransformAssetUrls(base) {
|
|
69
|
-
return {
|
|
70
|
-
base,
|
|
71
|
-
tags: {
|
|
72
|
-
audio: ['src'],
|
|
73
|
-
video: ['src', 'poster'],
|
|
74
|
-
img: ['src'],
|
|
75
|
-
image: ['src'],
|
|
76
|
-
'cover-image': ['src'],
|
|
77
|
-
// h5
|
|
78
|
-
'v-uni-audio': ['src'],
|
|
79
|
-
'v-uni-video': ['src', 'poster'],
|
|
80
|
-
'v-uni-image': ['src'],
|
|
81
|
-
'v-uni-cover-image': ['src'],
|
|
82
|
-
// nvue
|
|
83
|
-
'u-image': ['src'],
|
|
84
|
-
'u-video': ['src', 'poster'],
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
exports.createUniVueTransformAssetUrls = createUniVueTransformAssetUrls;
|
|
@@ -165,7 +165,10 @@ function uniViteInjectPlugin(options) {
|
|
|
165
165
|
if (newImports.size === 0) {
|
|
166
166
|
return {
|
|
167
167
|
code,
|
|
168
|
-
ast
|
|
168
|
+
// 不能返回 ast ,否则会导致代码不能被再次修改
|
|
169
|
+
// 比如 App.vue 中,console.log('uniCloud') 触发了 inject 检测,检测完,发现不需要
|
|
170
|
+
// 此时返回 ast,会导致 import { setupApp } from '@dcloudio/uni-h5' 不会被编译
|
|
171
|
+
// ast
|
|
169
172
|
map: sourceMap ? magicString.generateMap({ hires: true }) : null,
|
|
170
173
|
};
|
|
171
174
|
}
|
|
@@ -22,7 +22,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.
|
|
25
|
+
exports.cssUrlRE = exports.cssPostPlugin = exports.cssPlugin = exports.isDirectCSSRequest = exports.isCSSRequest = exports.cssLangRE = void 0;
|
|
26
26
|
const fs_1 = __importDefault(require("fs"));
|
|
27
27
|
const path_1 = __importDefault(require("path"));
|
|
28
28
|
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
@@ -602,7 +602,6 @@ function preprocessCss(content) {
|
|
|
602
602
|
}
|
|
603
603
|
return content;
|
|
604
604
|
}
|
|
605
|
-
exports.preprocessCss = preprocessCss;
|
|
606
605
|
/**
|
|
607
606
|
* relative url() inside \@imported sass and less files must be rebased to use
|
|
608
607
|
* root file as base.
|
|
@@ -4,9 +4,6 @@ export interface UniViteFilterPluginOptions {
|
|
|
4
4
|
resolvedConfig: ResolvedConfig;
|
|
5
5
|
filter: (id: string) => boolean;
|
|
6
6
|
}
|
|
7
|
-
export declare function injectH5AssetPlugin(config: ResolvedConfig): void;
|
|
8
|
-
export declare function injectH5CssPlugin(config: ResolvedConfig): void;
|
|
9
|
-
export declare function injectH5CssPostPlugin(config: ResolvedConfig): void;
|
|
10
7
|
export declare function injectAssetPlugin(config: ResolvedConfig): void;
|
|
11
8
|
export declare function injectCssPlugin(config: ResolvedConfig): void;
|
|
12
9
|
export declare function injectCssPostPlugin(config: ResolvedConfig, { chunkCssFilename, chunkCssCode, }: {
|
|
@@ -1,22 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.removePlugins = exports.replacePlugins = exports.injectCssPostPlugin = exports.injectCssPlugin = exports.injectAssetPlugin =
|
|
3
|
+
exports.removePlugins = exports.replacePlugins = exports.injectCssPostPlugin = exports.injectCssPlugin = exports.injectAssetPlugin = void 0;
|
|
4
4
|
const asset_1 = require("../plugins/vitejs/plugins/asset");
|
|
5
5
|
const css_1 = require("../plugins/vitejs/plugins/css");
|
|
6
|
-
const h5Asset_1 = require("../plugins/vitejs/plugins/h5Asset");
|
|
7
|
-
const h5Css_1 = require("../plugins/vitejs/plugins/h5Css");
|
|
8
|
-
function injectH5AssetPlugin(config) {
|
|
9
|
-
replacePlugins([(0, h5Asset_1.assetPlugin)(config)], config);
|
|
10
|
-
}
|
|
11
|
-
exports.injectH5AssetPlugin = injectH5AssetPlugin;
|
|
12
|
-
function injectH5CssPlugin(config) {
|
|
13
|
-
replacePlugins([(0, h5Css_1.cssPlugin)(config)], config);
|
|
14
|
-
}
|
|
15
|
-
exports.injectH5CssPlugin = injectH5CssPlugin;
|
|
16
|
-
function injectH5CssPostPlugin(config) {
|
|
17
|
-
replacePlugins([(0, h5Css_1.cssPostPlugin)(config)], config);
|
|
18
|
-
}
|
|
19
|
-
exports.injectH5CssPostPlugin = injectH5CssPostPlugin;
|
|
20
6
|
function injectAssetPlugin(config) {
|
|
21
7
|
replacePlugins([(0, asset_1.assetPlugin)(config)], config);
|
|
22
8
|
}
|
package/dist/vue/index.d.ts
CHANGED
package/dist/vue/index.js
CHANGED
|
@@ -10,5 +10,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.isExternalUrl = void 0;
|
|
13
14
|
__exportStar(require("./transforms"), exports);
|
|
14
15
|
__exportStar(require("./utils"), exports);
|
|
16
|
+
var templateUtils_1 = require("./transforms/templateUtils");
|
|
17
|
+
Object.defineProperty(exports, "isExternalUrl", { enumerable: true, get: function () { return templateUtils_1.isExternalUrl; } });
|
|
@@ -3,6 +3,8 @@ export * from './transformPageHead';
|
|
|
3
3
|
export * from './transformComponent';
|
|
4
4
|
export * from './transformEvent';
|
|
5
5
|
export * from './transformTag';
|
|
6
|
+
export { createAssetUrlTransformWithOptions } from './templateTransformAssetUrl';
|
|
7
|
+
export { createSrcsetTransformWithOptions } from './templateTransformSrcset';
|
|
6
8
|
export { ATTR_DATASET_EVENT_OPTS, createTransformOn, defaultMatch as matchTransformOn, } from './vOn';
|
|
7
9
|
export { createTransformModel, defaultMatch as matchTransformModel, } from './vModel';
|
|
8
10
|
export declare const transformMatchMedia: import("@vue/compiler-core").NodeTransform;
|
|
@@ -10,7 +10,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.transformComponentLink = exports.transformTapToClick = exports.transformMatchMedia = exports.matchTransformModel = exports.createTransformModel = exports.matchTransformOn = exports.createTransformOn = exports.ATTR_DATASET_EVENT_OPTS = void 0;
|
|
13
|
+
exports.transformComponentLink = exports.transformTapToClick = exports.transformMatchMedia = exports.matchTransformModel = exports.createTransformModel = exports.matchTransformOn = exports.createTransformOn = exports.ATTR_DATASET_EVENT_OPTS = exports.createSrcsetTransformWithOptions = exports.createAssetUrlTransformWithOptions = void 0;
|
|
14
14
|
const transformTag_1 = require("./transformTag");
|
|
15
15
|
const transformEvent_1 = require("./transformEvent");
|
|
16
16
|
const transformComponent_1 = require("./transformComponent");
|
|
@@ -20,6 +20,10 @@ __exportStar(require("./transformPageHead"), exports);
|
|
|
20
20
|
__exportStar(require("./transformComponent"), exports);
|
|
21
21
|
__exportStar(require("./transformEvent"), exports);
|
|
22
22
|
__exportStar(require("./transformTag"), exports);
|
|
23
|
+
var templateTransformAssetUrl_1 = require("./templateTransformAssetUrl");
|
|
24
|
+
Object.defineProperty(exports, "createAssetUrlTransformWithOptions", { enumerable: true, get: function () { return templateTransformAssetUrl_1.createAssetUrlTransformWithOptions; } });
|
|
25
|
+
var templateTransformSrcset_1 = require("./templateTransformSrcset");
|
|
26
|
+
Object.defineProperty(exports, "createSrcsetTransformWithOptions", { enumerable: true, get: function () { return templateTransformSrcset_1.createSrcsetTransformWithOptions; } });
|
|
23
27
|
var vOn_1 = require("./vOn");
|
|
24
28
|
Object.defineProperty(exports, "ATTR_DATASET_EVENT_OPTS", { enumerable: true, get: function () { return vOn_1.ATTR_DATASET_EVENT_OPTS; } });
|
|
25
29
|
Object.defineProperty(exports, "createTransformOn", { enumerable: true, get: function () { return vOn_1.createTransformOn; } });
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { NodeTransform } from '@vue/compiler-core';
|
|
2
|
+
export interface AssetURLTagConfig {
|
|
3
|
+
[name: string]: string[];
|
|
4
|
+
}
|
|
5
|
+
export interface AssetURLOptions {
|
|
6
|
+
/**
|
|
7
|
+
* If base is provided, instead of transforming relative asset urls into
|
|
8
|
+
* imports, they will be directly rewritten to absolute urls.
|
|
9
|
+
*/
|
|
10
|
+
base?: string | null;
|
|
11
|
+
/**
|
|
12
|
+
* If true, also processes absolute urls.
|
|
13
|
+
*/
|
|
14
|
+
includeAbsolute?: boolean;
|
|
15
|
+
tags?: AssetURLTagConfig;
|
|
16
|
+
}
|
|
17
|
+
export declare const defaultAssetUrlOptions: Required<AssetURLOptions>;
|
|
18
|
+
export declare const normalizeOptions: (options: AssetURLOptions | AssetURLTagConfig) => Required<AssetURLOptions>;
|
|
19
|
+
export declare const createAssetUrlTransformWithOptions: (options: Required<AssetURLOptions>) => NodeTransform;
|
|
20
|
+
/**
|
|
21
|
+
* A `@vue/compiler-core` plugin that transforms relative asset urls into
|
|
22
|
+
* either imports or absolute urls.
|
|
23
|
+
*
|
|
24
|
+
* ``` js
|
|
25
|
+
* // Before
|
|
26
|
+
* createVNode('img', { src: './logo.png' })
|
|
27
|
+
*
|
|
28
|
+
* // After
|
|
29
|
+
* import _imports_0 from './logo.png'
|
|
30
|
+
* createVNode('img', { src: _imports_0 })
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare const transformAssetUrl: NodeTransform;
|
|
@@ -0,0 +1,150 @@
|
|
|
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.transformAssetUrl = exports.createAssetUrlTransformWithOptions = exports.normalizeOptions = exports.defaultAssetUrlOptions = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const compiler_core_1 = require("@vue/compiler-core");
|
|
9
|
+
const templateUtils_1 = require("./templateUtils");
|
|
10
|
+
const shared_1 = require("@vue/shared");
|
|
11
|
+
exports.defaultAssetUrlOptions = {
|
|
12
|
+
base: null,
|
|
13
|
+
includeAbsolute: false,
|
|
14
|
+
tags: {
|
|
15
|
+
video: ['src', 'poster'],
|
|
16
|
+
source: ['src'],
|
|
17
|
+
img: ['src'],
|
|
18
|
+
image: ['xlink:href', 'href'],
|
|
19
|
+
use: ['xlink:href', 'href'],
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
const normalizeOptions = (options) => {
|
|
23
|
+
if (Object.keys(options).some((key) => (0, shared_1.isArray)(options[key]))) {
|
|
24
|
+
// legacy option format which directly passes in tags config
|
|
25
|
+
return {
|
|
26
|
+
...exports.defaultAssetUrlOptions,
|
|
27
|
+
tags: options,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
...exports.defaultAssetUrlOptions,
|
|
32
|
+
...options,
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
exports.normalizeOptions = normalizeOptions;
|
|
36
|
+
const createAssetUrlTransformWithOptions = (options) => {
|
|
37
|
+
return (node, context) => exports.transformAssetUrl(node, context, options);
|
|
38
|
+
};
|
|
39
|
+
exports.createAssetUrlTransformWithOptions = createAssetUrlTransformWithOptions;
|
|
40
|
+
/**
|
|
41
|
+
* A `@vue/compiler-core` plugin that transforms relative asset urls into
|
|
42
|
+
* either imports or absolute urls.
|
|
43
|
+
*
|
|
44
|
+
* ``` js
|
|
45
|
+
* // Before
|
|
46
|
+
* createVNode('img', { src: './logo.png' })
|
|
47
|
+
*
|
|
48
|
+
* // After
|
|
49
|
+
* import _imports_0 from './logo.png'
|
|
50
|
+
* createVNode('img', { src: _imports_0 })
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
const transformAssetUrl = (node, context, options = exports.defaultAssetUrlOptions) => {
|
|
54
|
+
if (node.type === 1 /* ELEMENT */) {
|
|
55
|
+
if (!node.props.length) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const tags = options.tags || exports.defaultAssetUrlOptions.tags;
|
|
59
|
+
const attrs = tags[node.tag];
|
|
60
|
+
const wildCardAttrs = tags['*'];
|
|
61
|
+
if (!attrs && !wildCardAttrs) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
// 策略:
|
|
65
|
+
// h5 平台保留原始策略
|
|
66
|
+
// 非 h5 平台
|
|
67
|
+
// - 绝对路径 static 资源不做转换
|
|
68
|
+
// - 相对路径 static 资源转换为绝对路径
|
|
69
|
+
// - 非 static 资源转换为 import
|
|
70
|
+
const assetAttrs = (attrs || []).concat(wildCardAttrs || []);
|
|
71
|
+
node.props.forEach((attr, index) => {
|
|
72
|
+
if (attr.type !== 6 /* ATTRIBUTE */ ||
|
|
73
|
+
!assetAttrs.includes(attr.name) ||
|
|
74
|
+
!attr.value ||
|
|
75
|
+
(0, templateUtils_1.isExternalUrl)(attr.value.content) ||
|
|
76
|
+
(0, templateUtils_1.isDataUrl)(attr.value.content) ||
|
|
77
|
+
attr.value.content[0] === '#') {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
// fixed by xxxxxx 区分 static 资源
|
|
81
|
+
const isStaticAsset = attr.value.content.indexOf('/static/') > -1;
|
|
82
|
+
// 绝对路径的静态资源不作处理
|
|
83
|
+
if (isStaticAsset && !(0, templateUtils_1.isRelativeUrl)(attr.value.content)) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const url = (0, templateUtils_1.parseUrl)(attr.value.content);
|
|
87
|
+
if (options.base && attr.value.content[0] === '.' && isStaticAsset) {
|
|
88
|
+
// explicit base - directly rewrite relative urls into absolute url
|
|
89
|
+
// to avoid generating extra imports
|
|
90
|
+
// Allow for full hostnames provided in options.base
|
|
91
|
+
const base = (0, templateUtils_1.parseUrl)(options.base);
|
|
92
|
+
const protocol = base.protocol || '';
|
|
93
|
+
const host = base.host ? protocol + '//' + base.host : '';
|
|
94
|
+
const basePath = base.path || '/';
|
|
95
|
+
// when packaged in the browser, path will be using the posix-
|
|
96
|
+
// only version provided by rollup-plugin-node-builtins.
|
|
97
|
+
attr.value.content =
|
|
98
|
+
host +
|
|
99
|
+
(path_1.default.posix || path_1.default).join(basePath, url.path + (url.hash || ''));
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
// otherwise, transform the url into an import.
|
|
103
|
+
// this assumes a bundler will resolve the import into the correct
|
|
104
|
+
// absolute url (e.g. webpack file-loader)
|
|
105
|
+
const exp = getImportsExpressionExp(url.path, url.hash, attr.loc, context);
|
|
106
|
+
node.props[index] = {
|
|
107
|
+
type: 7 /* DIRECTIVE */,
|
|
108
|
+
name: 'bind',
|
|
109
|
+
arg: (0, compiler_core_1.createSimpleExpression)(attr.name, true, attr.loc),
|
|
110
|
+
exp,
|
|
111
|
+
modifiers: [],
|
|
112
|
+
loc: attr.loc,
|
|
113
|
+
};
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
exports.transformAssetUrl = transformAssetUrl;
|
|
118
|
+
function getImportsExpressionExp(path, hash, loc, context) {
|
|
119
|
+
if (path) {
|
|
120
|
+
let name;
|
|
121
|
+
let exp;
|
|
122
|
+
const existingIndex = context.imports.findIndex((i) => i.path === path);
|
|
123
|
+
if (existingIndex > -1) {
|
|
124
|
+
name = `_imports_${existingIndex}`;
|
|
125
|
+
exp = context.imports[existingIndex].exp;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
name = `_imports_${context.imports.length}`;
|
|
129
|
+
exp = (0, compiler_core_1.createSimpleExpression)(name, false, loc, 2 /* CAN_HOIST */);
|
|
130
|
+
context.imports.push({ exp, path });
|
|
131
|
+
}
|
|
132
|
+
if (!hash) {
|
|
133
|
+
return exp;
|
|
134
|
+
}
|
|
135
|
+
const hashExp = `${name} + '${hash}'`;
|
|
136
|
+
const existingHoistIndex = context.hoists.findIndex((h) => {
|
|
137
|
+
return (h &&
|
|
138
|
+
h.type === 4 /* SIMPLE_EXPRESSION */ &&
|
|
139
|
+
!h.isStatic &&
|
|
140
|
+
h.content === hashExp);
|
|
141
|
+
});
|
|
142
|
+
if (existingHoistIndex > -1) {
|
|
143
|
+
return (0, compiler_core_1.createSimpleExpression)(`_hoisted_${existingHoistIndex + 1}`, false, loc, 2 /* CAN_HOIST */);
|
|
144
|
+
}
|
|
145
|
+
return context.hoist((0, compiler_core_1.createSimpleExpression)(hashExp, false, loc, 2 /* CAN_HOIST */));
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
return (0, compiler_core_1.createSimpleExpression)(`''`, false, loc, 2 /* CAN_HOIST */);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { NodeTransform } from '@vue/compiler-core';
|
|
2
|
+
import { AssetURLOptions } from './templateTransformAssetUrl';
|
|
3
|
+
export declare const createSrcsetTransformWithOptions: (options: Required<AssetURLOptions>) => NodeTransform;
|
|
4
|
+
export declare const transformSrcset: NodeTransform;
|
|
@@ -0,0 +1,122 @@
|
|
|
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.transformSrcset = exports.createSrcsetTransformWithOptions = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const compiler_core_1 = require("@vue/compiler-core");
|
|
9
|
+
const templateUtils_1 = require("./templateUtils");
|
|
10
|
+
const templateTransformAssetUrl_1 = require("./templateTransformAssetUrl");
|
|
11
|
+
const srcsetTags = ['img', 'source'];
|
|
12
|
+
// http://w3c.github.io/html/semantics-embedded-content.html#ref-for-image-candidate-string-5
|
|
13
|
+
const escapedSpaceCharacters = /( |\\t|\\n|\\f|\\r)+/g;
|
|
14
|
+
const createSrcsetTransformWithOptions = (options) => {
|
|
15
|
+
return (node, context) => exports.transformSrcset(node, context, options);
|
|
16
|
+
};
|
|
17
|
+
exports.createSrcsetTransformWithOptions = createSrcsetTransformWithOptions;
|
|
18
|
+
const transformSrcset = (node, context, options = templateTransformAssetUrl_1.defaultAssetUrlOptions) => {
|
|
19
|
+
if (node.type === 1 /* ELEMENT */) {
|
|
20
|
+
if (srcsetTags.includes(node.tag) && node.props.length) {
|
|
21
|
+
node.props.forEach((attr, index) => {
|
|
22
|
+
if (attr.name === 'srcset' && attr.type === 6 /* ATTRIBUTE */) {
|
|
23
|
+
if (!attr.value)
|
|
24
|
+
return;
|
|
25
|
+
const value = attr.value.content;
|
|
26
|
+
if (!value)
|
|
27
|
+
return;
|
|
28
|
+
const imageCandidates = value
|
|
29
|
+
.split(',')
|
|
30
|
+
.map((s) => {
|
|
31
|
+
// The attribute value arrives here with all whitespace, except
|
|
32
|
+
// normal spaces, represented by escape sequences
|
|
33
|
+
const [url, descriptor] = s
|
|
34
|
+
.replace(escapedSpaceCharacters, ' ')
|
|
35
|
+
.trim()
|
|
36
|
+
.split(' ', 2);
|
|
37
|
+
return { url, descriptor };
|
|
38
|
+
});
|
|
39
|
+
// data urls contains comma after the ecoding so we need to re-merge
|
|
40
|
+
// them
|
|
41
|
+
for (let i = 0; i < imageCandidates.length; i++) {
|
|
42
|
+
const { url } = imageCandidates[i];
|
|
43
|
+
if ((0, templateUtils_1.isDataUrl)(url)) {
|
|
44
|
+
imageCandidates[i + 1].url =
|
|
45
|
+
url + ',' + imageCandidates[i + 1].url;
|
|
46
|
+
imageCandidates.splice(i, 1);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const hasQualifiedUrl = imageCandidates.some(({ url }) => {
|
|
50
|
+
return (!(0, templateUtils_1.isExternalUrl)(url) &&
|
|
51
|
+
!(0, templateUtils_1.isDataUrl)(url) &&
|
|
52
|
+
(options.includeAbsolute || (0, templateUtils_1.isRelativeUrl)(url)));
|
|
53
|
+
});
|
|
54
|
+
// When srcset does not contain any qualified URLs, skip transforming
|
|
55
|
+
if (!hasQualifiedUrl) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (options.base) {
|
|
59
|
+
const base = options.base;
|
|
60
|
+
const set = [];
|
|
61
|
+
imageCandidates.forEach(({ url, descriptor }) => {
|
|
62
|
+
descriptor = descriptor ? ` ${descriptor}` : ``;
|
|
63
|
+
if ((0, templateUtils_1.isRelativeUrl)(url)) {
|
|
64
|
+
set.push((path_1.default.posix || path_1.default).join(base, url) + descriptor);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
set.push(url + descriptor);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
attr.value.content = set.join(', ');
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const compoundExpression = (0, compiler_core_1.createCompoundExpression)([], attr.loc);
|
|
74
|
+
imageCandidates.forEach(({ url, descriptor }, index) => {
|
|
75
|
+
if (!(0, templateUtils_1.isExternalUrl)(url) &&
|
|
76
|
+
!(0, templateUtils_1.isDataUrl)(url) &&
|
|
77
|
+
(options.includeAbsolute || (0, templateUtils_1.isRelativeUrl)(url))) {
|
|
78
|
+
const { path } = (0, templateUtils_1.parseUrl)(url);
|
|
79
|
+
let exp;
|
|
80
|
+
if (path) {
|
|
81
|
+
const existingImportsIndex = context.imports.findIndex((i) => i.path === path);
|
|
82
|
+
if (existingImportsIndex > -1) {
|
|
83
|
+
exp = (0, compiler_core_1.createSimpleExpression)(`_imports_${existingImportsIndex}`, false, attr.loc, 2 /* CAN_HOIST */);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
exp = (0, compiler_core_1.createSimpleExpression)(`_imports_${context.imports.length}`, false, attr.loc, 2 /* CAN_HOIST */);
|
|
87
|
+
context.imports.push({ exp, path });
|
|
88
|
+
}
|
|
89
|
+
compoundExpression.children.push(exp);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
const exp = (0, compiler_core_1.createSimpleExpression)(`"${url}"`, false, attr.loc, 2 /* CAN_HOIST */);
|
|
94
|
+
compoundExpression.children.push(exp);
|
|
95
|
+
}
|
|
96
|
+
const isNotLast = imageCandidates.length - 1 > index;
|
|
97
|
+
if (descriptor && isNotLast) {
|
|
98
|
+
compoundExpression.children.push(` + ' ${descriptor}, ' + `);
|
|
99
|
+
}
|
|
100
|
+
else if (descriptor) {
|
|
101
|
+
compoundExpression.children.push(` + ' ${descriptor}'`);
|
|
102
|
+
}
|
|
103
|
+
else if (isNotLast) {
|
|
104
|
+
compoundExpression.children.push(` + ', ' + `);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
const hoisted = context.hoist(compoundExpression);
|
|
108
|
+
hoisted.constType = 2 /* CAN_HOIST */;
|
|
109
|
+
node.props[index] = {
|
|
110
|
+
type: 7 /* DIRECTIVE */,
|
|
111
|
+
name: 'bind',
|
|
112
|
+
arg: (0, compiler_core_1.createSimpleExpression)('srcset', true, attr.loc),
|
|
113
|
+
exp: hoisted,
|
|
114
|
+
modifiers: [],
|
|
115
|
+
loc: attr.loc,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
exports.transformSrcset = transformSrcset;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { UrlWithStringQuery } from 'url';
|
|
3
|
+
export declare function isRelativeUrl(url: string): boolean;
|
|
4
|
+
export declare function isExternalUrl(url: string): boolean;
|
|
5
|
+
export declare function isDataUrl(url: string): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Parses string url into URL object.
|
|
8
|
+
*/
|
|
9
|
+
export declare function parseUrl(url: string): UrlWithStringQuery;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseUrl = exports.isDataUrl = exports.isExternalUrl = exports.isRelativeUrl = void 0;
|
|
4
|
+
const url_1 = require("url");
|
|
5
|
+
const shared_1 = require("@vue/shared");
|
|
6
|
+
function isRelativeUrl(url) {
|
|
7
|
+
const firstChar = url.charAt(0);
|
|
8
|
+
return firstChar === '.' || firstChar === '~' || firstChar === '@';
|
|
9
|
+
}
|
|
10
|
+
exports.isRelativeUrl = isRelativeUrl;
|
|
11
|
+
const externalRE = /^(https?:)?\/\//;
|
|
12
|
+
function isExternalUrl(url) {
|
|
13
|
+
return externalRE.test(url);
|
|
14
|
+
}
|
|
15
|
+
exports.isExternalUrl = isExternalUrl;
|
|
16
|
+
const dataUrlRE = /^\s*data:/i;
|
|
17
|
+
function isDataUrl(url) {
|
|
18
|
+
return dataUrlRE.test(url);
|
|
19
|
+
}
|
|
20
|
+
exports.isDataUrl = isDataUrl;
|
|
21
|
+
/**
|
|
22
|
+
* Parses string url into URL object.
|
|
23
|
+
*/
|
|
24
|
+
function parseUrl(url) {
|
|
25
|
+
const firstChar = url.charAt(0);
|
|
26
|
+
if (firstChar === '~') {
|
|
27
|
+
const secondChar = url.charAt(1);
|
|
28
|
+
url = url.slice(secondChar === '/' ? 2 : 1);
|
|
29
|
+
}
|
|
30
|
+
return parseUriParts(url);
|
|
31
|
+
}
|
|
32
|
+
exports.parseUrl = parseUrl;
|
|
33
|
+
/**
|
|
34
|
+
* vuejs/component-compiler-utils#22 Support uri fragment in transformed require
|
|
35
|
+
* @param urlString an url as a string
|
|
36
|
+
*/
|
|
37
|
+
function parseUriParts(urlString) {
|
|
38
|
+
// A TypeError is thrown if urlString is not a string
|
|
39
|
+
// @see https://nodejs.org/api/url.html#url_url_parse_urlstring_parsequerystring_slashesdenotehost
|
|
40
|
+
return (0, url_1.parse)((0, shared_1.isString)(urlString) ? urlString : '', false, true);
|
|
41
|
+
}
|
package/dist/vue/utils.d.ts
CHANGED
|
@@ -1,9 +1,29 @@
|
|
|
1
1
|
import { AttributeNode, ComponentNode, DirectiveNode, ElementNode, RootNode, ExpressionNode, TemplateChildNode, TransformContext } from '@vue/compiler-core';
|
|
2
2
|
export declare const VUE_REF = "r";
|
|
3
3
|
export declare const VUE_REF_IN_FOR = "r-i-f";
|
|
4
|
-
export declare function isUserComponent(node: RootNode | TemplateChildNode, context:
|
|
4
|
+
export declare function isUserComponent(node: RootNode | TemplateChildNode, context: {
|
|
5
|
+
isBuiltInComponent: TransformContext['isBuiltInComponent'];
|
|
6
|
+
}): node is ComponentNode;
|
|
5
7
|
export declare function createAttributeNode(name: string, content: string): AttributeNode;
|
|
6
8
|
export declare function addStaticClass(node: ElementNode, clazz: string): string | number | undefined;
|
|
7
9
|
export declare function createDirectiveNode(name: string, arg: string, exp: string | ExpressionNode): DirectiveNode;
|
|
8
10
|
export declare function createOnDirectiveNode(name: string, value: string): DirectiveNode;
|
|
9
11
|
export declare function createBindDirectiveNode(name: string, value: string | ExpressionNode): DirectiveNode;
|
|
12
|
+
export declare function createUniVueTransformAssetUrls(base: string): {
|
|
13
|
+
base: string;
|
|
14
|
+
includeAbsolute: boolean;
|
|
15
|
+
tags: {
|
|
16
|
+
audio: string[];
|
|
17
|
+
video: string[];
|
|
18
|
+
img: string[];
|
|
19
|
+
image: string[];
|
|
20
|
+
'cover-image': string[];
|
|
21
|
+
'v-uni-audio': string[];
|
|
22
|
+
'v-uni-video': string[];
|
|
23
|
+
'v-uni-image': string[];
|
|
24
|
+
'v-uni-cover-image': string[];
|
|
25
|
+
'u-image': string[];
|
|
26
|
+
'u-video': string[];
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export declare function getBaseNodeTransforms(base: string): import("@vue/compiler-core").NodeTransform[];
|