-
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
11 changed files
with
190 additions
and
10 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
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
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,40 @@ | ||
{ | ||
"name": "@xus/plugin-lib-legacy", | ||
"version": "0.1.0", | ||
"description": "a bundle for legacy", | ||
"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:legacy": "tsc --watch", | ||
"build:legacy": "tsc" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/xus-code/bundle-tools/issues" | ||
}, | ||
"dependencies": { | ||
"@babel/core": "^7.13.10", | ||
"@xus/babel-preset": "^0.1.11", | ||
"@xus/cli-shared": "^0.1.4", | ||
"@xus/cli-types": "^0.1.0", | ||
"@xus/core": "^0.1.5", | ||
"core-js": "^3.9.1", | ||
"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,50 @@ | ||
import { IPlugin } from '@xus/cli-types' | ||
import { legacyPlugin } from './plugin' | ||
|
||
export interface ILegacyOps { | ||
targets?: string | string[] | ||
helper?: 'bundled' | 'runtime' | ||
} | ||
|
||
export default (ops?: ILegacyOps) => { | ||
const { helper = 'runtime', targets = 'defaults' } = ops || {} | ||
return { | ||
name: 'xus:lib:legacy', | ||
apply(api) { | ||
// ensure minify is not esbuild | ||
api.onSetuped((config) => { | ||
const minify = config?.libBuild?.minify | ||
if (minify === 'esbuild') { | ||
throw new Error( | ||
`when use @xus/plugin-lib-legacy, minify should be use 'terser'!!! now is 'esbuild'.` | ||
) | ||
} | ||
}) | ||
|
||
api.modifyRollupConfig({ | ||
fn(rc) { | ||
rc.plugin('$$esbuild').tap((ops) => { | ||
// turn esbuild only handle .js/.ts/.tsx file | ||
!ops[0] && (ops[0] = {}) | ||
ops[0].exclude = /\.js$/ | ||
ops[0].target = 'es2019' | ||
return ops | ||
}) | ||
// babel | ||
rc.plugin('$$legacy') | ||
.use(legacyPlugin, [ | ||
{ | ||
helper, | ||
targets, | ||
sourceMaps: !!api.projectConfig?.libBuild?.sourcemap | ||
} | ||
]) | ||
.before('$$minify') | ||
|
||
return rc | ||
}, | ||
stage: 200 | ||
}) | ||
} | ||
} 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,55 @@ | ||
import { Logger } from '@xus/cli-shared' | ||
import { Plugin } from 'rollup' | ||
import * as babel from '@babel/core' | ||
// @ts-ignore | ||
import preset from '@xus/babel-preset' | ||
|
||
interface ILegacyPluginOps { | ||
targets?: string | string[] | ||
helper?: 'bundled' | 'runtime' | ||
sourceMaps?: boolean | ||
} | ||
|
||
const logger = new Logger(`xus:rollup:legacy`) | ||
|
||
export function legacyPlugin(ops?: ILegacyPluginOps): Plugin { | ||
const { helper = 'runtime', sourceMaps = false, targets = 'defaults' } = | ||
ops || {} | ||
return { | ||
name: 'xus:rollup:legacy', | ||
async renderChunk(code, chunk, ops) { | ||
logger.debug(`transform ${chunk.facadeModuleId}`) | ||
const presets = [ | ||
[ | ||
preset, | ||
{ | ||
targets, | ||
modules: false, | ||
useESModules: true, | ||
usageMode: | ||
helper === 'bundled' || ['iife', 'umd'].includes(ops.format), | ||
absoluteRuntime: false | ||
} | ||
] | ||
] | ||
const res = babel.transform(code, { | ||
ast: true, | ||
presets, | ||
sourceMaps, | ||
inputSourceMap: chunk.map, | ||
babelrc: false, | ||
configFile: false, | ||
filename: chunk.fileName, | ||
minified: false, | ||
compact: false | ||
}) | ||
logger.debug(`transform code: `) | ||
logger.debug(res) | ||
|
||
return { | ||
code: res!.code!, | ||
map: res!.map | ||
} | ||
} | ||
} | ||
} |
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/**/*"] | ||
} |
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