Skip to content

Commit

Permalink
fix: default enable JSX
Browse files Browse the repository at this point in the history
  • Loading branch information
Chieffo2021 committed Jun 17, 2021
1 parent 4b0ee62 commit 483a24f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 23 deletions.
1 change: 0 additions & 1 deletion src/transform/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ViteConfig } from '../config/vite';

export interface TransformContext {
vueVersion : number;
jsx : boolean;
config : ViteConfig;
importList : string[];
}
26 changes: 4 additions & 22 deletions src/transform/transformVuecli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export class VueCliTransformer implements Transformer {

context : TransformContext = {
vueVersion: DEFAULT_VUE_VERSION,
jsx: this.useJsx(),
config: {},
importList: [],
}
Expand Down Expand Up @@ -107,7 +106,7 @@ export class VueCliTransformer implements Transformer {

config.resolve = {};
config.resolve.alias = finalAlias;


config.resolve.extensions = [
'.mjs',
Expand All @@ -121,35 +120,18 @@ export class VueCliTransformer implements Transformer {
return config;
}

public useJsx() : boolean {
try {
const jsx = require('babel-plugin-transform-vue-jsx');
if (jsx) {
return true;
}
} catch (error) {} //eslint-disable-line no-empty

return false;
}

public transformVue(context: TransformContext) : void {
const plugins: RawValue[] = [];
if (context.vueVersion === 2) {
context.importList.push(
'import { createVuePlugin } from \'vite-plugin-vue2\';'
);
if (context.jsx) {
plugins.push(new RawValue('createVuePlugin({jsx:true})'));
} else {
plugins.push(new RawValue('createVuePlugin()'));
}
plugins.push(new RawValue('createVuePlugin({jsx:true})'));
} else {
context.importList.push('import vue from \'@vitejs/plugin-vue\';');
plugins.push(new RawValue('vue()'));
if (context.jsx) {
context.importList.push('import vueJsx from \'@vitejs/plugin-vue-jsx\';');
plugins.push(new RawValue('vueJsx()'));
}
context.importList.push('import vueJsx from \'@vitejs/plugin-vue-jsx\';');
plugins.push(new RawValue('vueJsx()'));
}

context.importList.push('import envCompatible from \'vite-plugin-env-compatible\';');
Expand Down

0 comments on commit 483a24f

Please sign in to comment.