提交 9b23e528 编写于 作者: fxy060608's avatar fxy060608

feat(cli): transform App.vue

上级 dbc1bc9d
export * from './vue'
export * from './json'
export * from './easycom/index'
export * from './vueCompilerOptions'
export * from './preprocess/index'
export * from './transforms/transformBuiltInComponent'
export * from './transforms/transformBuiltInEasycom'
export * from './transforms/transformEasycom'
import { NodeTransform } from '@vue/compiler-core'
import { isComponentNode } from '../easycom/index'
export const transformBuiltInEasycom: NodeTransform = (node) => {
if (!isComponentNode(node)) {
return
}
if (node.tag === 'match-media' && process.env.UNI_PLATFORM !== 'mp-weixin') {
node.tag = 'uni-match-media'
}
}
......@@ -2,14 +2,13 @@ import { CompilerOptions } from '@vue/compiler-sfc'
import {
COMPONENT_PREFIX,
isBuiltInComponent,
isNativeTag,
isBuiltInComponent,
} from '@dcloudio/uni-shared'
import { transformBuiltInComponent } from './transforms/transformBuiltInComponent'
import { transformBuiltInEasycom } from './transforms/transformBuiltInEasycom'
import { transformEasycom } from './transforms/transformEasycom'
import { isEasycomTag } from './easycom'
import { isEasycomTag } from '../easycom'
import { transformEasycom, transformBuiltInEasycom } from './transforms/easycom'
import { transformBuiltInComponent } from './transforms/builtInComponent'
interface CodegenContext {
push: (code: string, node: any) => void
......
......@@ -10,7 +10,7 @@ import {
import { COMPONENT_PREFIX, isBuiltInComponent } from '@dcloudio/uni-shared'
import { addAutoImport, isComponentNode } from '../easycom'
import { addAutoImport, isComponentNode } from '../../easycom'
const COMPONENTS_PATH = '@dcloudio/uni-h5/dist/uni-h5.esm.js'
......@@ -44,6 +44,9 @@ function createStyleImportItem(oldTag: string, node: ElementNode) {
}
export const transformBuiltInComponent: NodeTransform = (node, context) => {
if (process.env.UNI_PLATFORM !== 'h5') {
return
}
if (!isComponentNode(node)) {
return
}
......
......@@ -16,7 +16,7 @@ import {
matchEasycom,
addAutoImport,
isComponentNode,
} from '../easycom'
} from '../../easycom'
function createImportItem(path: string, node: ComponentNode) {
const tag = node.tag
......@@ -69,3 +69,12 @@ export const transformEasycom: NodeTransform = (node, context) => {
addAutoImport(createImportItem(path, node), context)
}
}
export const transformBuiltInEasycom: NodeTransform = (node) => {
if (!isComponentNode(node)) {
return
}
if (node.tag === 'match-media' && process.env.UNI_PLATFORM !== 'mp-weixin') {
node.tag = 'uni-match-media'
}
}
......@@ -5,7 +5,8 @@
"main": "dist/uni-h5.esm.js",
"module": "dist/uni-h5.esm.js",
"files": [
"dist"
"dist",
"style"
],
"sideEffects": [
"dist/uni-h5.css"
......
......@@ -132,13 +132,3 @@ export default {
}
}
</script>
<style>
@import url('./index.css');
uni-app {
display: block;
box-sizing: border-box;
width: 100%;
height: 100%;
}
</style>
......@@ -177,3 +177,12 @@ uni-page {
[nvue] uni-swiper-item {
position: absolute;
}
uni-app {
display: block;
box-sizing: border-box;
width: 100%;
height: 100%;
}
\ No newline at end of file
import { VitePluginUniResolvedOptions } from '.'
const defaultPlatform = 'h5'
export function initEnv(_options: VitePluginUniResolvedOptions) {
process.env.UNI_PLATFORM = process.env.UNI_PLATFORM || defaultPlatform
}
......@@ -2,6 +2,7 @@ import path from 'path'
import { Plugin, ViteDevServer } from 'vite'
import { initEnv } from './env'
import { createLoad } from './load'
import { createConfig } from './config'
import { createResolveId } from './resolveId'
......@@ -28,6 +29,7 @@ export default function uniPlugin(
root: process.cwd(),
inputDir: rawOptions.inputDir || path.resolve(process.cwd(), 'src'),
}
initEnv(options)
return {
name: 'vite:uni',
config: createConfig(options),
......
import fs from 'fs'
import path from 'path'
import slash from 'slash'
import { VitePluginUniResolvedOptions } from '..'
let appVuePath: string
export const app = {
test(id: string, inputDir: string) {
if (!appVuePath) {
appVuePath = slash(path.resolve(inputDir, 'App.vue'))
}
return id === appVuePath
},
load(filename: string, _options: VitePluginUniResolvedOptions) {
// TODO 等待plugin-vue修复node_modules中资源引用失败的Bug
// <style src="@dcloudio/uni-h5/style/base.css"/>
return `<template><VUniApp/></template>${fs
.readFileSync(filename, 'utf-8')
.toString()}`
},
}
......@@ -2,12 +2,13 @@ import debug from 'debug'
import { Plugin } from 'vite'
import { VitePluginUniResolvedOptions } from '..'
import { app } from './app'
import { main } from './main'
import { pages } from './pages'
const debugLoad = debug('uni:load')
const loads = [main, pages]
const loads = [app, main, pages]
export function createLoad(
options: VitePluginUniResolvedOptions
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册