mirror of
https://github.com/youzan/vant.git
synced 2025-10-15 23:55:08 +00:00
build: using rollup-plugin-esbuild
This commit is contained in:
@@ -4,10 +4,6 @@ Vant Use 是从 Vant 实际应用场景中沉淀的 Vue 组合式 API 库。
|
||||
|
||||
## 安装
|
||||
|
||||
如果项目中已经安装了 Vant 3,则无须手动安装 Vant Use。
|
||||
|
||||
如果项目中未使用 Vant,可以通过 `npm` 或 `yarn` 手动安装 Vant Use。
|
||||
|
||||
```bash
|
||||
# 通过 npm 安装
|
||||
npm i @vant/use -S
|
||||
|
@@ -1,3 +0,0 @@
|
||||
module.exports = {
|
||||
presets: [['@vant/cli/preset.cjs', { loose: true }]],
|
||||
};
|
@@ -4,16 +4,17 @@
|
||||
"description": "Vant Composition API",
|
||||
"main": "dist/cjs/index.js",
|
||||
"module": "dist/esm/index.js",
|
||||
"typings": "dist/types/index.d.ts",
|
||||
"typings": "dist/index.d.ts",
|
||||
"sideEffects": false,
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"clean": "rm -rf ./dist",
|
||||
"build:lib": "node ./scripts/build.js",
|
||||
"dev": "rollup --config rollup.config.js --watch",
|
||||
"build:types": "tsc -p ./tsconfig.json --emitDeclarationOnly",
|
||||
"build": "pnpm build:lib && pnpm build:types",
|
||||
"build:bundle": "rollup --config rollup.config.js",
|
||||
"build": "pnpm clean && pnpm build:bundle && pnpm build:types",
|
||||
"release": "pnpm build && release-it",
|
||||
"prepare": "pnpm build"
|
||||
},
|
||||
@@ -24,12 +25,10 @@
|
||||
"license": "MIT",
|
||||
"repository": "https://github.com/youzan/vant/tree/dev/packages/vant-use",
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.12.9",
|
||||
"@vant/cli": "workspace:*",
|
||||
"fast-glob": "^3.2.7",
|
||||
"fs-extra": "^10.0.0",
|
||||
"release-it": "^14.0.2",
|
||||
"typescript": "4.x",
|
||||
"rollup": "^2.33.3",
|
||||
"rollup-plugin-esbuild": "^4.6.0",
|
||||
"vue": "^3.2.20"
|
||||
},
|
||||
"release-it": {
|
||||
|
18
packages/vant-use/rollup.config.js
Normal file
18
packages/vant-use/rollup.config.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import path from 'path';
|
||||
import esbuild from 'rollup-plugin-esbuild';
|
||||
|
||||
export default {
|
||||
input: path.join(__dirname, 'src', 'index.ts'),
|
||||
output: [
|
||||
{
|
||||
dir: 'dist/cjs',
|
||||
format: 'cjs',
|
||||
},
|
||||
{
|
||||
dir: 'dist/esm',
|
||||
format: 'esm',
|
||||
},
|
||||
],
|
||||
external: ['vue'],
|
||||
plugins: [esbuild()],
|
||||
};
|
@@ -1,40 +0,0 @@
|
||||
const glob = require('fast-glob');
|
||||
const { join } = require('path');
|
||||
const { transformAsync } = require('@babel/core');
|
||||
const { readFileSync, outputFileSync } = require('fs-extra');
|
||||
|
||||
const srcDir = join(__dirname, '..', 'src');
|
||||
const distDir = join(__dirname, '..', 'dist');
|
||||
const srcFiles = glob.sync(join(srcDir, '**', '*.ts'), {
|
||||
ignore: ['**/node_modules', '**/*.spec.ts'],
|
||||
});
|
||||
|
||||
const compile = (filePath, distDir) =>
|
||||
new Promise((resolve, reject) => {
|
||||
const code = readFileSync(filePath, 'utf-8');
|
||||
const distPath = filePath.replace(srcDir, distDir).replace('.ts', '.js');
|
||||
|
||||
transformAsync(code, { filename: filePath })
|
||||
.then((result) => {
|
||||
if (result) {
|
||||
outputFileSync(distPath, result.code);
|
||||
resolve();
|
||||
}
|
||||
})
|
||||
.catch(reject);
|
||||
});
|
||||
|
||||
async function build() {
|
||||
// esm output
|
||||
await Promise.all(
|
||||
srcFiles.map((srcFile) => compile(srcFile, join(distDir, 'esm')))
|
||||
);
|
||||
|
||||
// cjs output
|
||||
process.env.BABEL_MODULE = 'commonjs';
|
||||
await Promise.all(
|
||||
srcFiles.map((srcFile) => compile(srcFile, join(distDir, 'cjs')))
|
||||
);
|
||||
}
|
||||
|
||||
build();
|
@@ -1,4 +1,4 @@
|
||||
import { raf, cancelRaf } from '../utils';
|
||||
import { raf, cancelRaf } from '../src/utils';
|
||||
|
||||
test('raf', async () => {
|
||||
const spy = jest.fn();
|
@@ -1,13 +1,12 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2015",
|
||||
"outDir": "./dist/types",
|
||||
"module": "ES2015",
|
||||
"outDir": "./dist",
|
||||
"module": "ESNext",
|
||||
"strict": true,
|
||||
"declaration": true,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": true,
|
||||
"moduleResolution": "Node"
|
||||
"moduleResolution": "Node",
|
||||
},
|
||||
"include": ["src/**/*"]
|
||||
}
|
||||
|
Reference in New Issue
Block a user