Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Microbundle compat bundler and React based jotai utils core #27

Merged
merged 4 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .codesandbox/ci.json
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"
}
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: '16.x'
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'

- name: Get yarn cache
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: '16.x'
node-version: '18.x'

- name: Get yarn cache
id: yarn-cache
Expand Down
17 changes: 13 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
"module": "./dist/index.modern.js",
"import": "./dist/index.modern.mjs",
"default": "./dist/index.umd.js"
},
"./react": {
"types": "./dist/react/src/react/index.d.ts",
"module": "./dist/react/index.modern.js",
"import": "./dist/react/index.modern.mjs",
"default": "./dist/react/index.umd.js"
}
},
"sideEffects": false,
Expand All @@ -29,8 +35,7 @@
"dist"
],
"scripts": {
"compile": "microbundle build -f modern,umd --globals react=React",
"postcompile": "cp dist/index.modern.mjs dist/index.modern.js && cp dist/index.modern.mjs.map dist/index.modern.js.map",
"compile": "NODE_ENV=production rollup -c",
"test": "run-s eslint tsc-test jest",
"eslint": "eslint --ext .js,.ts,.tsx .",
"jest": "jest",
Expand Down Expand Up @@ -65,6 +70,7 @@
"@typescript-eslint/parser": "^6.13.1",
"bumpp": "^8.2.1",
"css-loader": "^6.8.1",
"esbuild": "^0.20.2",
"eslint": "^8.55.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^8.10.0",
Expand All @@ -77,7 +83,6 @@
"jest-environment-jsdom": "^29.7.0",
"joi": "^17.11.0",
"jotai": "^2.6.0",
"microbundle": "^0.14.2",
"normalize.css": "^8.0.1",
"npm-run-all": "^4.1.5",
"prettier": "^2.8.8",
Expand All @@ -86,11 +91,15 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"regenerator-runtime": "^0.13.11",
"rollup": "^4.14.2",
"rollup-plugin-esbuild": "^6.1.1",
"rollup-plugin-typescript2": "^0.36.0",
"style-loader": "^3.3.3",
"styled-components": "^5.3.11",
"ts-jest": "^29.1.1",
"ts-loader": "^9.5.1",
"typescript": "^5.2.0",
"tslib": "^2.6.2",
"typescript": "^5.4.5",
"valibot": "^0.21.0",
"webpack": "^5.89.0",
"webpack-cli": "^4.10.0",
Expand Down
111 changes: 111 additions & 0 deletions rollup.config.js
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],
},
];
},
};
}
1 change: 1 addition & 0 deletions src/react/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { noop } from './utils/noop';
1 change: 1 addition & 0 deletions src/react/utils/noop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const noop = () => {};
Loading
Loading