初始化
This commit is contained in:
9
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/entry.d.ts
generated
vendored
Normal file
9
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/entry.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import { Plugin } from 'vite';
|
||||
import { UniMiniProgramPluginOptions } from '../plugin';
|
||||
export declare function virtualPagePath(filepath: string): string;
|
||||
export declare function virtualComponentPath(filepath: string): string;
|
||||
export declare function parseVirtualPagePath(uniPageUrl: string): string;
|
||||
export declare function parseVirtualComponentPath(uniComponentUrl: string): string;
|
||||
export declare function isUniPageUrl(id: string): boolean;
|
||||
export declare function isUniComponentUrl(id: string): boolean;
|
||||
export declare function uniEntryPlugin({ global, }: UniMiniProgramPluginOptions): Plugin;
|
||||
71
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/entry.js
generated
vendored
Normal file
71
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/entry.js
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.uniEntryPlugin = exports.isUniComponentUrl = exports.isUniPageUrl = exports.parseVirtualComponentPath = exports.parseVirtualPagePath = exports.virtualComponentPath = exports.virtualPagePath = void 0;
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
||||
const uniPagePrefix = 'uniPage://';
|
||||
const uniComponentPrefix = 'uniComponent://';
|
||||
function virtualPagePath(filepath) {
|
||||
return uniPagePrefix + (0, uni_cli_shared_1.encodeBase64Url)(filepath);
|
||||
}
|
||||
exports.virtualPagePath = virtualPagePath;
|
||||
function virtualComponentPath(filepath) {
|
||||
return uniComponentPrefix + (0, uni_cli_shared_1.encodeBase64Url)(filepath);
|
||||
}
|
||||
exports.virtualComponentPath = virtualComponentPath;
|
||||
function parseVirtualPagePath(uniPageUrl) {
|
||||
return (0, uni_cli_shared_1.decodeBase64Url)(uniPageUrl.replace(uniPagePrefix, ''));
|
||||
}
|
||||
exports.parseVirtualPagePath = parseVirtualPagePath;
|
||||
function parseVirtualComponentPath(uniComponentUrl) {
|
||||
return (0, uni_cli_shared_1.decodeBase64Url)(uniComponentUrl.replace(uniComponentPrefix, ''));
|
||||
}
|
||||
exports.parseVirtualComponentPath = parseVirtualComponentPath;
|
||||
function isUniPageUrl(id) {
|
||||
return id.startsWith(uniPagePrefix);
|
||||
}
|
||||
exports.isUniPageUrl = isUniPageUrl;
|
||||
function isUniComponentUrl(id) {
|
||||
return id.startsWith(uniComponentPrefix);
|
||||
}
|
||||
exports.isUniComponentUrl = isUniComponentUrl;
|
||||
function uniEntryPlugin({ global, }) {
|
||||
const inputDir = process.env.UNI_INPUT_DIR;
|
||||
return {
|
||||
name: 'uni:virtual',
|
||||
enforce: 'pre',
|
||||
resolveId(id) {
|
||||
if (isUniPageUrl(id) || isUniComponentUrl(id)) {
|
||||
return id;
|
||||
}
|
||||
},
|
||||
load(id) {
|
||||
if (isUniPageUrl(id)) {
|
||||
const filepath = (0, uni_cli_shared_1.normalizePath)(path_1.default.resolve(inputDir, parseVirtualPagePath(id)));
|
||||
this.addWatchFile(filepath);
|
||||
return {
|
||||
code: `import MiniProgramPage from '${filepath}'
|
||||
${global}.createPage(MiniProgramPage)`,
|
||||
};
|
||||
}
|
||||
else if (isUniComponentUrl(id)) {
|
||||
const filepath = (0, uni_cli_shared_1.normalizePath)(path_1.default.resolve(inputDir, parseVirtualComponentPath(id)));
|
||||
this.addWatchFile(filepath);
|
||||
(0, uni_cli_shared_1.addMiniProgramComponentJson)((0, uni_cli_shared_1.removeExt)((0, uni_cli_shared_1.normalizeMiniProgramFilename)(filepath, inputDir)), {
|
||||
component: true,
|
||||
styleIsolation: process.env.UNI_PLATFORM === 'mp-baidu'
|
||||
? 'apply-shared'
|
||||
: undefined,
|
||||
});
|
||||
return {
|
||||
code: `import Component from '${filepath}'
|
||||
${global}.createComponent(Component)`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
exports.uniEntryPlugin = uniEntryPlugin;
|
||||
5
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/mainJs.d.ts
generated
vendored
Normal file
5
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/mainJs.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import type { SFCScriptCompileOptions } from '@vue/compiler-sfc';
|
||||
export declare function uniMainJsPlugin(options?: {
|
||||
normalizeComponentName?: (name: string) => string;
|
||||
babelParserPlugins?: SFCScriptCompileOptions['babelParserPlugins'];
|
||||
}): import("vite").Plugin;
|
||||
46
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/mainJs.js
generated
vendored
Normal file
46
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/mainJs.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.uniMainJsPlugin = void 0;
|
||||
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
||||
const usingComponents_1 = require("./usingComponents");
|
||||
function uniMainJsPlugin(options = {}) {
|
||||
const normalizeComponentName = options.normalizeComponentName || ((name) => name);
|
||||
return (0, uni_cli_shared_1.defineUniMainJsPlugin)((opts) => {
|
||||
return {
|
||||
name: 'uni:mp-main-js',
|
||||
enforce: 'pre',
|
||||
async transform(source, id) {
|
||||
if (opts.filter(id)) {
|
||||
source = source.includes('createSSRApp')
|
||||
? createApp(source)
|
||||
: createLegacyApp(source);
|
||||
const inputDir = process.env.UNI_INPUT_DIR;
|
||||
const { imports } = await (0, uni_cli_shared_1.updateMiniProgramGlobalComponents)(id, (0, uni_cli_shared_1.parseProgram)(source, id, {
|
||||
babelParserPlugins: options.babelParserPlugins,
|
||||
}), {
|
||||
inputDir,
|
||||
resolve: this.resolve,
|
||||
normalizeComponentName,
|
||||
});
|
||||
const { code, map } = await (0, uni_cli_shared_1.transformDynamicImports)(source, imports, {
|
||||
id,
|
||||
sourceMap: (0, uni_cli_shared_1.withSourcemap)(opts.resolvedConfig),
|
||||
dynamicImport: usingComponents_1.dynamicImport,
|
||||
});
|
||||
return {
|
||||
code: `import '\0plugin-vue:export-helper';import 'uni-mp-runtime';import './${uni_cli_shared_1.PAGES_JSON_JS}';` +
|
||||
code,
|
||||
map,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
exports.uniMainJsPlugin = uniMainJsPlugin;
|
||||
function createApp(code) {
|
||||
return `${code};createApp().app.mount("#app");`;
|
||||
}
|
||||
function createLegacyApp(code) {
|
||||
return code;
|
||||
}
|
||||
3
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/manifestJson.d.ts
generated
vendored
Normal file
3
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/manifestJson.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { Plugin } from 'vite';
|
||||
import { UniMiniProgramPluginOptions } from '../plugin';
|
||||
export declare function uniManifestJsonPlugin(options: UniMiniProgramPluginOptions): Plugin;
|
||||
95
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/manifestJson.js
generated
vendored
Normal file
95
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/manifestJson.js
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.uniManifestJsonPlugin = void 0;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const shared_1 = require("@vue/shared");
|
||||
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
||||
function findUserProjectConfigFile(inputDir, config) {
|
||||
for (let i = 0; i < config.length; i++) {
|
||||
const projectFilename = path_1.default.resolve(inputDir, config[i]);
|
||||
// 根目录包含指定文件,则直接拷贝
|
||||
if (fs_1.default.existsSync(projectFilename)) {
|
||||
return projectFilename;
|
||||
}
|
||||
}
|
||||
}
|
||||
function uniManifestJsonPlugin(options) {
|
||||
return (0, uni_cli_shared_1.defineUniManifestJsonPlugin)((opts) => {
|
||||
const inputDir = process.env.UNI_INPUT_DIR;
|
||||
const platform = process.env.UNI_PLATFORM;
|
||||
let projectJson;
|
||||
let userProjectFilename;
|
||||
let projectSource;
|
||||
if (options.project) {
|
||||
userProjectFilename = findUserProjectConfigFile(inputDir, options.project.config);
|
||||
}
|
||||
return {
|
||||
name: 'uni:mp-manifest-json',
|
||||
enforce: 'pre',
|
||||
transform(code, id) {
|
||||
if (!opts.filter(id)) {
|
||||
return;
|
||||
}
|
||||
this.addWatchFile(path_1.default.resolve(inputDir, 'manifest.json'));
|
||||
(0, uni_cli_shared_1.getLocaleFiles)(path_1.default.resolve(inputDir, 'locale')).forEach((filepath) => {
|
||||
this.addWatchFile(filepath);
|
||||
});
|
||||
if (options.project) {
|
||||
// 根目录包含指定文件,则直接拷贝
|
||||
if (userProjectFilename) {
|
||||
this.addWatchFile(userProjectFilename);
|
||||
projectJson = (0, uni_cli_shared_1.parseJson)(fs_1.default.readFileSync(userProjectFilename, 'utf8'));
|
||||
}
|
||||
else {
|
||||
const template = options.project.source;
|
||||
if ((0, shared_1.hasOwn)(template, 'appid')) {
|
||||
let projectName = path_1.default.basename(inputDir);
|
||||
if (projectName === 'src') {
|
||||
projectName = path_1.default.basename(path_1.default.dirname(inputDir));
|
||||
}
|
||||
template.projectname = projectName;
|
||||
// TODO condition
|
||||
if (process.env.UNI_AUTOMATOR_WS_ENDPOINT) {
|
||||
if (!template.setting) {
|
||||
template.setting = {};
|
||||
}
|
||||
template.setting.urlCheck = false;
|
||||
}
|
||||
projectJson = (0, uni_cli_shared_1.parseMiniProgramProjectJson)(code, platform, {
|
||||
template,
|
||||
pagesJson: (0, uni_cli_shared_1.parsePagesJsonOnce)(inputDir, platform),
|
||||
});
|
||||
}
|
||||
else {
|
||||
// 无需解析,直接拷贝,如 quickapp-webview
|
||||
projectJson = template;
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
code: '',
|
||||
map: { mappings: '' },
|
||||
};
|
||||
},
|
||||
generateBundle() {
|
||||
if (projectJson && options.project) {
|
||||
const { filename, normalize } = options.project;
|
||||
const source = JSON.stringify(normalize ? normalize(projectJson) : projectJson, null, 2);
|
||||
if (projectSource !== source) {
|
||||
projectSource = source;
|
||||
this.emitFile({
|
||||
fileName: filename,
|
||||
type: 'asset',
|
||||
source,
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
exports.uniManifestJsonPlugin = uniManifestJsonPlugin;
|
||||
4
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/pagesJson.d.ts
generated
vendored
Normal file
4
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/pagesJson.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import { Plugin, ResolvedConfig } from 'vite';
|
||||
import { UniMiniProgramPluginOptions } from '../plugin';
|
||||
export declare function getNVueCssPaths(config: ResolvedConfig): string[] | undefined;
|
||||
export declare function uniPagesJsonPlugin(options: UniMiniProgramPluginOptions): Plugin;
|
||||
112
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/pagesJson.js
generated
vendored
Normal file
112
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/pagesJson.js
generated
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.uniPagesJsonPlugin = exports.getNVueCssPaths = void 0;
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const debug_1 = __importDefault(require("debug"));
|
||||
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
||||
const entry_1 = require("./entry");
|
||||
const uni_i18n_1 = require("@dcloudio/uni-i18n");
|
||||
const debugPagesJson = (0, debug_1.default)('uni:pages-json');
|
||||
const nvueCssPathsCache = new Map();
|
||||
function getNVueCssPaths(config) {
|
||||
return nvueCssPathsCache.get(config);
|
||||
}
|
||||
exports.getNVueCssPaths = getNVueCssPaths;
|
||||
function uniPagesJsonPlugin(options) {
|
||||
let resolvedConfig;
|
||||
const platform = process.env.UNI_PLATFORM;
|
||||
const inputDir = process.env.UNI_INPUT_DIR;
|
||||
return (0, uni_cli_shared_1.defineUniPagesJsonPlugin)((opts) => {
|
||||
return {
|
||||
name: 'uni:mp-pages-json',
|
||||
enforce: 'pre',
|
||||
configResolved(config) {
|
||||
resolvedConfig = config;
|
||||
},
|
||||
transform(code, id) {
|
||||
if (!opts.filter(id)) {
|
||||
return null;
|
||||
}
|
||||
this.addWatchFile(path_1.default.resolve(inputDir, 'pages.json'));
|
||||
(0, uni_cli_shared_1.getLocaleFiles)(path_1.default.resolve(inputDir, 'locale')).forEach((filepath) => {
|
||||
this.addWatchFile(filepath);
|
||||
});
|
||||
const manifestJson = (0, uni_cli_shared_1.parseManifestJsonOnce)(inputDir);
|
||||
const { appJson, pageJsons, nvuePages } = (0, uni_cli_shared_1.parseMiniProgramPagesJson)(code, platform, {
|
||||
debug: !!manifestJson.debug,
|
||||
darkmode: options.app.darkmode,
|
||||
networkTimeout: manifestJson.networkTimeout,
|
||||
subpackages: !!options.app.subpackages,
|
||||
...options.json,
|
||||
});
|
||||
nvueCssPathsCache.set(resolvedConfig, nvuePages.map((pagePath) => pagePath + options.style.extname));
|
||||
(0, uni_cli_shared_1.mergeMiniProgramAppJson)(appJson, manifestJson[platform]);
|
||||
if (options.json?.formatAppJson) {
|
||||
options.json.formatAppJson(appJson, manifestJson, pageJsons);
|
||||
}
|
||||
// 使用 once 获取的话,可以节省编译时间,但 i18n 内容发生变化时,pages.json 不会自动更新
|
||||
const i18nOptions = (0, uni_cli_shared_1.initI18nOptionsOnce)(platform, inputDir, false, true);
|
||||
if (i18nOptions) {
|
||||
const { locale, locales, delimiters } = i18nOptions;
|
||||
(0, uni_i18n_1.parseI18nJson)(appJson, locales[locale], delimiters);
|
||||
(0, uni_i18n_1.parseI18nJson)(pageJsons, locales[locale], delimiters);
|
||||
}
|
||||
const { normalize } = options.app;
|
||||
(0, uni_cli_shared_1.addMiniProgramAppJson)(normalize ? normalize(appJson) : appJson);
|
||||
Object.keys(pageJsons).forEach((name) => {
|
||||
if (isNormalPage(name)) {
|
||||
(0, uni_cli_shared_1.addMiniProgramPageJson)(name, pageJsons[name]);
|
||||
}
|
||||
});
|
||||
return {
|
||||
code: `import './${uni_cli_shared_1.MANIFEST_JSON_JS}'\n` + importPagesCode(appJson),
|
||||
map: { mappings: '' },
|
||||
};
|
||||
},
|
||||
generateBundle() {
|
||||
(0, uni_cli_shared_1.findChangedJsonFiles)(options.app.usingComponents).forEach((value, key) => {
|
||||
debugPagesJson('json.changed', key);
|
||||
this.emitFile({
|
||||
type: 'asset',
|
||||
fileName: key + '.json',
|
||||
source: value,
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
exports.uniPagesJsonPlugin = uniPagesJsonPlugin;
|
||||
/**
|
||||
* 字节跳动小程序可以配置 ext:// 开头的插件页面模板,如 ext://microapp-trade-plugin/order-confirm
|
||||
* @param pagePath
|
||||
* @returns
|
||||
*/
|
||||
function isNormalPage(pagePath) {
|
||||
return !pagePath.startsWith('ext://');
|
||||
}
|
||||
function importPagesCode(pagesJson) {
|
||||
const importPagesCode = [];
|
||||
function importPageCode(pagePath) {
|
||||
if (!isNormalPage(pagePath)) {
|
||||
return;
|
||||
}
|
||||
const pagePathWithExtname = (0, uni_cli_shared_1.normalizePagePath)(pagePath, process.env.UNI_PLATFORM);
|
||||
if (pagePathWithExtname) {
|
||||
importPagesCode.push(`import('${(0, entry_1.virtualPagePath)(pagePathWithExtname)}')`);
|
||||
}
|
||||
}
|
||||
pagesJson.pages.forEach((pagePath) => importPageCode(pagePath));
|
||||
if (pagesJson.subPackages) {
|
||||
pagesJson.subPackages.forEach(({ root, pages }) => {
|
||||
pages &&
|
||||
pages.forEach((pagePath) => importPageCode(path_1.default.join(root, pagePath)));
|
||||
});
|
||||
}
|
||||
return `if(!Math){
|
||||
${importPagesCode.join('\n')}
|
||||
}`;
|
||||
}
|
||||
3
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/plugin.d.ts
generated
vendored
Normal file
3
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/plugin.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import type { Plugin } from 'vite';
|
||||
import { UniMiniProgramPluginOptions } from '../plugin';
|
||||
export declare function uniMiniProgramPluginPlugin({ style: { extname }, }: UniMiniProgramPluginOptions): Plugin;
|
||||
51
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/plugin.js
generated
vendored
Normal file
51
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/plugin.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.uniMiniProgramPluginPlugin = void 0;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
||||
const subpackage_1 = require("./subpackage");
|
||||
const shared_1 = require("@vue/shared");
|
||||
const build_1 = require("../plugin/build");
|
||||
function uniMiniProgramPluginPlugin({ style: { extname }, }) {
|
||||
const entry = initPluginEntry();
|
||||
const rollupOptions = {};
|
||||
if (entry) {
|
||||
rollupOptions.input = (0, shared_1.extend)({
|
||||
app: (0, uni_cli_shared_1.resolveMainPathOnce)(process.env.UNI_INPUT_DIR),
|
||||
}, entry);
|
||||
}
|
||||
return {
|
||||
name: 'uni:mp-plugin',
|
||||
enforce: 'post',
|
||||
config() {
|
||||
return {
|
||||
build: {
|
||||
rollupOptions,
|
||||
},
|
||||
};
|
||||
},
|
||||
generateBundle: (0, subpackage_1.createNonAppGenerateBundle)(extname),
|
||||
};
|
||||
}
|
||||
exports.uniMiniProgramPluginPlugin = uniMiniProgramPluginPlugin;
|
||||
function initPluginEntry() {
|
||||
const pluginJsonFilename = path_1.default.resolve(process.env.UNI_INPUT_DIR, uni_cli_shared_1.MP_PLUGIN_JSON_NAME);
|
||||
if (!fs_1.default.existsSync(pluginJsonFilename)) {
|
||||
(0, build_1.notFound)(pluginJsonFilename);
|
||||
}
|
||||
const pluginJson = (0, uni_cli_shared_1.parseJson)(fs_1.default.readFileSync(pluginJsonFilename, 'utf8'), true);
|
||||
if (!pluginJson.main) {
|
||||
return;
|
||||
}
|
||||
const mainFilename = path_1.default.resolve(process.env.UNI_INPUT_DIR, pluginJson.main);
|
||||
if (!fs_1.default.existsSync(mainFilename)) {
|
||||
(0, build_1.notFound)(mainFilename);
|
||||
}
|
||||
return {
|
||||
[(0, uni_cli_shared_1.removeExt)(pluginJson.main)]: mainFilename,
|
||||
};
|
||||
}
|
||||
6
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/renderjs.d.ts
generated
vendored
Normal file
6
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/renderjs.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import { Plugin, ResolvedConfig } from 'vite';
|
||||
import { MiniProgramFilterOptions } from '@dcloudio/uni-cli-shared';
|
||||
export declare function getFiltersCache(resolvedConfig: ResolvedConfig): MiniProgramFilterOptions[];
|
||||
export declare function uniRenderjsPlugin({ lang }: {
|
||||
lang?: string;
|
||||
}): Plugin;
|
||||
61
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/renderjs.js
generated
vendored
Normal file
61
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/renderjs.js
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.uniRenderjsPlugin = exports.getFiltersCache = void 0;
|
||||
const debug_1 = __importDefault(require("debug"));
|
||||
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
||||
const debugRenderjs = (0, debug_1.default)('uni:mp-renderjs');
|
||||
const filtersCache = new Map();
|
||||
function getFiltersCache(resolvedConfig) {
|
||||
return filtersCache.get(resolvedConfig) || [];
|
||||
}
|
||||
exports.getFiltersCache = getFiltersCache;
|
||||
function uniRenderjsPlugin({ lang }) {
|
||||
let resolvedConfig;
|
||||
return {
|
||||
name: 'uni:mp-renderjs',
|
||||
configResolved(config) {
|
||||
resolvedConfig = config;
|
||||
filtersCache.set(resolvedConfig, []);
|
||||
},
|
||||
transform(code, id) {
|
||||
const { type, name } = (0, uni_cli_shared_1.parseRenderjs)(id);
|
||||
if (!type) {
|
||||
return null;
|
||||
}
|
||||
debugRenderjs(id);
|
||||
if (type !== lang) {
|
||||
return {
|
||||
code: 'export default {}',
|
||||
map: { mappings: '' },
|
||||
};
|
||||
}
|
||||
this.addWatchFile((0, uni_cli_shared_1.cleanUrl)(id));
|
||||
if (!name) {
|
||||
this.error((0, uni_cli_shared_1.missingModuleName)(type, code));
|
||||
}
|
||||
else {
|
||||
let cache = filtersCache.get(resolvedConfig);
|
||||
if (cache) {
|
||||
const index = cache.findIndex((item) => item.id === id);
|
||||
if (index > -1) {
|
||||
cache.splice(index, 1);
|
||||
}
|
||||
cache.push({
|
||||
id,
|
||||
type,
|
||||
name,
|
||||
code,
|
||||
});
|
||||
}
|
||||
}
|
||||
return {
|
||||
code: (0, uni_cli_shared_1.genWxsCallMethodsCode)(code),
|
||||
map: { mappings: '' },
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
exports.uniRenderjsPlugin = uniRenderjsPlugin;
|
||||
2
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/runtimeHooks.d.ts
generated
vendored
Normal file
2
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/runtimeHooks.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import type { Plugin } from 'vite';
|
||||
export declare function uniRuntimeHooksPlugin(): Plugin;
|
||||
50
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/runtimeHooks.js
generated
vendored
Normal file
50
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/runtimeHooks.js
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.uniRuntimeHooksPlugin = void 0;
|
||||
const uni_shared_1 = require("@dcloudio/uni-shared");
|
||||
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
||||
const compiler_sfc_1 = require("@vue/compiler-sfc");
|
||||
function uniRuntimeHooksPlugin() {
|
||||
return {
|
||||
name: 'uni:mp-runtime-hooks',
|
||||
enforce: 'post',
|
||||
async transform(source, id) {
|
||||
const isSetupJs = (0, uni_cli_shared_1.isUniPageSfcFile)(id);
|
||||
const isSetupTs = !isSetupJs && (0, uni_cli_shared_1.isUniPageSetupAndTs)(id);
|
||||
if (!isSetupJs && !isSetupTs) {
|
||||
return null;
|
||||
}
|
||||
if (isSetupJs && !source.includes('_sfc_main')) {
|
||||
return null;
|
||||
}
|
||||
if (isSetupTs && !source.includes('defineComponent')) {
|
||||
return null;
|
||||
}
|
||||
const matches = source.match(new RegExp(`(${Object.keys(uni_shared_1.MINI_PROGRAM_PAGE_RUNTIME_HOOKS).join('|')})`, 'g'));
|
||||
if (!matches) {
|
||||
return null;
|
||||
}
|
||||
if (matches.includes('onShareTimeline')) {
|
||||
matches.push('onShareAppMessage');
|
||||
}
|
||||
const hooks = new Set(matches);
|
||||
let flag = 0;
|
||||
for (const hook of hooks) {
|
||||
flag |= uni_shared_1.MINI_PROGRAM_PAGE_RUNTIME_HOOKS[hook];
|
||||
}
|
||||
if (isSetupJs) {
|
||||
source = source + `;_sfc_main.__runtimeHooks = ${flag};`;
|
||||
}
|
||||
else if (isSetupTs) {
|
||||
source =
|
||||
(0, compiler_sfc_1.rewriteDefault)(source, '_sfc_defineComponent') +
|
||||
`\n_sfc_defineComponent.__runtimeHooks = ${flag};\nexport default _sfc_defineComponent`;
|
||||
}
|
||||
return {
|
||||
code: source,
|
||||
map: { mappings: '' },
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
exports.uniRuntimeHooksPlugin = uniRuntimeHooksPlugin;
|
||||
4
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/subpackage.d.ts
generated
vendored
Normal file
4
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/subpackage.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import type { Plugin } from 'vite';
|
||||
import { UniMiniProgramPluginOptions } from '../plugin';
|
||||
export declare function uniSubpackagePlugin({ style: { extname }, }: UniMiniProgramPluginOptions): Plugin;
|
||||
export declare function createNonAppGenerateBundle(extname: string): Plugin['generateBundle'];
|
||||
40
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/subpackage.js
generated
vendored
Normal file
40
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/subpackage.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createNonAppGenerateBundle = exports.uniSubpackagePlugin = void 0;
|
||||
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
||||
function uniSubpackagePlugin({ style: { extname }, }) {
|
||||
return {
|
||||
name: 'uni:mp-subpackage',
|
||||
enforce: 'post',
|
||||
generateBundle: createNonAppGenerateBundle(extname),
|
||||
};
|
||||
}
|
||||
exports.uniSubpackagePlugin = uniSubpackagePlugin;
|
||||
function createNonAppGenerateBundle(extname) {
|
||||
return function generateBundle(_, bundle) {
|
||||
;
|
||||
['project.config.json', 'app.json'].forEach((name) => {
|
||||
delete bundle[name];
|
||||
});
|
||||
const appJsFile = 'app.js';
|
||||
const appCssFile = 'app' + extname;
|
||||
Object.keys(bundle).forEach((name) => {
|
||||
if (!(0, uni_cli_shared_1.isMiniProgramPageFile)(name)) {
|
||||
return;
|
||||
}
|
||||
// 仅页面级 wxss 需要补充 app.wxss
|
||||
if (name.endsWith(extname)) {
|
||||
const cssFile = bundle[name];
|
||||
cssFile.source =
|
||||
`@import "${(0, uni_cli_shared_1.relativeFile)(name, appCssFile)}";\n` +
|
||||
cssFile.source.toString();
|
||||
}
|
||||
else if (name.endsWith('.js')) {
|
||||
const jsFile = bundle[name];
|
||||
jsFile.code =
|
||||
`require('${(0, uni_cli_shared_1.relativeFile)(name, appJsFile)}');\n` + jsFile.code;
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
exports.createNonAppGenerateBundle = createNonAppGenerateBundle;
|
||||
7
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/usingComponents.d.ts
generated
vendored
Normal file
7
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/usingComponents.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import type { Plugin } from 'vite';
|
||||
import type { SFCScriptCompileOptions } from '@vue/compiler-sfc';
|
||||
export declare function uniUsingComponentsPlugin(options?: {
|
||||
normalizeComponentName?: (name: string) => string;
|
||||
babelParserPlugins?: SFCScriptCompileOptions['babelParserPlugins'];
|
||||
}): Plugin;
|
||||
export declare function dynamicImport(name: string, value: string): string;
|
||||
84
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/usingComponents.js
generated
vendored
Normal file
84
uni_modules/UniDevTools/node_modules/@dcloudio/uni-mp-vite/dist/plugins/usingComponents.js
generated
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.dynamicImport = exports.uniUsingComponentsPlugin = void 0;
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
||||
const entry_1 = require("./entry");
|
||||
function uniUsingComponentsPlugin(options = {}) {
|
||||
const normalizeComponentName = options.normalizeComponentName || ((name) => name);
|
||||
const parseAst = (source, id) => {
|
||||
return (0, uni_cli_shared_1.parseProgram)(source, id, {
|
||||
babelParserPlugins: options.babelParserPlugins,
|
||||
});
|
||||
};
|
||||
const inputDir = process.env.UNI_INPUT_DIR;
|
||||
let resolvedConfig;
|
||||
return {
|
||||
name: 'uni:mp-using-component',
|
||||
enforce: 'post',
|
||||
configResolved(config) {
|
||||
resolvedConfig = config;
|
||||
},
|
||||
async transform(source, id) {
|
||||
const { filename, query } = (0, uni_cli_shared_1.parseVueRequest)(id);
|
||||
if ((0, uni_cli_shared_1.isAppVue)(filename)) {
|
||||
return null;
|
||||
}
|
||||
const sourceMap = (0, uni_cli_shared_1.withSourcemap)(resolvedConfig);
|
||||
const dynamicImportOptions = {
|
||||
id,
|
||||
sourceMap,
|
||||
dynamicImport,
|
||||
};
|
||||
const resolve = async (source, importer, options) => {
|
||||
const id = (0, uni_cli_shared_1.resolveUTSModule)(source, importer || process.env.UNI_INPUT_DIR);
|
||||
if (id) {
|
||||
source = id;
|
||||
}
|
||||
return this.resolve(source, importer, options);
|
||||
};
|
||||
if (query.vue) {
|
||||
if (query.type === 'script') {
|
||||
// 需要主动监听
|
||||
this.addWatchFile(filename);
|
||||
const descriptor = await (0, uni_cli_shared_1.parseScriptDescriptor)(filename, parseAst(source, id), {
|
||||
resolve,
|
||||
isExternal: true,
|
||||
});
|
||||
(0, uni_cli_shared_1.updateMiniProgramComponentsByScriptFilename)(filename, inputDir, normalizeComponentName);
|
||||
return (0, uni_cli_shared_1.transformDynamicImports)(source, descriptor.imports, dynamicImportOptions);
|
||||
}
|
||||
else if (query.type === 'template') {
|
||||
// 需要主动监听
|
||||
this.addWatchFile(filename);
|
||||
const descriptor = await (0, uni_cli_shared_1.parseTemplateDescriptor)(filename, parseAst(source, id), {
|
||||
resolve,
|
||||
isExternal: true,
|
||||
});
|
||||
(0, uni_cli_shared_1.updateMiniProgramComponentsByTemplateFilename)(filename, inputDir, normalizeComponentName);
|
||||
return (0, uni_cli_shared_1.transformDynamicImports)(source, descriptor.imports, dynamicImportOptions);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (!uni_cli_shared_1.EXTNAME_VUE.includes(path_1.default.extname(filename))) {
|
||||
return null;
|
||||
}
|
||||
const ast = parseAst(source, id);
|
||||
const descriptor = await (0, uni_cli_shared_1.parseMainDescriptor)(filename, ast, resolve);
|
||||
(0, uni_cli_shared_1.updateMiniProgramComponentsByMainFilename)(filename, inputDir, normalizeComponentName);
|
||||
return (0, uni_cli_shared_1.transformDynamicImports)(source, descriptor.imports, dynamicImportOptions);
|
||||
},
|
||||
};
|
||||
}
|
||||
exports.uniUsingComponentsPlugin = uniUsingComponentsPlugin;
|
||||
function dynamicImport(name, value) {
|
||||
// 开发者可能将页面作为组件来引用
|
||||
if ((0, uni_cli_shared_1.isMiniProgramPageFile)(value, process.env.UNI_INPUT_DIR)) {
|
||||
return `const ${name} = ()=>import('${(0, entry_1.virtualPagePath)(value)}')`;
|
||||
}
|
||||
return `const ${name} = ()=>import('${(0, entry_1.virtualComponentPath)(value)}')`;
|
||||
}
|
||||
exports.dynamicImport = dynamicImport;
|
||||
Reference in New Issue
Block a user