-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
298 additions
and
1,963 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# `vue` | ||
|
||
> TODO: description | ||
## Usage | ||
|
||
``` | ||
const cli = require('cli'); | ||
// TODO: DEMONSTRATE API | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"name": "@xus/plugin-lib-vue-jsx", | ||
"version": "0.1.0", | ||
"description": "a bundle for vue jsx", | ||
"main": "dist/index.js", | ||
"typings": "dist/index.d.ts", | ||
"keywords": [ | ||
"cli", | ||
"bundle" | ||
], | ||
"author": "guo.xu <xuguo@outlook.it>", | ||
"homepage": "https://github.com/xus-code/bundle-tools/tree/master/packages/cli#readme", | ||
"license": "MIT", | ||
"files": [ | ||
"dist" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/xus-code/bundle-tools.git" | ||
}, | ||
"scripts": { | ||
"dev:vuejsx": "tsc --watch", | ||
"build:vuejsx": "tsc" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/xus-code/bundle-tools/issues" | ||
}, | ||
"dependencies": { | ||
"@babel/core": "^7.13.10", | ||
"@babel/plugin-transform-typescript": "^7.13.0", | ||
"@vue/babel-plugin-jsx": "^1.0.3", | ||
"@vue/babel-preset-jsx": "^1.2.4", | ||
"@xus/cli-types": "^0.1.0", | ||
"rollup": "^2.40.0" | ||
}, | ||
"devDependencies": { | ||
"@types/babel__core": "^7.1.12" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { IPlugin } from '@xus/cli-types' | ||
import { vuejsx, IVueJsx } from './plugin' | ||
|
||
export interface IVueJsxOps { | ||
version?: 2 | 3 | ||
jsxOps?: IVueJsx['jsxOps'] | ||
} | ||
|
||
export default (ops?: IVueJsxOps) => { | ||
const { version = 3, jsxOps = {} } = ops || {} | ||
return { | ||
name: 'xus:rollup:vuejsx', | ||
apply(api) { | ||
api.modifyRollupConfig({ | ||
fn(rc) { | ||
rc.plugin('$$esbuild').tap((ops) => { | ||
// turn esbuild only handle .js file | ||
!ops[0] && (ops[0] = {}) | ||
ops[0].include = /\.(j|t)s$/ | ||
return ops | ||
}) | ||
// vue jsx transform | ||
rc.plugin('vuejsx').use(vuejsx, [ | ||
{ | ||
version, | ||
jsxOps, | ||
sourceMaps: !!api.projectConfig?.libBuild?.sourcemap | ||
} | ||
]) | ||
return rc | ||
}, | ||
// last to run | ||
stage: 100 | ||
}) | ||
} | ||
} as IPlugin | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Plugin } from 'rollup' | ||
import * as babel from '@babel/core' | ||
import jsx3, { VueJSXPluginOptions } from '@vue/babel-plugin-jsx' | ||
// @ts-ignore | ||
import jsx2 from '@vue/babel-preset-jsx' | ||
|
||
export interface IVueJsx { | ||
version?: 2 | 3 | ||
jsxOps?: VueJSXPluginOptions | Record<string, any> | ||
sourceMaps?: boolean | ||
} | ||
|
||
const filterRE = /\.[jt]sx$/ | ||
const tsRE = /\.tsx$/ | ||
|
||
export function vuejsx(ops?: IVueJsx): Plugin { | ||
const { version = 3, jsxOps = {}, sourceMaps = false } = ops || {} | ||
return { | ||
name: 'xus:vuejsx', | ||
async transform(code, id) { | ||
if (filterRE.test(id)) { | ||
const presets = [] | ||
const plugins = [] | ||
if (version === 3) { | ||
plugins.push([jsx3, jsxOps]) | ||
} else { | ||
presets.push([jsx2, jsxOps]) | ||
} | ||
if (tsRE.test(id)) { | ||
plugins.push([ | ||
// @ts-ignore | ||
await import('@babel/plugin-transform-typescript'), | ||
{ isTSX: true, allowExtensions: true } | ||
]) | ||
} | ||
// ready to transform | ||
const res = babel.transformSync(code, { | ||
ast: true, | ||
presets, | ||
plugins, | ||
sourceFileName: id, | ||
sourceMaps, | ||
babelrc: false, | ||
configFile: false | ||
}) | ||
return { | ||
code: res!.code!, | ||
map: res!.map | ||
} | ||
} | ||
return null | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "./dist" | ||
}, | ||
"extends": "../../tsconfig.json", | ||
"include": ["./src/**/*"] | ||
} |
Oops, something went wrong.