Skip to content

Commit c4c83c8

Browse files
authored
fix: fix the dist files not exist in npm tarball
2 parents a8dec93 + 187ec3c commit c4c83c8

File tree

4 files changed

+105
-10
lines changed

4 files changed

+105
-10
lines changed

packages/router/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
README.md

packages/router/package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"scripts": {
2626
"build": "rollup -c rollup.config.js",
2727
"build:watch": "rollup -c rollup.config.js --watch",
28-
"release": "semantic-release"
28+
"release": "semantic-release",
29+
"prepack": "npm run build"
2930
},
3031
"dependencies": {
3132
"history": "^5.3.0"
@@ -36,8 +37,9 @@
3637
"@semantic-release/git": "^10.0.1",
3738
"@types/react": "^17.0.33",
3839
"rollup": "^2.70.1",
40+
"rollup-plugin-copy": "^3.4.0",
3941
"semantic-release": "^19.0.2",
4042
"tslib": "^2.3.1",
4143
"typescript": "^4.6.2"
4244
}
43-
}
45+
}

packages/router/rollup.config.js

+27-8
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,48 @@ const path = require('path')
33
const { defineConfig } = require('rollup')
44
const typescript = require('@rollup/plugin-typescript')
55

6+
// 构建输出目录
7+
const OUT_DIR = 'dist/'
8+
69
// 防止 watch 模式下重复清空
710
let cleanable = true
11+
812
/**
913
* 清空构建目录
1014
*
11-
* @param {string} dir
1215
* @returns @type {import('rollup').Plugin}
1316
*/
14-
const clean = dir => {
17+
const clean = () => {
1518
return {
1619
name: 'clean',
17-
buildStart(options) {
18-
const dirpath = path.resolve(__dirname, dir)
19-
if (cleanable && fs.existsSync(dirpath)) {
20+
buildStart() {
21+
const distPath = path.resolve(__dirname, OUT_DIR)
22+
if (cleanable && fs.existsSync(distPath)) {
2023
cleanable = false
21-
fs.rmSync(dirpath, {
24+
fs.rmSync(distPath, {
2225
recursive: true
2326
})
2427
}
2528
}
2629
}
2730
}
2831

29-
const OUT_DIR = 'dist/'
32+
/**
33+
* 从上级目录复制一些共用的文件
34+
*
35+
* @returns @type {import('rollup').Plugin}
36+
*/
37+
const copy = () => {
38+
return {
39+
name: 'copy',
40+
buildStart() {
41+
fs.copyFileSync(
42+
path.resolve(__dirname, '../..', 'README.md'),
43+
path.resolve(__dirname, 'README.md')
44+
)
45+
}
46+
}
47+
}
3048

3149
export default defineConfig({
3250
input: 'src/index.ts',
@@ -44,7 +62,8 @@ export default defineConfig({
4462
],
4563
external: ['history', 'react', 'react/jsx-runtime'],
4664
plugins: [
47-
clean(OUT_DIR),
65+
clean(),
66+
copy({}),
4867
typescript({
4968
tsconfig: './tsconfig.json',
5069
compilerOptions: {

pnpm-lock.yaml

+73
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)