Skip to content

Commit a4726c2

Browse files
muco-rolleTresor Muco
andauthored
Add JSON Import Attribute for Node.js Compatibility (#354)
Co-authored-by: Tresor Muco <tresormuco@gmail.com>
1 parent 34fdb6f commit a4726c2

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

src/output.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const outputEntry = async (dest: string, format: Output['format'], config
4444
if (format === 'cjs') {
4545
entry.push(`exports.${name} = require('./${name}.json')`)
4646
} else {
47-
entry.push(`export { default as ${name} } from './${name}.json'`)
47+
entry.push(`export { default as ${name} } from './${name}.json' with { type: 'json' }`)
4848
}
4949
dts.push(`export type ${collection.name} = Collections['${name}']['schema']['_output']`)
5050
dts.push(`export declare const ${name}: ${collection.name + (collection.single ? '' : '[]')}\n`)

test/basic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ test('standalone fixtures', async t => {
99
await build({ config: 'examples/basic/velite.config.js' })
1010

1111
const entry = await readFile('examples/basic/.velite/index.js', 'utf8')
12-
equal(entry.length, 288, 'entry output length should be 288')
12+
equal(entry.length, 398, 'entry output length should be 398')
1313

1414
const dts = await readFile('examples/basic/.velite/index.d.ts', 'utf8')
1515
equal(dts.length, 632, 'dts output length should be 632')

test/nextjs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ test('integration with nextjs fixtures', async t => {
88
await new Promise((res, rej) => exec('npm run build', { cwd: 'examples/nextjs' }, (e, s) => (e ? rej(e) : res(s))))
99

1010
const entry = await readFile('examples/nextjs/.velite/index.js', 'utf8')
11-
equal(entry.length, 288, 'entry output length should be 288')
11+
equal(entry.length, 398, 'entry output length should be 398')
1212

1313
const dts = await readFile('examples/nextjs/.velite/index.d.ts', 'utf8')
1414
equal(dts.length, 632, 'dts output length should be 632')

test/vite.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ test('integration with vite fixtures', async t => {
88
await new Promise((res, rej) => exec('npm run build', { cwd: 'examples/vite' }, (e, s) => (e ? rej(e) : res(s))))
99

1010
const entry = await readFile('examples/vite/.velite/index.js', 'utf8')
11-
equal(entry.length, 288, 'entry output length should be 288')
11+
equal(entry.length, 398, 'entry output length should be 398')
1212

1313
const dts = await readFile('examples/vite/.velite/index.d.ts', 'utf8')
1414
equal(dts.length, 632, 'dts output length should be 632')

0 commit comments

Comments
 (0)