@dcloudio/uni-app-vite
Advanced tools
Comparing version 3.0.0-alpha-3000020210618002 to 3.0.0-alpha-3000020210708001
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const fs_1 = __importDefault(require("fs")); | ||
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared"); | ||
const plugin_1 = require("./plugin"); | ||
const copy_1 = require("./plugins/copy"); | ||
const mainJs_1 = require("./plugins/mainJs"); | ||
@@ -7,16 +14,12 @@ const manifestJson_1 = require("./plugins/manifestJson"); | ||
const resolveId_1 = require("./plugins/resolveId"); | ||
const UniAppPlugin = { | ||
name: 'vite:uni-app', | ||
uni: { | ||
transformEvent: { | ||
tap: 'click', | ||
}, | ||
}, | ||
}; | ||
exports.default = [ | ||
resolveId_1.uniResolveIdPlugin(), | ||
copy_1.uniCopyPlugin(), | ||
mainJs_1.uniMainJsPlugin(), | ||
manifestJson_1.uniManifestJsonPlugin(), | ||
pagesJson_1.uniPagesJsonPlugin(), | ||
UniAppPlugin, | ||
plugin_1.UniAppPlugin, | ||
uni_cli_shared_1.uniCssPlugin({ | ||
app: fs_1.default.readFileSync(require.resolve('@dcloudio/uni-app-plus/dist/style.css'), 'utf8'), | ||
}), | ||
]; |
@@ -16,3 +16,3 @@ "use strict"; | ||
return { | ||
code, | ||
code: `import './pages.json.js';` + code, | ||
map: this.getCombinedSourcemap(), | ||
@@ -27,6 +27,6 @@ }; | ||
function createApp(code) { | ||
return `createApp().app.mount("#app");${code.replace('createSSRApp', 'createVueApp as createSSRApp')}`; | ||
return `const __app__=createApp().app;__app__._component.render=()=>{};__app__.use(uni.__vuePlugin).mount("#app");${code.replace('createSSRApp', 'createVueApp as createSSRApp')}`; | ||
} | ||
function createLegacyApp(code) { | ||
return `function createApp(rootComponent,rootProps){return createVueApp(rootComponent, rootProps)};${code.replace('createApp', 'createVueApp')}`; | ||
return `function createApp(rootComponent,rootProps){const app=createVueApp(rootComponent,rootProps).use(uni.__vuePlugin);app.render=()=>{};const oldMount=app.mount;app.mount=(container)=>{const appVm=oldMount.call(app,container);return appVm;};return app;};${code.replace('createApp', 'createVueApp')}`; | ||
} |
"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 path_1 = __importDefault(require("path")); | ||
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared"); | ||
const defaultRouter = { | ||
mode: 'hash', | ||
base: '/', | ||
}; | ||
const defaultAsync = { | ||
loading: 'AsyncLoading', | ||
error: 'AsyncError', | ||
delay: 200, | ||
timeout: 60000, | ||
suspensible: true, | ||
}; | ||
const defaultNetworkTimeout = { | ||
request: 60000, | ||
connectSocket: 60000, | ||
uploadFile: 60000, | ||
downloadFile: 60000, | ||
}; | ||
const defaultQQMapKey = 'XVXBZ-NDMC4-JOGUS-XGIEE-QVHDZ-AMFV2'; | ||
function uniManifestJsonPlugin() { | ||
let manifestJson; | ||
return uni_cli_shared_1.defineUniManifestJsonPlugin((opts) => { | ||
@@ -32,36 +19,19 @@ return { | ||
} | ||
const manifest = JSON.parse(code); | ||
const { debug, h5 } = manifest; | ||
const appid = (manifest.appid || '').replace('__UNI__', ''); | ||
const router = Object.assign(Object.assign({}, defaultRouter), ((h5 && h5.router) || {})); | ||
if (!router.base) { | ||
router.base = '/'; | ||
} | ||
const async = Object.assign(Object.assign({}, defaultAsync), ((h5 && h5.async) || {})); | ||
const networkTimeout = Object.assign(Object.assign({}, defaultNetworkTimeout), (manifest.networkTimeout || {})); | ||
const sdkConfigs = (h5 && h5.sdkConfigs) || {}; | ||
const qqMapKey = (sdkConfigs.maps && | ||
sdkConfigs.maps.qqmap && | ||
sdkConfigs.maps.qqmap.key) || | ||
defaultQQMapKey; | ||
const flexDirection = (manifest['app'] && | ||
manifest['app'].nvue && | ||
manifest['app'].nvue['flex-direction']) || | ||
'column'; | ||
return { | ||
code: `export const appid = '${appid || ''}' | ||
export const debug = ${!!debug} | ||
export const nvue = ${JSON.stringify({ | ||
'flex-direction': flexDirection, | ||
})} | ||
export const networkTimeout = ${JSON.stringify(networkTimeout)} | ||
// h5 | ||
export const router = ${JSON.stringify(router)} | ||
export const async = ${JSON.stringify(async)} | ||
export const qqMapKey = '${qqMapKey}' | ||
export const sdkConfigs = ${JSON.stringify(sdkConfigs)} | ||
`, | ||
map: { mappings: '' }, | ||
}; | ||
this.addWatchFile(path_1.default.resolve(process.env.UNI_INPUT_DIR, 'manifest.json')); | ||
manifestJson = uni_cli_shared_1.normalizeAppManifestJson(JSON.parse(code), uni_cli_shared_1.parsePagesJsonOnce(process.env.UNI_INPUT_DIR, process.env.UNI_PLATFORM)); | ||
return ''; | ||
}, | ||
generateBundle() { | ||
// 生成一个空的app-config.js,兼容基座已有规范 | ||
this.emitFile({ | ||
fileName: `app-config.js`, | ||
type: 'asset', | ||
source: '(function(){})();', | ||
}); | ||
this.emitFile({ | ||
fileName: `manifest.json`, | ||
type: 'asset', | ||
source: JSON.stringify(manifestJson, null, 2), | ||
}); | ||
}, | ||
}; | ||
@@ -68,0 +38,0 @@ }); |
@@ -7,9 +7,6 @@ "use strict"; | ||
exports.uniPagesJsonPlugin = void 0; | ||
const fs_1 = __importDefault(require("fs")); | ||
const path_1 = __importDefault(require("path")); | ||
const slash_1 = __importDefault(require("slash")); | ||
const shared_1 = require("@vue/shared"); | ||
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared"); | ||
const pkg = require('@dcloudio/vite-plugin-uni/package.json'); | ||
function uniPagesJsonPlugin() { | ||
let pagesJson; | ||
return uni_cli_shared_1.defineUniPagesJsonPlugin((opts) => { | ||
@@ -19,14 +16,21 @@ return { | ||
enforce: 'pre', | ||
transform(code, id, ssr) { | ||
if (opts.filter(id)) { | ||
const { resolvedConfig } = opts; | ||
return { | ||
code: (resolvedConfig.command === 'serve' || | ||
(resolvedConfig.command === 'build' && ssr) | ||
? registerGlobalCode(resolvedConfig, ssr) | ||
: '') + generatePagesJsonCode(ssr, code, resolvedConfig), | ||
map: { mappings: '' }, | ||
}; | ||
transform(code, id) { | ||
if (!opts.filter(id)) { | ||
return; | ||
} | ||
this.addWatchFile(path_1.default.resolve(process.env.UNI_INPUT_DIR, 'pages.json')); | ||
pagesJson = uni_cli_shared_1.normalizePagesJson(code, process.env.UNI_PLATFORM); | ||
// TODO subpackages | ||
pagesJson.pages.forEach((page) => { | ||
this.addWatchFile(path_1.default.resolve(process.env.UNI_INPUT_DIR, page.path + '.vue')); | ||
}); | ||
return (`import './manifest.json.js'\n` + uni_cli_shared_1.normalizeAppPagesJson(pagesJson)); | ||
}, | ||
generateBundle() { | ||
this.emitFile({ | ||
fileName: `app-config-service.js`, | ||
type: 'asset', | ||
source: uni_cli_shared_1.normalizeAppConfigService(pagesJson, uni_cli_shared_1.parseManifestJsonOnce(process.env.UNI_INPUT_DIR)), | ||
}); | ||
}, | ||
}; | ||
@@ -36,195 +40,1 @@ }); | ||
exports.uniPagesJsonPlugin = uniPagesJsonPlugin; | ||
function generatePagesJsonCode(ssr, jsonStr, config) { | ||
const globalName = getGlobal(ssr); | ||
const pagesJson = uni_cli_shared_1.normalizePagesJson(jsonStr, process.env.UNI_INPUT_DIR, process.env.UNI_PLATFORM); | ||
const { importLayoutComponentsCode, defineLayoutComponentsCode } = generateLayoutComponentsCode(globalName, pagesJson); | ||
const definePagesCode = generatePagesDefineCode(pagesJson, config); | ||
const uniRoutesCode = generateRoutes(globalName, pagesJson, config); | ||
const uniConfigCode = generateConfig(globalName, pagesJson, config); | ||
const manifestJsonPath = slash_1.default(path_1.default.resolve(process.env.UNI_INPUT_DIR, 'manifest.json.js')); | ||
const cssCode = generateCssCode(config); | ||
return ` | ||
import { defineAsyncComponent, resolveComponent, createVNode, withCtx, openBlock, createBlock } from 'vue' | ||
import { PageComponent, AsyncLoadingComponent, AsyncErrorComponent } from '@dcloudio/uni-h5' | ||
import { appid, debug, networkTimeout, router, async, sdkConfigs, qqMapKey, nvue } from '${manifestJsonPath}' | ||
${importLayoutComponentsCode} | ||
const extend = Object.assign | ||
${cssCode} | ||
${uniConfigCode} | ||
${defineLayoutComponentsCode} | ||
${definePagesCode} | ||
${uniRoutesCode} | ||
${config.command === 'serve' ? hmrCode : ''} | ||
export {} | ||
`; | ||
} | ||
const hmrCode = `if(import.meta.hot){ | ||
import.meta.hot.on('invalidate', (data) => { | ||
import.meta.hot.invalidate() | ||
}) | ||
}`; | ||
function getGlobal(ssr) { | ||
return ssr ? 'global' : 'window'; | ||
} | ||
function registerGlobalCode(config, ssr) { | ||
const name = getGlobal(ssr); | ||
const rpx2pxCode = !ssr && config.define.__UNI_FEATURE_RPX__ | ||
? `import {upx2px} from '@dcloudio/uni-h5' | ||
${name}.rpx2px = upx2px | ||
` | ||
: ''; | ||
return `${rpx2pxCode} | ||
import {uni,getCurrentPages,getApp,UniServiceJSBridge,UniViewJSBridge} from '@dcloudio/uni-h5' | ||
${name}.getApp = getApp | ||
${name}.getCurrentPages = getCurrentPages | ||
${name}.uni = uni | ||
${name}.UniViewJSBridge = UniViewJSBridge | ||
${name}.UniServiceJSBridge = UniServiceJSBridge | ||
`; | ||
} | ||
function normalizePageIdentifier(path) { | ||
return shared_1.capitalize(shared_1.camelize(path.replace(/\//g, '-'))); | ||
} | ||
function generateCssCode(config) { | ||
const define = config.define; | ||
const cssFiles = [uni_cli_shared_1.H5_FRAMEWORK_STYLE_PATH + 'base.css']; | ||
// if (define.__UNI_FEATURE_PAGES__) { | ||
cssFiles.push(uni_cli_shared_1.H5_FRAMEWORK_STYLE_PATH + 'async.css'); | ||
// } | ||
if (define.__UNI_FEATURE_RESPONSIVE__) { | ||
cssFiles.push(uni_cli_shared_1.H5_FRAMEWORK_STYLE_PATH + 'layout.css'); | ||
} | ||
if (define.__UNI_FEATURE_NAVIGATIONBAR__) { | ||
cssFiles.push(uni_cli_shared_1.H5_FRAMEWORK_STYLE_PATH + 'pageHead.css'); | ||
} | ||
if (define.__UNI_FEATURE_TABBAR__) { | ||
cssFiles.push(uni_cli_shared_1.H5_FRAMEWORK_STYLE_PATH + 'tabBar.css'); | ||
} | ||
if (define.__UNI_FEATURE_NVUE__) { | ||
cssFiles.push(uni_cli_shared_1.H5_FRAMEWORK_STYLE_PATH + 'nvue.css'); | ||
} | ||
if (define.__UNI_FEATURE_PULL_DOWN_REFRESH__) { | ||
cssFiles.push(uni_cli_shared_1.H5_FRAMEWORK_STYLE_PATH + 'pageRefresh.css'); | ||
} | ||
if (define.__UNI_FEATURE_NAVIGATIONBAR_SEARCHINPUT__) { | ||
cssFiles.push(uni_cli_shared_1.BASE_COMPONENTS_STYLE_PATH + 'input.css'); | ||
} | ||
if (config.command === 'serve') { | ||
// 开发模式,自动添加所有API相关css | ||
Object.keys(uni_cli_shared_1.API_DEPS_CSS).forEach((name) => { | ||
const styles = uni_cli_shared_1.API_DEPS_CSS[name]; | ||
styles.forEach((style) => { | ||
if (!cssFiles.includes(style)) { | ||
cssFiles.push(style); | ||
} | ||
}); | ||
}); | ||
} | ||
return cssFiles.map((file) => `import '${file}'`).join('\n'); | ||
} | ||
function generateLayoutComponentsCode(globalName, pagesJson) { | ||
const windowNames = [ | ||
'topWindow', | ||
'leftWindow', | ||
'rightWindow', | ||
]; | ||
let importLayoutComponentsCode = ''; | ||
let defineLayoutComponentsCode = `${globalName}.__uniLayout = ${globalName}.__uniLayout || {}\n`; | ||
windowNames.forEach((name) => { | ||
const windowConfig = pagesJson[name]; | ||
if (windowConfig && windowConfig.path) { | ||
importLayoutComponentsCode += `import ${name} from './${windowConfig.path}'\n`; | ||
defineLayoutComponentsCode += `${globalName}.__uniConfig.${name}.component = ${name}\n`; | ||
} | ||
}); | ||
return { | ||
importLayoutComponentsCode, | ||
defineLayoutComponentsCode, | ||
}; | ||
} | ||
function generatePageDefineCode(pageOptions) { | ||
const pageIdent = normalizePageIdentifier(pageOptions.path); | ||
return `const ${pageIdent}Loader = ()=>import('./${pageOptions.path}?mpType=page') | ||
const ${pageIdent} = defineAsyncComponent(extend({loader:${pageIdent}Loader},AsyncComponentOptions))`; | ||
} | ||
function generatePagesDefineCode(pagesJson, _config) { | ||
const { pages } = pagesJson; | ||
return (`const AsyncComponentOptions = { | ||
loadingComponent: AsyncLoadingComponent, | ||
errorComponent: AsyncErrorComponent, | ||
delay: async.delay, | ||
timeout: async.timeout, | ||
suspensible: async.suspensible | ||
} | ||
` + pages.map((pageOptions) => generatePageDefineCode(pageOptions)).join('\n')); | ||
} | ||
function normalizePagesRoute(pagesJson) { | ||
const firstPagePath = pagesJson.pages[0].path; | ||
const tabBarList = (pagesJson.tabBar && pagesJson.tabBar.list) || []; | ||
return pagesJson.pages.map((pageOptions) => { | ||
const pagePath = pageOptions.path; | ||
const name = normalizePageIdentifier(pagePath); | ||
const isEntry = firstPagePath === pagePath ? true : undefined; | ||
const tabBarIndex = tabBarList.findIndex((tabBarPage) => tabBarPage.pagePath === pagePath); | ||
const isTabBar = tabBarIndex !== -1 ? true : undefined; | ||
const isNVue = fs_1.default.existsSync(path_1.default.join(process.env.UNI_INPUT_DIR, pagePath + '.nvue')); | ||
let windowTop = 0; | ||
const meta = shared_1.extend({ | ||
route: pageOptions.path, | ||
isNVue: isNVue ? true : undefined, | ||
isQuit: isEntry || isTabBar ? true : undefined, | ||
isEntry, | ||
isTabBar, | ||
tabBarIndex, | ||
windowTop, | ||
}, pageOptions.style); | ||
return { | ||
name, | ||
path: pageOptions.path, | ||
meta, | ||
}; | ||
}); | ||
} | ||
function generatePageRoute({ name, path, meta }, config) { | ||
const { isEntry } = meta; | ||
const alias = isEntry ? `\n alias:'/${path}',` : ''; | ||
return `{ | ||
path:'/${isEntry ? '' : path}',${alias} | ||
component:{setup(){return ()=>renderPage(${name})}}, | ||
loader: ${normalizePageIdentifier(path)}Loader, | ||
meta: ${JSON.stringify(meta)} | ||
}`; | ||
} | ||
function generatePagesRoute(pagesRouteOptions, config) { | ||
return pagesRouteOptions.map((pageOptions) => generatePageRoute(pageOptions, config)); | ||
} | ||
function generateRoutes(globalName, pagesJson, config) { | ||
return ` | ||
function renderPage(component){ | ||
return (openBlock(), createBlock(PageComponent, null, {page: withCtx(() => [createVNode(component, { ref: "page" }, null, 512 /* NEED_PATCH */)]), _: 1 /* STABLE */})) | ||
} | ||
${globalName}.__uniRoutes=[${[ | ||
...generatePagesRoute(normalizePagesRoute(pagesJson), config), | ||
].join(',')}]`; | ||
} | ||
function generateConfig(globalName, pagesJson, config) { | ||
delete pagesJson.pages; | ||
delete pagesJson.subPackages; | ||
delete pagesJson.subpackages; | ||
pagesJson.compilerVersion = pkg['uni-app'].compilerVersion; | ||
return ((config.command === 'serve' | ||
? '' | ||
: `${globalName}['____'+appid+'____']=true | ||
delete ${globalName}['____'+appid+'____'] | ||
`) + | ||
`${globalName}.__uniConfig=extend(${JSON.stringify(pagesJson)},{ | ||
async, | ||
debug, | ||
networkTimeout, | ||
sdkConfigs, | ||
qqMapKey, | ||
nvue, | ||
router | ||
}) | ||
`); | ||
} |
@@ -7,3 +7,2 @@ "use strict"; | ||
exports.uniResolveIdPlugin = void 0; | ||
const path_1 = __importDefault(require("path")); | ||
const debug_1 = __importDefault(require("debug")); | ||
@@ -18,9 +17,7 @@ const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared"); | ||
configResolved() { | ||
const { MODE } = uni_cli_shared_1.parseCompatConfigOnce(process.env.UNI_INPUT_DIR); | ||
resolveCache['@dcloudio/uni-h5'] = uni_cli_shared_1.resolveBuiltIn(path_1.default.join('@dcloudio/uni-h5', 'dist/uni-h5.es.js')); | ||
resolveCache['@dcloudio/uni-h5-vue'] = uni_cli_shared_1.resolveBuiltIn(path_1.default.join('@dcloudio/uni-h5-vue', `dist/vue.runtime.${MODE === 2 ? 'compat.' : ''}esm.js`)); | ||
resolveCache['@dcloudio/uni-app-vue'] = uni_cli_shared_1.resolveBuiltIn('@dcloudio/uni-app-vue'); | ||
}, | ||
resolveId(id) { | ||
if (id === 'vue') { | ||
id = '@dcloudio/uni-h5-vue'; | ||
id = '@dcloudio/uni-app-vue'; | ||
} | ||
@@ -32,6 +29,2 @@ const cache = resolveCache[id]; | ||
} | ||
if (id.startsWith('@dcloudio/uni-h5/style') || | ||
id.startsWith('@dcloudio/uni-components/style')) { | ||
return (resolveCache[id] = uni_cli_shared_1.resolveBuiltIn(id)); | ||
} | ||
}, | ||
@@ -38,0 +31,0 @@ }; |
{ | ||
"name": "@dcloudio/uni-app-vite", | ||
"version": "3.0.0-alpha-3000020210618002", | ||
"version": "3.0.0-alpha-3000020210708001", | ||
"description": "uni-app-vite", | ||
@@ -9,3 +9,4 @@ "main": "dist/index.js", | ||
"dist/**/*.js", | ||
"dist/**/*.d.ts" | ||
"dist/**/*.d.ts", | ||
"lib" | ||
], | ||
@@ -26,3 +27,3 @@ "repository": { | ||
"license": "Apache-2.0", | ||
"gitHead": "91d7c6f34134dc2f2ec372b68008db6a58234099" | ||
"gitHead": "b151fe7e8364e3492054835f047ce902f39d8bf1" | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 4 instances in 1 package
733019
18
20651
15
1