提交 424a83a4 编写于 作者: fxy060608's avatar fxy060608

chore: merge

import { defineUniMainJsPlugin } from '@dcloudio/uni-cli-shared'
import { defineUniMainJsPlugin, PAGES_JSON_JS } from '@dcloudio/uni-cli-shared'
export function uniMainJsPlugin() {
return defineUniMainJsPlugin((opts) => {
......@@ -11,7 +11,7 @@ export function uniMainJsPlugin() {
? createApp(code)
: createLegacyApp(code)
return {
code: `import './pages.json.js';` + code,
code: `import './${PAGES_JSON_JS}';` + code,
map: { mappings: '' },
}
}
......
......@@ -8,6 +8,7 @@ import {
normalizePagesJson,
parseManifestJsonOnce,
getLocaleFiles,
MANIFEST_JSON_JS,
} from '@dcloudio/uni-cli-shared'
export function uniPagesJsonPlugin(): Plugin {
......@@ -43,7 +44,8 @@ export function uniPagesJsonPlugin(): Plugin {
})
return {
code:
`import './manifest.json.js'\n` + normalizeAppPagesJson(pagesJson),
`import './${MANIFEST_JSON_JS}'\n` +
normalizeAppPagesJson(pagesJson),
map: { mappings: '' },
}
},
......
......@@ -16,6 +16,12 @@ export const extensions = [
'.json',
].concat(EXTNAME_VUE)
export const PAGES_JSON_JS = 'pages-json-js'
export const MANIFEST_JSON_JS = 'manifest-json-js'
export const JSON_JS_MAP = {
'pages.json': PAGES_JSON_JS,
'manifest.json': MANIFEST_JSON_JS,
} as const
export const ASSETS_INLINE_LIMIT = 40 * 1024
export const APP_SERVICE_FILENAME = 'app-service.js'
......
import fs from 'fs'
import path from 'path'
import { JSON_JS_MAP } from '../../constants'
import { normalizePath } from '../../utils'
import {
CreateUniViteFilterPlugin,
......@@ -11,7 +12,7 @@ export const defineUniManifestJsonPlugin =
createDefineJsonJsPlugin('manifest.json')
function createDefineJsonJsPlugin(name: 'pages.json' | 'manifest.json') {
const JSON_JS = name + '.js'
const JSON_JS = JSON_JS_MAP[name]
return function (createVitePlugin: CreateUniViteFilterPlugin) {
const opts = {
resolvedConfig: {},
......@@ -26,6 +27,7 @@ function createDefineJsonJsPlugin(name: 'pages.json' | 'manifest.json') {
const origConfigResolved = plugin.configResolved
let jsonPath = ''
let jsonJsPath = ''
plugin.resolveId = function (id, importer, options) {
const res =
......@@ -34,12 +36,13 @@ function createDefineJsonJsPlugin(name: 'pages.json' | 'manifest.json') {
return res
}
if (id.endsWith(JSON_JS)) {
return jsonPath + '.js'
return jsonJsPath
}
}
plugin.configResolved = function (config) {
opts.resolvedConfig = config
jsonPath = normalizePath(path.join(process.env.UNI_INPUT_DIR, name))
jsonJsPath = normalizePath(path.join(process.env.UNI_INPUT_DIR, JSON_JS))
return origConfigResolved && origConfigResolved(config)
}
......
......@@ -29,6 +29,7 @@ import type Less from 'less'
import type { Alias } from 'types/alias'
import { transform, formatMessages } from 'esbuild'
import { preCss, preNVueCss } from '../../../../preprocess'
import { PAGES_JSON_JS } from '../../../../constants'
// const debug = createDebugger('vite:css')
export interface CSSOptions {
......@@ -196,7 +197,7 @@ function findCssModuleIds(
const moduleInfo = this.getModuleInfo(moduleId)
if (moduleInfo) {
moduleInfo.importedIds.forEach((id) => {
if (id.includes('pages.json.js')) {
if (id.includes(PAGES_JSON_JS)) {
// 查询main.js时,需要忽略pages.json.js,否则会把所有页面样式加进来
return
}
......
......@@ -5,7 +5,9 @@ import { extend } from '@vue/shared'
import {
initEasycomsOnce,
initFeatures,
MANIFEST_JSON_JS,
normalizePath,
PAGES_JSON_JS,
parseManifestJson,
parsePagesJson,
resolveComponentsLibPath,
......@@ -29,8 +31,8 @@ export function createHandleHotUpdate(): Plugin['handleHotUpdate'] {
const platform = process.env.UNI_PLATFORM
if (!invalidateFiles) {
invalidateFiles = [
path.resolve(inputDir, 'pages.json.js'),
path.resolve(inputDir, 'manifest.json.js'),
path.resolve(inputDir, PAGES_JSON_JS),
path.resolve(inputDir, MANIFEST_JSON_JS),
require.resolve('@dcloudio/uni-h5/dist/uni-h5.es.js'),
]
try {
......
import path from 'path'
import {
defineUniMainJsPlugin,
isSsr,
normalizePath,
PAGES_JSON_JS,
} from '@dcloudio/uni-cli-shared'
import { isSSR, isSsrManifest } from '../utils'
export function uniMainJsPlugin() {
return defineUniMainJsPlugin((opts) => {
let pagesJsonJsPath = ''
let runSSR = false
return {
name: 'uni:h5-main-js',
enforce: 'pre',
configResolved(config) {
pagesJsonJsPath = normalizePath(
path.resolve(process.env.UNI_INPUT_DIR, 'pages.json.js')
)
runSSR =
isSsr(config.command, config) || isSsrManifest(config.command, config)
},
......@@ -31,7 +26,7 @@ export function uniMainJsPlugin() {
? createSSRServerApp(code)
: createSSRClientApp(code)
}
code = `import '${pagesJsonJsPath}';${code}`
code = `import './${PAGES_JSON_JS}';${code}`
return {
code,
map: this.getCombinedSourcemap(),
......
import path from 'path'
import type { Plugin, ResolvedConfig } from 'vite'
import {
API_DEPS_CSS,
......@@ -10,9 +9,9 @@ import {
defineUniPagesJsonPlugin,
normalizePagesRoute,
normalizePagePath,
normalizePath,
isEnableTreeShaking,
parseManifestJsonOnce,
MANIFEST_JSON_JS,
} from '@dcloudio/uni-cli-shared'
import { isSSR } from '../utils'
......@@ -49,15 +48,12 @@ function generatePagesJsonCode(
const definePagesCode = generatePagesDefineCode(pagesJson, config)
const uniRoutesCode = generateRoutes(globalName, pagesJson, config)
const uniConfigCode = generateConfig(globalName, pagesJson, config)
const manifestJsonPath = normalizePath(
path.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, useI18n, setupWindow, setupPage } from '@dcloudio/uni-h5'
import { appid, debug, networkTimeout, router, async, sdkConfigs, qqMapKey, googleMapKey, nvue, locale, fallbackLocale } from '${manifestJsonPath}'
import { appid, debug, networkTimeout, router, async, sdkConfigs, qqMapKey, googleMapKey, nvue, locale, fallbackLocale } from './${MANIFEST_JSON_JS}'
const locales = import.meta.globEager('./locale/*.json')
${importLayoutComponentsCode}
const extend = Object.assign
......
import {
defineUniMainJsPlugin,
PAGES_JSON_JS,
parseProgram,
transformDynamicImports,
updateMiniProgramGlobalComponents,
......@@ -39,7 +40,7 @@ export function uniMainJsPlugin(
})
return {
code:
`import 'plugin-vue:export-helper';import 'uni-mp-runtime';import './pages.json.js';` +
`import 'plugin-vue:export-helper';import 'uni-mp-runtime';import './${PAGES_JSON_JS}';` +
code,
map,
}
......
......@@ -13,6 +13,7 @@ import {
addMiniProgramAppJson,
findChangedJsonFiles,
mergeMiniProgramAppJson,
MANIFEST_JSON_JS,
} from '@dcloudio/uni-cli-shared'
import { virtualPagePath } from './entry'
import { UniMiniProgramPluginOptions } from '../plugin'
......@@ -73,7 +74,7 @@ export function uniPagesJsonPlugin(
addMiniProgramPageJson(name, pageJsons[name])
})
return {
code: `import './manifest.json.js'\n` + importPagesCode(appJson),
code: `import './${MANIFEST_JSON_JS}'\n` + importPagesCode(appJson),
map: { mappings: '' },
}
},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册