提交
This commit is contained in:
674
pxdj-merch-uni/miniprogram_npm/@dcloudio/uni-app-uts/index.js
Normal file
674
pxdj-merch-uni/miniprogram_npm/@dcloudio/uni-app-uts/index.js
Normal file
@@ -0,0 +1,674 @@
|
||||
module.exports = (function() {
|
||||
var __MODS__ = {};
|
||||
var __DEFINE__ = function(modId, func, req) { var m = { exports: {}, _tempexports: {} }; __MODS__[modId] = { status: 0, func: func, req: req, m: m }; };
|
||||
var __REQUIRE__ = function(modId, source) { if(!__MODS__[modId]) return require(source); if(!__MODS__[modId].status) { var m = __MODS__[modId].m; m._exports = m._tempexports; var desp = Object.getOwnPropertyDescriptor(m, "exports"); if (desp && desp.configurable) Object.defineProperty(m, "exports", { set: function (val) { if(typeof val === "object" && val !== m._exports) { m._exports.__proto__ = val.__proto__; Object.keys(val).forEach(function (k) { m._exports[k] = val[k]; }); } m._tempexports = val }, get: function () { return m._tempexports; } }); __MODS__[modId].status = 1; __MODS__[modId].func(__MODS__[modId].req, m, m.exports); } return __MODS__[modId].m.exports; };
|
||||
var __REQUIRE_WILDCARD__ = function(obj) { if(obj && obj.__esModule) { return obj; } else { var newObj = {}; if(obj != null) { for(var k in obj) { if (Object.prototype.hasOwnProperty.call(obj, k)) newObj[k] = obj[k]; } } newObj.default = obj; return newObj; } };
|
||||
var __REQUIRE_DEFAULT__ = function(obj) { return obj && obj.__esModule ? obj.default : obj; };
|
||||
__DEFINE__(1745998156416, function(require, module, exports) {
|
||||
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.transformVue = exports.genClassName = void 0;
|
||||
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
||||
const plugins_1 = require("./plugins");
|
||||
const css_1 = require("./plugins/css");
|
||||
const mainUTS_1 = require("./plugins/mainUTS");
|
||||
const manifestJson_1 = require("./plugins/manifestJson");
|
||||
const pagesJson_1 = require("./plugins/pagesJson");
|
||||
const pre_1 = require("./plugins/pre");
|
||||
const uvue_1 = require("./plugins/uvue");
|
||||
exports.default = () => {
|
||||
return [
|
||||
(0, pre_1.uniPrePlugin)(),
|
||||
(0, uni_cli_shared_1.uniUTSPlugin)({
|
||||
x: true,
|
||||
extApis: (0, uni_cli_shared_1.parseUniExtApiNamespacesOnce)(process.env.UNI_UTS_PLATFORM, process.env.UNI_UTS_TARGET_LANGUAGE),
|
||||
}),
|
||||
(0, plugins_1.uniAppUTSPlugin)(),
|
||||
(0, mainUTS_1.uniAppMainPlugin)(),
|
||||
(0, manifestJson_1.uniAppManifestPlugin)(),
|
||||
(0, pagesJson_1.uniAppPagesPlugin)(),
|
||||
(0, css_1.uniAppCssPlugin)(),
|
||||
(0, uvue_1.uniAppUVuePlugin)(),
|
||||
];
|
||||
};
|
||||
var utils_1 = require("./plugins/utils");
|
||||
Object.defineProperty(exports, "genClassName", { enumerable: true, get: function () { return utils_1.genClassName; } });
|
||||
var index_1 = require("./plugins/uvue/index");
|
||||
Object.defineProperty(exports, "transformVue", { enumerable: true, get: function () { return index_1.transformVue; } });
|
||||
|
||||
}, function(modId) {var map = {"./plugins":1745998156417,"./plugins/css":1745998156419,"./plugins/mainUTS":1745998156420,"./plugins/manifestJson":1745998156421,"./plugins/pagesJson":1745998156422,"./plugins/pre":1745998156423,"./plugins/utils":1745998156418}; return __REQUIRE__(map[modId], modId); })
|
||||
__DEFINE__(1745998156417, function(require, module, exports) {
|
||||
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.uniAppUTSPlugin = void 0;
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const fs_extra_1 = __importDefault(require("fs-extra"));
|
||||
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
||||
const uni_i18n_1 = require("@dcloudio/uni-i18n");
|
||||
const utils_1 = require("./utils");
|
||||
const REMOVED_PLUGINS = [
|
||||
'vite:build-metadata',
|
||||
'vite:modulepreload-polyfill',
|
||||
'vite:css',
|
||||
'vite:esbuild',
|
||||
'vite:json',
|
||||
'vite:wasm-helper',
|
||||
'vite:worker',
|
||||
'vite:asset',
|
||||
'vite:wasm-fallback',
|
||||
'vite:define',
|
||||
'vite:css-post',
|
||||
'vite:build-html',
|
||||
'vite:html-inline-proxy',
|
||||
'vite:worker-import-meta-url',
|
||||
'vite:asset-import-meta-url',
|
||||
'vite:force-systemjs-wrap-complete',
|
||||
'vite:watch-package-data',
|
||||
'commonjs',
|
||||
'vite:data-uri',
|
||||
'vite:dynamic-import-vars',
|
||||
'vite:import-glob',
|
||||
'vite:build-import-analysis',
|
||||
'vite:esbuild-transpile',
|
||||
'vite:terser',
|
||||
'vite:reporter',
|
||||
];
|
||||
function uniAppUTSPlugin() {
|
||||
const inputDir = process.env.UNI_INPUT_DIR;
|
||||
const outputDir = process.env.UNI_OUTPUT_DIR;
|
||||
const mainUTS = (0, uni_cli_shared_1.resolveMainPathOnce)(inputDir);
|
||||
const tempOutputDir = (0, utils_1.uvueOutDir)();
|
||||
const manifestJson = (0, uni_cli_shared_1.parseManifestJsonOnce)(inputDir);
|
||||
// 开始编译时,清空输出目录
|
||||
function emptyOutDir() {
|
||||
if (fs_extra_1.default.existsSync(outputDir)) {
|
||||
(0, uni_cli_shared_1.emptyDir)(outputDir);
|
||||
}
|
||||
}
|
||||
emptyOutDir();
|
||||
return {
|
||||
name: 'uni:app-uts',
|
||||
apply: 'build',
|
||||
uni: createUniOptions(),
|
||||
config() {
|
||||
return {
|
||||
base: '/',
|
||||
build: {
|
||||
outDir: tempOutputDir,
|
||||
lib: {
|
||||
// 必须使用 lib 模式
|
||||
fileName: 'output',
|
||||
entry: (0, uni_cli_shared_1.resolveMainPathOnce)(inputDir),
|
||||
formats: ['cjs'],
|
||||
},
|
||||
rollupOptions: {
|
||||
external(source) {
|
||||
if (['vue', 'vuex', 'pinia'].includes(source)) {
|
||||
return true;
|
||||
}
|
||||
// 相对目录
|
||||
if (source.startsWith('@/') || source.startsWith('.')) {
|
||||
return false;
|
||||
}
|
||||
if (path_1.default.isAbsolute(source)) {
|
||||
return false;
|
||||
}
|
||||
// android 系统库,三方库
|
||||
if (source.includes('.')) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
configResolved(config) {
|
||||
const plugins = config.plugins;
|
||||
const len = plugins.length;
|
||||
for (let i = len - 1; i >= 0; i--) {
|
||||
const plugin = plugins[i];
|
||||
if (REMOVED_PLUGINS.includes(plugin.name)) {
|
||||
plugins.splice(i, 1);
|
||||
}
|
||||
}
|
||||
},
|
||||
async transform(code, id) {
|
||||
const { filename } = (0, uni_cli_shared_1.parseVueRequest)(id);
|
||||
if (!filename.endsWith('.uts')) {
|
||||
return;
|
||||
}
|
||||
// 仅处理 uts 文件
|
||||
// 忽略 uni-app-uts/lib/automator/index.uts
|
||||
if (!filename.includes('uni-app-uts')) {
|
||||
const isMainUTS = (0, uni_cli_shared_1.normalizePath)(id) === mainUTS;
|
||||
const fileName = path_1.default.relative(inputDir, id);
|
||||
this.emitFile({
|
||||
type: 'asset',
|
||||
fileName: normalizeFilename(fileName, isMainUTS),
|
||||
source: normalizeCode(code, isMainUTS),
|
||||
});
|
||||
}
|
||||
code = await (0, utils_1.parseImports)(code);
|
||||
return code;
|
||||
},
|
||||
async writeBundle() {
|
||||
const res = await (0, uni_cli_shared_1.resolveUTSCompiler)().compileApp(path_1.default.join(tempOutputDir, 'index.uts'), {
|
||||
inputDir: tempOutputDir,
|
||||
outputDir: outputDir,
|
||||
package: 'uni.' + (manifestJson.appid || '').replace(/_/g, ''),
|
||||
sourceMap: true,
|
||||
uni_modules: [...uni_cli_shared_1.utsPlugins],
|
||||
extApis: (0, uni_cli_shared_1.parseUniExtApiNamespacesOnce)(process.env.UNI_UTS_PLATFORM, process.env.UNI_UTS_TARGET_LANGUAGE),
|
||||
});
|
||||
if (res) {
|
||||
const files = [];
|
||||
if (process.env.UNI_APP_UTS_CHANGED_FILES) {
|
||||
try {
|
||||
files.push(...JSON.parse(process.env.UNI_APP_UTS_CHANGED_FILES));
|
||||
}
|
||||
catch (e) { }
|
||||
}
|
||||
if (res.changed && res.changed.length) {
|
||||
files.push(...res.changed);
|
||||
}
|
||||
process.env.UNI_APP_UTS_CHANGED_FILES = JSON.stringify([
|
||||
...new Set(files),
|
||||
]);
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
exports.uniAppUTSPlugin = uniAppUTSPlugin;
|
||||
function normalizeFilename(filename, isMain = false) {
|
||||
if (isMain) {
|
||||
return 'index.uts';
|
||||
}
|
||||
return (0, utils_1.parseUTSRelativeFilename)(filename);
|
||||
}
|
||||
function normalizeCode(code, isMain = false) {
|
||||
if (!isMain) {
|
||||
return code;
|
||||
}
|
||||
const automatorCode = process.env.UNI_AUTOMATOR_WS_ENDPOINT
|
||||
? 'initAutomator();'
|
||||
: '';
|
||||
return `
|
||||
${code}
|
||||
export function main(app: IApp) {
|
||||
defineAppConfig();
|
||||
definePageRoutes();
|
||||
${automatorCode}
|
||||
(createApp()['app'] as VueApp).mount(app);
|
||||
}
|
||||
`;
|
||||
}
|
||||
function createUniOptions() {
|
||||
return {
|
||||
copyOptions() {
|
||||
const platform = process.env.UNI_PLATFORM;
|
||||
const inputDir = process.env.UNI_INPUT_DIR;
|
||||
const outputDir = process.env.UNI_OUTPUT_DIR;
|
||||
const targets = [];
|
||||
// 自动化测试时,不启用隐私政策
|
||||
if (!process.env.UNI_AUTOMATOR_WS_ENDPOINT) {
|
||||
targets.push({
|
||||
src: 'androidPrivacy.json',
|
||||
dest: outputDir,
|
||||
transform(source) {
|
||||
const options = (0, uni_cli_shared_1.initI18nOptions)(platform, inputDir, false, true);
|
||||
if (!options) {
|
||||
return;
|
||||
}
|
||||
return (0, uni_i18n_1.compileI18nJsonStr)(source.toString(), options);
|
||||
},
|
||||
});
|
||||
const debugFilename = '__nvue_debug__';
|
||||
if (fs_extra_1.default.existsSync(path_1.default.resolve(inputDir, debugFilename))) {
|
||||
targets.push({
|
||||
src: debugFilename,
|
||||
dest: outputDir,
|
||||
});
|
||||
}
|
||||
}
|
||||
return {
|
||||
assets: ['hybrid/html/**/*', 'uni_modules/*/hybrid/html/**/*'],
|
||||
targets,
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
}, function(modId) { var map = {"./utils":1745998156418}; return __REQUIRE__(map[modId], modId); })
|
||||
__DEFINE__(1745998156418, function(require, module, exports) {
|
||||
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.parseUTSImportFilename = exports.parseUTSRelativeFilename = exports.stringifyMap = exports.isVue = exports.genClassName = exports.uvueOutDir = exports.parseImports = exports.ENTRY_FILENAME = void 0;
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const es_module_lexer_1 = require("es-module-lexer");
|
||||
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
||||
const shared_1 = require("@vue/shared");
|
||||
exports.ENTRY_FILENAME = 'index.uts';
|
||||
async function parseImports(code) {
|
||||
await es_module_lexer_1.init;
|
||||
const [imports] = (0, es_module_lexer_1.parse)(code);
|
||||
return imports
|
||||
.map(({ s, e }) => {
|
||||
return `import "${code.slice(s, e)}"`;
|
||||
})
|
||||
.concat(parseUniExtApiImports(code))
|
||||
.join('\n');
|
||||
}
|
||||
exports.parseImports = parseImports;
|
||||
function parseUniExtApiImports(code) {
|
||||
const extApis = (0, uni_cli_shared_1.parseUniExtApiNamespacesJsOnce)(process.env.UNI_UTS_PLATFORM, process.env.UNI_UTS_TARGET_LANGUAGE);
|
||||
const pattern = /uni\.(\w+)/g;
|
||||
const apis = new Set();
|
||||
let match;
|
||||
while ((match = pattern.exec(code)) !== null) {
|
||||
apis.add(match[1]);
|
||||
}
|
||||
const imports = [];
|
||||
apis.forEach((api) => {
|
||||
const extApi = extApis[api];
|
||||
if (extApi) {
|
||||
imports.push(`import "${extApi[0]}"`);
|
||||
}
|
||||
});
|
||||
return imports;
|
||||
}
|
||||
function uvueOutDir() {
|
||||
return path_1.default.join(process.env.UNI_OUTPUT_DIR, '../.uvue');
|
||||
}
|
||||
exports.uvueOutDir = uvueOutDir;
|
||||
function genClassName(fileName, prefix = 'Gen') {
|
||||
return (prefix +
|
||||
(0, shared_1.capitalize)((0, shared_1.camelize)((0, uni_cli_shared_1.removeExt)((0, uni_cli_shared_1.normalizePath)(fileName).replace(/\//g, '-')))));
|
||||
}
|
||||
exports.genClassName = genClassName;
|
||||
function isVue(filename) {
|
||||
return filename.endsWith('.vue') || filename.endsWith('.uvue');
|
||||
}
|
||||
exports.isVue = isVue;
|
||||
function stringifyMap(obj) {
|
||||
return serialize(obj, true);
|
||||
}
|
||||
exports.stringifyMap = stringifyMap;
|
||||
function serialize(obj, ts = false) {
|
||||
if ((0, shared_1.isString)(obj)) {
|
||||
return `"${obj}"`;
|
||||
}
|
||||
else if ((0, shared_1.isPlainObject)(obj)) {
|
||||
const entries = Object.entries(obj).map(([key, value]) => `[${serialize(key, ts)},${serialize(value, ts)}]`);
|
||||
return `new Map${ts ? '<string, any>' : ''}([${entries.join(',')}])`;
|
||||
}
|
||||
else if ((0, shared_1.isArray)(obj)) {
|
||||
return `[${obj.map((item) => serialize(item, ts)).join(',')}]`;
|
||||
}
|
||||
else {
|
||||
return String(obj);
|
||||
}
|
||||
}
|
||||
function parseUTSRelativeFilename(filename) {
|
||||
if (!path_1.default.isAbsolute(filename)) {
|
||||
return filename;
|
||||
}
|
||||
return (0, uni_cli_shared_1.normalizeNodeModules)(path_1.default.relative(process.env.UNI_INPUT_DIR, filename));
|
||||
}
|
||||
exports.parseUTSRelativeFilename = parseUTSRelativeFilename;
|
||||
function parseUTSImportFilename(filename) {
|
||||
if (!path_1.default.isAbsolute(filename)) {
|
||||
return filename;
|
||||
}
|
||||
return (0, uni_cli_shared_1.normalizePath)(path_1.default.join(uvueOutDir(), (0, uni_cli_shared_1.normalizeNodeModules)(path_1.default.relative(process.env.UNI_INPUT_DIR, filename))));
|
||||
}
|
||||
exports.parseUTSImportFilename = parseUTSImportFilename;
|
||||
|
||||
}, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
|
||||
__DEFINE__(1745998156419, function(require, module, exports) {
|
||||
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.uniAppCssPlugin = void 0;
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const picocolors_1 = __importDefault(require("picocolors"));
|
||||
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
||||
const uni_nvue_styler_1 = require("@dcloudio/uni-nvue-styler");
|
||||
const utils_1 = require("./utils");
|
||||
function uniAppCssPlugin() {
|
||||
const mainUTS = (0, uni_cli_shared_1.resolveMainPathOnce)(process.env.UNI_INPUT_DIR);
|
||||
let resolvedConfig;
|
||||
const name = 'uni:app-uvue-css';
|
||||
return {
|
||||
name,
|
||||
apply: 'build',
|
||||
configResolved(config) {
|
||||
resolvedConfig = config;
|
||||
const uvueCssPostPlugin = (0, uni_cli_shared_1.cssPostPlugin)(config, {
|
||||
isJsCode: true,
|
||||
platform: process.env.UNI_PLATFORM,
|
||||
chunkCssFilename(id) {
|
||||
if (id === mainUTS) {
|
||||
return 'App.vue.style.uts';
|
||||
}
|
||||
const { filename } = (0, uni_cli_shared_1.parseVueRequest)(id);
|
||||
if ((0, utils_1.isVue)(filename)) {
|
||||
return (0, uni_cli_shared_1.normalizePath)(path_1.default.relative(process.env.UNI_INPUT_DIR, filename) + '.style.uts');
|
||||
}
|
||||
},
|
||||
async chunkCssCode(filename, cssCode) {
|
||||
const { code, messages } = await (0, uni_nvue_styler_1.parse)(cssCode, {
|
||||
filename,
|
||||
logLevel: 'ERROR',
|
||||
map: true,
|
||||
ts: true,
|
||||
chunk: 100,
|
||||
type: 'uvue',
|
||||
});
|
||||
messages.forEach((message) => {
|
||||
if (message.type === 'error') {
|
||||
let msg = `[plugin:uni:app-uvue-css] ${message.text}`;
|
||||
if (message.line && message.column) {
|
||||
msg += `\n${(0, uni_cli_shared_1.generateCodeFrame)(cssCode, {
|
||||
line: message.line,
|
||||
column: message.column,
|
||||
}).replace(/\t/g, ' ')}`;
|
||||
}
|
||||
msg += `\n${(0, uni_cli_shared_1.formatAtFilename)(filename)}`;
|
||||
resolvedConfig.logger.error(picocolors_1.default.red(msg));
|
||||
}
|
||||
});
|
||||
return `export const ${(0, utils_1.genClassName)(filename.replace('.style.uts', ''))}Styles = ${code}`;
|
||||
},
|
||||
});
|
||||
// 增加 css plugins
|
||||
(0, uni_cli_shared_1.insertBeforePlugin)((0, uni_cli_shared_1.cssPlugin)(config), name, config);
|
||||
const plugins = config.plugins;
|
||||
const index = plugins.findIndex((p) => p.name === 'uni:app-uvue');
|
||||
plugins.splice(index, 0, uvueCssPostPlugin);
|
||||
},
|
||||
async transform(source, filename) {
|
||||
if (!uni_cli_shared_1.cssLangRE.test(filename) || uni_cli_shared_1.commonjsProxyRE.test(filename)) {
|
||||
return;
|
||||
}
|
||||
// 仅做校验使用
|
||||
const { messages } = await (0, uni_nvue_styler_1.parse)(source, {
|
||||
filename,
|
||||
logLevel: 'WARNING',
|
||||
map: true,
|
||||
ts: true,
|
||||
noCode: true,
|
||||
type: 'uvue',
|
||||
});
|
||||
messages.forEach((message) => {
|
||||
if (message.type === 'warning') {
|
||||
let msg = `[plugin:uni:app-uvue-css] ${message.text}`;
|
||||
if (message.line && message.column) {
|
||||
msg += `\n${(0, uni_cli_shared_1.generateCodeFrame)(source, {
|
||||
line: message.line,
|
||||
column: message.column,
|
||||
}).replace(/\t/g, ' ')}`;
|
||||
}
|
||||
msg += `\n${(0, uni_cli_shared_1.formatAtFilename)(filename)}`;
|
||||
resolvedConfig.logger.warn(picocolors_1.default.yellow(msg));
|
||||
}
|
||||
});
|
||||
return { code: source };
|
||||
},
|
||||
};
|
||||
}
|
||||
exports.uniAppCssPlugin = uniAppCssPlugin;
|
||||
|
||||
}, function(modId) { var map = {"./utils":1745998156418}; return __REQUIRE__(map[modId], modId); })
|
||||
__DEFINE__(1745998156420, function(require, module, exports) {
|
||||
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.uniAppMainPlugin = void 0;
|
||||
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
||||
const utils_1 = require("./utils");
|
||||
function uniAppMainPlugin() {
|
||||
const mainUTS = (0, uni_cli_shared_1.resolveMainPathOnce)(process.env.UNI_INPUT_DIR);
|
||||
return {
|
||||
name: 'uni:app-main',
|
||||
apply: 'build',
|
||||
async transform(code, id) {
|
||||
if ((0, uni_cli_shared_1.normalizePath)(id) === mainUTS) {
|
||||
code = await (0, utils_1.parseImports)(code);
|
||||
return `
|
||||
import './${uni_cli_shared_1.MANIFEST_JSON_UTS}'
|
||||
import './${uni_cli_shared_1.PAGES_JSON_UTS}'
|
||||
${code}
|
||||
export default 'main.uts'
|
||||
`;
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
exports.uniAppMainPlugin = uniAppMainPlugin;
|
||||
|
||||
}, function(modId) { var map = {"./utils":1745998156418}; return __REQUIRE__(map[modId], modId); })
|
||||
__DEFINE__(1745998156421, function(require, module, exports) {
|
||||
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.uniAppManifestPlugin = void 0;
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const fs_extra_1 = __importDefault(require("fs-extra"));
|
||||
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
||||
const utils_1 = require("./utils");
|
||||
function isManifest(id) {
|
||||
return id.endsWith(uni_cli_shared_1.MANIFEST_JSON_UTS);
|
||||
}
|
||||
function uniAppManifestPlugin() {
|
||||
const manifestJsonPath = path_1.default.resolve(process.env.UNI_INPUT_DIR, 'manifest.json');
|
||||
const manifestJsonUTSPath = path_1.default.resolve(process.env.UNI_INPUT_DIR, uni_cli_shared_1.MANIFEST_JSON_UTS);
|
||||
let manifestJson = {};
|
||||
return {
|
||||
name: 'uni:app-manifest',
|
||||
apply: 'build',
|
||||
resolveId(id) {
|
||||
if (isManifest(id)) {
|
||||
return manifestJsonUTSPath;
|
||||
}
|
||||
},
|
||||
load(id) {
|
||||
if (isManifest(id)) {
|
||||
return fs_extra_1.default.readFileSync(manifestJsonPath, 'utf8');
|
||||
}
|
||||
},
|
||||
transform(code, id) {
|
||||
if (isManifest(id)) {
|
||||
this.addWatchFile(path_1.default.resolve(process.env.UNI_INPUT_DIR, 'manifest.json'));
|
||||
manifestJson = (0, uni_cli_shared_1.parseJson)(code);
|
||||
return `export default 'manifest.json'`;
|
||||
}
|
||||
},
|
||||
generateBundle(_, bundle) {
|
||||
if (bundle[utils_1.ENTRY_FILENAME]) {
|
||||
const asset = bundle[utils_1.ENTRY_FILENAME];
|
||||
asset.source =
|
||||
asset.source +
|
||||
`
|
||||
import "io.dcloud.uniapp.appframe.AppConfig"
|
||||
export class UniAppConfig extends AppConfig {
|
||||
override name: string = "${manifestJson.name || ''}"
|
||||
override appid: string = "${manifestJson.appid || ''}"
|
||||
override versionName: string = "${manifestJson.versionName || ''}"
|
||||
override versionCode: string = "${manifestJson.versionCode || ''}"
|
||||
constructor() {}
|
||||
}
|
||||
`;
|
||||
}
|
||||
fs_extra_1.default.outputFileSync(path_1.default.resolve(process.env.UNI_OUTPUT_DIR, 'manifest.json'), JSON.stringify({
|
||||
id: manifestJson.appid || '',
|
||||
name: manifestJson.name || '',
|
||||
description: manifestJson.description || '',
|
||||
version: {
|
||||
name: manifestJson.versionName || '',
|
||||
code: manifestJson.versionCode || '',
|
||||
},
|
||||
'uni-app-x': manifestJson['uni-app-x'] || {},
|
||||
app: manifestJson.app || {},
|
||||
}, null, 2));
|
||||
},
|
||||
};
|
||||
}
|
||||
exports.uniAppManifestPlugin = uniAppManifestPlugin;
|
||||
|
||||
}, function(modId) { var map = {"./utils":1745998156418}; return __REQUIRE__(map[modId], modId); })
|
||||
__DEFINE__(1745998156422, function(require, module, exports) {
|
||||
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.uniAppPagesPlugin = void 0;
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const fs_extra_1 = __importDefault(require("fs-extra"));
|
||||
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
||||
const utils_1 = require("./utils");
|
||||
function isPages(id) {
|
||||
return id.endsWith(uni_cli_shared_1.PAGES_JSON_UTS);
|
||||
}
|
||||
function uniAppPagesPlugin() {
|
||||
const pagesJsonPath = path_1.default.resolve(process.env.UNI_INPUT_DIR, 'pages.json');
|
||||
const pagesJsonUTSPath = path_1.default.resolve(process.env.UNI_INPUT_DIR, uni_cli_shared_1.PAGES_JSON_UTS);
|
||||
let imports = [];
|
||||
let routes = [];
|
||||
let globalStyle = 'new Map()';
|
||||
let tabBar = 'null';
|
||||
return {
|
||||
name: 'uni:app-pages',
|
||||
apply: 'build',
|
||||
resolveId(id) {
|
||||
if (isPages(id)) {
|
||||
return pagesJsonUTSPath;
|
||||
}
|
||||
},
|
||||
load(id) {
|
||||
if (isPages(id)) {
|
||||
return fs_extra_1.default.readFileSync(pagesJsonPath, 'utf8');
|
||||
}
|
||||
},
|
||||
transform(code, id) {
|
||||
if (isPages(id)) {
|
||||
this.addWatchFile(path_1.default.resolve(process.env.UNI_INPUT_DIR, 'pages.json'));
|
||||
const pagesJson = (0, uni_cli_shared_1.normalizeUniAppXAppPagesJson)(code);
|
||||
imports = [];
|
||||
routes = [];
|
||||
pagesJson.pages.forEach((page, index) => {
|
||||
const className = (0, utils_1.genClassName)(page.path);
|
||||
let isQuit = index === 0;
|
||||
imports.push(page.path);
|
||||
routes.push(`{ path: "${page.path}", component: ${className}Class, meta: { isQuit: ${isQuit} } as PageMeta, style: ${stringifyPageStyle(page.style)} } as PageRoute`);
|
||||
});
|
||||
if (pagesJson.globalStyle) {
|
||||
globalStyle = stringifyPageStyle(pagesJson.globalStyle);
|
||||
}
|
||||
if (pagesJson.tabBar) {
|
||||
tabBar = (0, utils_1.stringifyMap)(pagesJson.tabBar);
|
||||
}
|
||||
return `${imports.map((p) => `import './${p}.uvue'`).join('\n')}
|
||||
export default 'pages.json'`;
|
||||
}
|
||||
},
|
||||
generateBundle(_, bundle) {
|
||||
if (bundle[utils_1.ENTRY_FILENAME]) {
|
||||
const asset = bundle[utils_1.ENTRY_FILENAME];
|
||||
asset.source =
|
||||
asset.source +
|
||||
`
|
||||
${imports
|
||||
.map((p) => {
|
||||
const className = (0, utils_1.genClassName)(p);
|
||||
return `import ${className}Class from './${p}.uvue?type=page'`;
|
||||
})
|
||||
.join('\n')}
|
||||
function definePageRoutes() {
|
||||
${routes.map((route) => `__uniRoutes.push(${route})`).join('\n')}
|
||||
}
|
||||
function defineAppConfig(){
|
||||
__uniConfig.entryPagePath = '/${imports[0]}'
|
||||
__uniConfig.globalStyle = ${globalStyle}
|
||||
__uniConfig.tabBar = ${tabBar}
|
||||
}
|
||||
`;
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
exports.uniAppPagesPlugin = uniAppPagesPlugin;
|
||||
function stringifyPageStyle(pageStyle) {
|
||||
return (0, utils_1.stringifyMap)(pageStyle);
|
||||
}
|
||||
|
||||
}, function(modId) { var map = {"./utils":1745998156418}; return __REQUIRE__(map[modId], modId); })
|
||||
__DEFINE__(1745998156423, function(require, module, exports) {
|
||||
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.uniPrePlugin = void 0;
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const debug_1 = __importDefault(require("debug"));
|
||||
const pluginutils_1 = require("@rollup/pluginutils");
|
||||
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
||||
const debugPreJs = (0, debug_1.default)('uni:pre-js');
|
||||
const debugPreHtml = (0, debug_1.default)('uni:pre-html');
|
||||
const debugPreJsTry = (0, debug_1.default)('uni:pre-js-try');
|
||||
const PRE_HTML_EXTNAME = ['.vue', '.uvue'];
|
||||
const PRE_JS_EXTNAME = ['.json', '.css', '.uts'].concat(PRE_HTML_EXTNAME);
|
||||
function uniPrePlugin(options = {}) {
|
||||
const filter = (0, pluginutils_1.createFilter)(options.include, options.exclude);
|
||||
const preJsFile = uni_cli_shared_1.preUVueJs;
|
||||
const preHtmlFile = uni_cli_shared_1.preUVueHtml;
|
||||
return {
|
||||
name: 'uni:pre',
|
||||
transform(code, id) {
|
||||
if (!filter(id)) {
|
||||
return;
|
||||
}
|
||||
const { filename } = (0, uni_cli_shared_1.parseVueRequest)(id);
|
||||
const extname = path_1.default.extname(filename);
|
||||
const isHtml = PRE_HTML_EXTNAME.includes(extname);
|
||||
const isJs = PRE_JS_EXTNAME.includes(extname);
|
||||
const isPre = isHtml || isJs;
|
||||
if (isPre) {
|
||||
debugPreJsTry(id);
|
||||
}
|
||||
const hasEndif = isPre && code.includes('#endif');
|
||||
if (!hasEndif) {
|
||||
return;
|
||||
}
|
||||
if (isHtml) {
|
||||
code = preHtmlFile(code);
|
||||
debugPreHtml(id);
|
||||
}
|
||||
if (isJs) {
|
||||
code = preJsFile(code);
|
||||
debugPreJs(id);
|
||||
}
|
||||
return {
|
||||
code,
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
exports.uniPrePlugin = uniPrePlugin;
|
||||
|
||||
}, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
|
||||
return __REQUIRE__(1745998156416);
|
||||
})()
|
||||
//miniprogram-npm-outsideDeps=["@dcloudio/uni-cli-shared","./plugins/uvue","./plugins/uvue/index","path","fs-extra","@dcloudio/uni-i18n","es-module-lexer","@vue/shared","picocolors","@dcloudio/uni-nvue-styler","debug","@rollup/pluginutils"]
|
||||
//# sourceMappingURL=index.js.map
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user