Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Commit

Permalink
Fix asset transform paths, fix SFCs with no template tag, fix babel p…
Browse files Browse the repository at this point in the history
…reset resolution (#19)

* fix: use root from config when transforming asset urls

* fix: handle windows paths when transforming asset urls

* fix: fix uninitialized const

* fix: resolve babel preset from correct location

* fix: don't try to transform jsx in .ts files
  • Loading branch information
andrew0 committed Jan 23, 2021
1 parent 19f7274 commit 8a6cea3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ export function createVuePlugin(rawOptions: VueViteOptions = {}): Plugin {
return handleHotUpdate(ctx, options)
},

configResolved(config) {
options.isProduction = config.isProduction
options.root = config.root
},

configureServer(server) {
options.devServer = server
},
Expand Down Expand Up @@ -121,7 +126,7 @@ export function createVuePlugin(rawOptions: VueViteOptions = {}): Plugin {
async transform(code, id) {
const { filename, query } = parseVueRequest(id)

if (/\.(tsx?|jsx)$/.test(id)) {
if (/\.(tsx|jsx)$/.test(id)) {
return transformVueJsx(code, id)
}

Expand Down
2 changes: 1 addition & 1 deletion src/jsxTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { transform } from '@babel/core'
// todo hmr
export function transformVueJsx(code: string, filename: string) {
const result = transform(code, {
presets: ['@vue/babel-preset-jsx'],
presets: [require('@vue/babel-preset-jsx')],
filename,
sourceMaps: true,
})!
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ async function genScriptCode(
function genTemplateRequest(filename: string, descriptor: SFCDescriptor) {
const template = descriptor.template
if (!template) {
return { code: `const render, staticRenderFns` }
return { code: `let render, staticRenderFns` }
}
if (template.src) {
linkSrcToDescriptor(template.src, filename, descriptor)
Expand Down
3 changes: 2 additions & 1 deletion src/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { SFCBlock, compileTemplate } from '@vue/component-compiler-utils'
import * as vueTemplateCompiler from 'vue-template-compiler'
import path from 'path'
import { TransformPluginContext } from 'rollup'
import slash from 'slash'
import { ResolvedOptions } from './index'
import { createRollupError } from './utils/error'

Expand All @@ -19,7 +20,7 @@ export function compileSFCTemplate(
transformAssetUrls: true,
transformAssetUrlsOptions: devServer
? {
base: path.posix.dirname(path.relative(root, filename)),
base: '/' + slash(path.relative(root, path.dirname(filename))),
}
: {},
isProduction,
Expand Down

0 comments on commit 8a6cea3

Please sign in to comment.