Skip to content

Commit 6d78038

Browse files
committed
fix: build
1 parent d9e8618 commit 6d78038

File tree

3 files changed

+44
-23
lines changed

3 files changed

+44
-23
lines changed

package.json

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,32 @@
1010
},
1111
"scripts": {
1212
"prepack": "npm run build",
13-
"test": "npm run test:eslint && npm run test:vitest && npm run test:build",
13+
"test": "npm run test:eslint && npm run test:vitest && npm run build",
1414
"test:eslint": "eslint",
1515
"test:vitest": "vitest run",
1616
"test:build": "npm run build:production && node scripts/test-build.mjs",
17-
"dev:example": "vite serve example --host 0.0.0.0",
1817
"dev": "concurrently \"npm run dev:example\" \"npm run build:watch\"",
19-
"build": "npm run build:production && npm run build:example",
18+
"dev:example": "vite serve example --host 0.0.0.0",
19+
"build": "npm run build:production && node scripts/test-build.mjs",
2020
"build:watch": "vite build --watch",
2121
"build:production": "vite build",
2222
"build:example": "vite build example && cp example/CNAME example-dist/",
2323
"deploy:example": "npm run build:example && gh-pages -d example-dist"
2424
},
25-
"module": "dist/index.es.js",
26-
"main": "dist/index.cjs.js",
25+
"type": "module",
2726
"types": "dist/index.d.ts",
27+
"typings": "dist/index.d.ts",
28+
"main": "dist/index.mjs",
29+
"module": "dist/index.mjs",
2830
"exports": {
2931
".": {
3032
"types": "./dist/index.d.ts",
31-
"import": "./dist/index.es.js",
32-
"require": "./dist/index.cjs.js"
33-
}
33+
"default": "./dist/index.mjs",
34+
"import": "./dist/index.mjs",
35+
"require": "./dist/index.cjs"
36+
},
37+
"./style.css": "./dist/style.css",
38+
"./package.json": "./package.json"
3439
},
3540
"devDependencies": {
3641
"@commitlint/cli": "17.8.1",

scripts/test-build.mjs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,34 @@ const __dirname = new URL('.', import.meta.url).pathname
66

77
const pkg = JSON.parse(await readFile(`${__dirname}/../package.json`))
88

9-
const files = [pkg.main, pkg.module, pkg.types]
9+
const files = [pkg.main, pkg.module, pkg.types, pkg.typings, pkg.exports]
1010

11-
const fileStats = await Promise.all(
12-
files.map(async (file) => {
11+
const wrongFiles = []
12+
async function traverse(obj) {
13+
if (Array.isArray(obj)) {
14+
return Promise.all(obj.map((item) => traverse(item)))
15+
}
16+
17+
if (typeof obj === 'object' && obj !== null) {
18+
return Promise.all(Object.values(obj).map((item) => traverse(item)))
19+
}
20+
21+
if (typeof obj === 'string') {
22+
console.log('check', obj)
1323
try {
14-
await stat(`${__dirname}/../${file}`)
15-
return true
24+
await stat(`${__dirname}/../${obj}`)
1625
} catch {
1726
console.warn(`file(${file}) not found`)
18-
return false
27+
wrongFiles.push(file)
1928
}
20-
}),
21-
)
22-
23-
if (fileStats.some((file) => !file)) {
24-
console.error('Build failed')
25-
process.exit(1)
29+
}
2630
}
2731

28-
console.log('Build succeeded')
32+
traverse(files).then(() => {
33+
if (wrongFiles.length > 0) {
34+
console.error('Build failed')
35+
process.exit(1)
36+
}
37+
38+
console.log('Build succeeded')
39+
})

vite.config.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ export default defineConfig({
2222
lib: {
2323
entry: 'src/index.ts',
2424
name: 'VueScrollPicker',
25-
formats: ['es', 'umd', 'cjs'],
26-
fileName: (format) => `index.${format}.js`,
25+
formats: ['es', 'cjs'],
26+
fileName: (format, entryName) =>
27+
format === 'es'
28+
? `${entryName}.mjs`
29+
: format === 'cjs'
30+
? `${entryName}.cjs`
31+
: `${entryName}.js`,
2732
},
2833
rollupOptions: {
2934
external: ['vue'],

0 commit comments

Comments
 (0)