Skip to content

Commit

Permalink
feat: adds build config for min and modular imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Harsh Kumar Choudhary authored and Harsh Kumar Choudhary committed Mar 11, 2024
1 parent 42a2a3f commit 18d9c29
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 51 deletions.
44 changes: 35 additions & 9 deletions build.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
import { defineBuildConfig } from 'unbuild'

export default defineBuildConfig({
entries: [
'src/index',
],
declaration: true,
clean: true,
rollup: {
emitCJS: true,
export default defineBuildConfig([
{
// If entries is not provided, will be automatically inferred from package.json
entries: [
'./src/index',
// mkdist builder transpiles file-to-file keeping original sources structure
{
builder: 'mkdist',
input: './src/',
outDir: './dist/',
},
],

/**
* `compatible` means "src/index.ts" will generate "dist/index.d.mts", "dist/index.d.cts" and "dist/index.d.ts".
* `node16` means "src/index.ts" will generate "dist/index.d.mts" and "dist/index.d.cts".
* `true` is equivalent to `compatible`.
* `false` will disable declaration generation.
* `undefined` will auto detect based on "package.json". If "package.json" has "types" field, it will be `"compatible"`, otherwise `false`.
*/
declaration: 'compatible',
failOnWarn: false,
},
{
name: 'minified',
entries: ['./src/index'],
outDir: './dist/min',
rollup: {
esbuild: {
minify: true,
},
emitCJS: true,
},
failOnWarn: false,
},
})
])
27 changes: 25 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,31 @@
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
"require": "./dist/min/index.cjs",
"default": "./dist/index.mjs"
},
"./min": {
"default": "./dist/min/index.mjs"
},
"./idleQueue.js": {
"types": "./dist/idleQueue.d.ts",
"default": "./dist/idleQueue.mjs"
},
"./idleCbWithPolyfill.js": {
"types": "./dist/idleCbWithPolyfill.d.ts",
"default": "./dist/idleCbWithPolyfill.mjs"
},
"./idleValue.js": {
"types": "./dist/idleValue.d.ts",
"default": "./dist/idleValue.mjs"
},
"./defineIdleProperty.js": {
"types": "./dist/defineIdleProperty.d.ts",
"default": "./dist/defineIdleProperty.mjs"
},
"./defineIdleProperties.js": {
"types": "./dist/defineIdleProperties.d.ts",
"default": "./dist/defineIdleProperties.mjs"
}
},
"main": "./dist/index.mjs",
Expand Down
93 changes: 54 additions & 39 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/defineIdleProperty.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IdleValue } from './IdleValue'
import { IdleValue } from './idleValue'

Check failure on line 1 in src/defineIdleProperty.ts

View workflow job for this annotation

GitHub Actions / typecheck

Cannot find module './idleValue' or its corresponding type declarations.

export function defineIdleProperty<T, TInitFunc extends () => T, K extends PropertyKey>( // Add K
obj: Record<K, any>,
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export { IdleQueue } from './idleQueue'
export { defineIdleProperty } from './defineIdleProperty'
export { defineIdleProperties } from './defineIdleProperties'
export { cIC, rIC } from './idleCbWithPolyfill'
export { IdleValue } from './idleValue'

Check failure on line 5 in src/index.ts

View workflow job for this annotation

GitHub Actions / typecheck

Cannot find module './idleValue' or its corresponding type declarations.

0 comments on commit 18d9c29

Please sign in to comment.