提交 191f250e 编写于 作者: fxy060608's avatar fxy060608

chore: merge

上级 1f1015b1
......@@ -9,6 +9,7 @@ import {
cssPostPlugin,
formatAtFilename,
generateCodeFrame,
insertBeforePlugin,
normalizePath,
parseVueRequest,
resolveMainPathOnce,
......@@ -20,14 +21,12 @@ import { genClassName, isVue } from './utils'
export function uniAppCssPlugin(): Plugin {
const mainUTS = resolveMainPathOnce(process.env.UNI_INPUT_DIR)
let resolvedConfig: ResolvedConfig
const name = 'uni:app-uvue-css'
return {
name: 'uni:app-uvue-css',
name,
apply: 'build',
configResolved(config) {
resolvedConfig = config
const plugins = config.plugins as Plugin[]
// 增加 css plugins
plugins.push(cssPlugin(config))
const uvueCssPostPlugin = cssPostPlugin(config, {
isJsCode: true,
platform: process.env.UNI_PLATFORM,
......@@ -42,25 +41,46 @@ export function uniAppCssPlugin(): Plugin {
)
}
},
chunkCssCode(filename, cssCode) {
return (
`export const ${genClassName(
filename.replace('.style.uts', '')
)}Styles = ` + cssCode
)
async chunkCssCode(filename, cssCode) {
const { code, messages } = await parse(cssCode, {
filename,
logLevel: 'ERROR',
map: true,
ts: true,
})
messages.forEach((message) => {
if (message.type === 'error') {
let msg = `[plugin:uni:app-uvue-css] ${message.text}`
if (message.line && message.column) {
msg += `\n${generateCodeFrame(cssCode, {
line: message.line,
column: message.column,
})}`
}
msg += `\n${formatAtFilename(filename)}`
resolvedConfig.logger.error(colors.red(msg))
}
})
return `export const ${genClassName(
filename.replace('.style.uts', '')
)}Styles = [${code}]`
},
})
plugins.push(uvueCssPostPlugin)
// 增加 css plugins
insertBeforePlugin(cssPlugin(config), name, config)
;(config.plugins as Plugin[]).push(uvueCssPostPlugin)
},
async transform(source, filename) {
if (!cssLangRE.test(filename) || commonjsProxyRE.test(filename)) {
return
}
const { code, messages } = await parse(source, {
// 仅做校验使用
const { messages } = await parse(source, {
filename,
logLevel: 'WARNING',
map: true,
ts: true,
noCode: true,
})
messages.forEach((message) => {
if (message.type === 'warning') {
......@@ -75,7 +95,7 @@ export function uniAppCssPlugin(): Plugin {
resolvedConfig.logger.warn(colors.yellow(msg))
}
})
return { code, map: { mappings: '' } }
return { code: source }
},
}
}
......@@ -12,7 +12,7 @@ export function defineUniMainJsPlugin(
const opts = {
resolvedConfig: {},
filter(id) {
return id === mainJsPath || id === mainTsPath
return id === mainJsPath || id === mainTsPath || id === mainUTsPath
},
} as UniViteFilterPluginOptions
......@@ -21,6 +21,7 @@ export function defineUniMainJsPlugin(
let mainJsPath = ''
let mainTsPath = ''
let mainUTsPath = ''
plugin.configResolved = function (config) {
opts.resolvedConfig = config
const mainPath = normalizePath(
......@@ -28,6 +29,7 @@ export function defineUniMainJsPlugin(
)
mainJsPath = mainPath + '.js'
mainTsPath = mainPath + '.ts'
mainUTsPath = mainPath + '.uts'
return origConfigResolved && origConfigResolved(config)
}
......
......@@ -358,18 +358,8 @@ export function cssPostPlugin(
.map((id) => styles.get(id) || '')
.join('\n')
}
const genJsCode = (fileName: string) => {
const res: string[] = []
;[...cssChunks.get(fileName)!].forEach((id) => {
const jsCode = styles.get(id) || ''
if (jsCode) {
res.push(jsCode)
}
})
return `[${res.join(', ')}]`
}
for (const filename of cssChunks.keys()) {
const cssCode = isJsCode ? genJsCode(filename) : genCssCode(filename)
const cssCode = genCssCode(filename)
let source = await processChunkCSS(cssCode, {
filename: filename,
inlined: false,
......
......@@ -57,3 +57,14 @@ export function removePlugins(
}
})
}
export function insertBeforePlugin(
plugin: Plugin,
before: string,
config: ResolvedConfig
) {
const index = config.plugins.findIndex((p) => p.name === before)
if (index > -1) {
;(config.plugins as Plugin[]).splice(index, 0, plugin)
}
}
......@@ -62,7 +62,7 @@ function transformSwiper(node) {
}
}
const customElements = ['aweme-data'];
const customElements = ['aweme-data', 'consume-card'];
const projectConfigFilename = 'project.config.json';
const nodeTransforms = [
uniCliShared.transformRef,
......
......@@ -7,6 +7,7 @@ interface ParseOptions extends NormalizeOptions {
filename?: string
map?: boolean
ts?: boolean
noCode?: boolean
}
export async function parse(input: string, options: ParseOptions = {}) {
......@@ -19,12 +20,15 @@ export async function parse(input: string, options: ParseOptions = {}) {
root: null,
messages: [
{
type: 'warning',
type: 'error',
text: err.message,
} as Message,
],
}
})
if (options.noCode === true) {
return { code: '', messages }
}
const obj = root ? objectifier(root) : {}
if (options.map) {
return { code: mapToInitString(objToMap(obj), options.ts), messages }
......
......@@ -4,7 +4,7 @@
"sourceMap": false,
"declaration": true,
"declarationDir": "./dist/packages/uni-nvue-styler/src",
"target": "es2015",
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"allowJs": false,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册