-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Microbundle compat bundler and React based jotai utils core (#27)
* feat: add microbundle compat with rollup * ci: move to 18 * ci: update csb base version * chore: disable eslint import rules for config
- Loading branch information
1 parent
cfa47b7
commit ce67123
Showing
8 changed files
with
536 additions
and
1,904 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"buildCommand": "compile", | ||
"sandboxes": ["new", "react-typescript-react-ts"], | ||
"node": "16" | ||
"node": "18" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* eslint | ||
@typescript-eslint/no-var-requires: 0, | ||
import/no-extraneous-dependencies: 0, | ||
global-require: 0, | ||
*/ | ||
|
||
const typescript = require('rollup-plugin-typescript2'); | ||
const { minify } = require('rollup-plugin-esbuild'); | ||
const { dirname, resolve, join } = require('path'); | ||
|
||
/** @returns {import("rollup").RollupOptions[]} */ | ||
module.exports = function config() { | ||
const builder = configBuilder(); | ||
|
||
const pkg = require('./package.json'); | ||
|
||
return builder.merge( | ||
// core | ||
builder.buildUMD('./src/index.ts', pkg.name, 'dist'), | ||
builder.buildESM('./src/index.ts', 'dist'), | ||
|
||
// react | ||
builder.buildUMD('./src/react/index.ts', 'jotai-form-react', 'dist/react'), | ||
builder.buildESM('./src/react/index.ts', 'dist/react'), | ||
); | ||
}; | ||
|
||
function configBuilder({ env } = {}) { | ||
/** @type {Partial<import("rollup").RollupOptions>} */ | ||
|
||
const isDev = env || process.env.NODE_ENV !== 'production'; | ||
|
||
const getCommonPlugins = (input, output) => | ||
[ | ||
!isDev ? minify() : false, | ||
typescript({ | ||
cwd: process.cwd(), | ||
useTsconfigDeclarationDir: true, | ||
tsconfig: './tsconfig.json', | ||
tsconfigOverride: { | ||
compilerOptions: { | ||
module: 'ESNext', | ||
target: 'esnext', | ||
}, | ||
}, | ||
tsconfigDefaults: { | ||
compilerOptions: { | ||
declarationDir: join(resolve(output), dirname(input)), | ||
declaration: true, | ||
}, | ||
files: [input], | ||
}, | ||
}), | ||
].filter(Boolean); | ||
|
||
return { | ||
merge(...configs) { | ||
return [].concat(configs).flat(1); | ||
}, | ||
/** @returns {import("rollup").RollupOptions[]} */ | ||
buildESM(input, output) { | ||
const plugins = getCommonPlugins(input, output); | ||
|
||
return [ | ||
{ | ||
input, | ||
output: { | ||
globals: { | ||
react: 'React', | ||
}, | ||
dir: output, | ||
format: 'es', | ||
entryFileNames: '[name].modern.js', | ||
}, | ||
plugins: [...plugins], | ||
}, | ||
{ | ||
input, | ||
output: { | ||
globals: { | ||
react: 'React', | ||
}, | ||
dir: output, | ||
format: 'es', | ||
entryFileNames: '[name].modern.mjs', | ||
}, | ||
plugins: [...plugins], | ||
}, | ||
]; | ||
}, | ||
/** @returns {import("rollup").RollupOptions[]} */ | ||
buildUMD(input, name, output) { | ||
const plugins = getCommonPlugins(input, output); | ||
return [ | ||
{ | ||
input, | ||
output: { | ||
globals: { | ||
react: 'React', | ||
}, | ||
format: 'umd', | ||
dir: output, | ||
name, | ||
entryFileNames: '[name].umd.js', | ||
}, | ||
plugins: [...plugins], | ||
}, | ||
]; | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { noop } from './utils/noop'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const noop = () => {}; |
Oops, something went wrong.