Skip to content

Commit

Permalink
feat: esm bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
07akioni committed Feb 21, 2024
1 parent 71b8919 commit c38b01d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
14 changes: 14 additions & 0 deletions esm-test/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { NDataTable } from '../dist/index.prod.mjs'
import { createApp } from 'vue'

// eslint-disable-next-line n/no-exports-assign
exports = undefined

describe('esm', () => {
it('works', () => {
const div = document.createElement('div')
document.body.appendChild(div)
createApp(NDataTable).mount(div)
expect(div.innerHTML).toContain('n-data-table')
})
})
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ module.exports = {

// A map from regular expressions to paths to transformers
transform: {
'^.+\\.(jsx|js)?$': 'babel-jest',
'^.+\\.(jsx|js|mjs)?$': 'babel-jest',
'^.+\\.(tsx|ts)?$': [
'ts-jest',
{
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"test:cov": "NODE_ENV=test NODE_OPTIONS=--unhandled-rejections=warn jest",
"test:watch": "NODE_ENV=test jest ---watch --verbose --coverage",
"test:umd": "jest --collectCoverage=false --testMatch=\"<rootDir>/umd-test/index.spec.js\"",
"test:esm": "jest --collectCoverage=false --testMatch=\"<rootDir>/esm-test/index.spec.js\"",
"gen-version": "node scripts/gen-version",
"gen-volar-dts": "esbuild scripts/gen-component-declaration.js --bundle --platform=node --tsconfig=tsconfig.esbuild.json | node",
"build:site:ts": "bash ./scripts/pre-build-site/pre-build-site.sh && TUSIMPLE=true NODE_ENV=production NODE_OPTIONS=--max-old-space-size=4096 vite build && bash ./scripts/post-build-site/post-build-site.sh",
Expand Down
34 changes: 15 additions & 19 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const extensions = ['.mjs', '.js', '.json', '.ts']

const baseConfig = defineConfig({
input: path.resolve('./src/index.ts'),
external: ['vue'],
plugins: [
nodeResolve({ extensions }),
esbuild({
Expand All @@ -28,25 +29,20 @@ const baseConfig = defineConfig({
})

const umdConfig = defineConfig({
external: ['vue'],
output: [
{
name: 'naive',
format: 'umd',
exports: 'named',
globals: {
vue: 'Vue'
}
output: {
name: 'naive',
format: 'umd',
exports: 'named',
globals: {
vue: 'Vue'
}
]
}
})

const esmConfig = defineConfig({
output: [
{
format: 'esm'
}
]
output: {
format: 'esm'
}
})

const devConfig = defineConfig({
Expand Down Expand Up @@ -100,11 +96,11 @@ const esmProdOutputConfig = defineConfig({

module.exports = [
// umd dev
merge(baseConfig, umdConfig, devConfig, umdDevOutputConfig),
merge.all([baseConfig, umdConfig, devConfig, umdDevOutputConfig]),
// umd prod
merge(baseConfig, umdConfig, prodConfig, umdProdOutputConfig),
merge.all([baseConfig, umdConfig, prodConfig, umdProdOutputConfig]),
// esm dev
merge(baseConfig, esmConfig, devConfig, esmDevOutputConfig),
merge.all([baseConfig, esmConfig, devConfig, esmDevOutputConfig]),
// esm prod
merge(baseConfig, esmConfig, prodConfig, esmProdOutputConfig)
merge.all([baseConfig, esmConfig, prodConfig, esmProdOutputConfig])
]

0 comments on commit c38b01d

Please sign in to comment.