Skip to content

Commit

Permalink
build: min.js
Browse files Browse the repository at this point in the history
  • Loading branch information
acrazing committed Oct 23, 2024
1 parent 25feea0 commit c7d3f61
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 6 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
],
"devDependencies": {
"@rollup/plugin-alias": "^5.1.1",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^12.1.1",
"@testing-library/dom": "^10.4.0",
"@testing-library/react": "^16.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { Dispatch, Store } from 'amos';
import { must } from 'amos-utils';
import { createContext, ReactNode, useContext } from 'react';
import { createContext, createElement, ReactNode, useContext } from 'react';

export const Context = createContext<Store | null>(null);

Expand All @@ -16,7 +16,7 @@ export interface ProviderProps {

export const Provider = ({ store, children }: ProviderProps) => {
must(store, 'store is required for <Provider />.');
return <Context.Provider value={store}>{children}</Context.Provider>;
return createElement(Context.Provider, { value: store }, children);
};

export const Consumer = Context.Consumer;
Expand Down
6 changes: 3 additions & 3 deletions packages/amos/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Amos

Amos is a decentralized state management library, inspired by `redux`, `vuex` and `recoil`.
A decentralized, data structure-based, fully featured state management library.

## Highlights

- Decentralized (or, in a more trendy term: atomic).
- Data structure-based: help you read/write state easily.
- Strong TypeScript support.
- All in one: everything in a single package `amos`, including:
- All in one: everything in a single package `amos` with zero dependencies, including:
- All commonly used data structures: Number, Boolean, Array, Object, List, Map.
- Box relationships.
- Batch.
Expand Down Expand Up @@ -48,7 +48,7 @@ const countBox = numberBox('count');

function Count() {
const dispatch = useDispatch();
const [count] = useSelector(countBox);
const count = useSelector(countBox);

return (
<div>
Expand Down
10 changes: 10 additions & 0 deletions scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
*/

import alias from '@rollup/plugin-alias';
import terser from '@rollup/plugin-terser';
import typescript from '@rollup/plugin-typescript';
import * as fs from 'fs-extra';
import { upperFirst } from 'lodash';
import * as child_process from 'node:child_process';
import * as console from 'node:console';
import { rollup } from 'rollup';
Expand Down Expand Up @@ -54,6 +56,14 @@ export const build = autorun(
await Promise.all([
bundle.write({ format: 'esm', sourcemap: true, file: `${outDir}/index.esm.js` }),
bundle.write({ format: 'cjs', sourcemap: true, file: `${outDir}/index.cjs.js` }),
bundle.write({
format: 'iife',
sourcemap: true,
name: name === 'dist' ? 'Amos' : 'Amos' + upperFirst(name),
file: `${outDir}/index.min.js`,
plugins: [terser()],
globals: { amos: 'Amos', react: 'React' },
}),
]);
await bundle.close();
if (name !== 'dist') {
Expand Down
26 changes: 25 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ __metadata:
resolution: "@amos/root@workspace:."
dependencies:
"@rollup/plugin-alias": "npm:^5.1.1"
"@rollup/plugin-terser": "npm:^0.4.4"
"@rollup/plugin-typescript": "npm:^12.1.1"
"@testing-library/dom": "npm:^10.4.0"
"@testing-library/react": "npm:^16.0.1"
Expand Down Expand Up @@ -3302,6 +3303,22 @@ __metadata:
languageName: node
linkType: hard

"@rollup/plugin-terser@npm:^0.4.4":
version: 0.4.4
resolution: "@rollup/plugin-terser@npm:0.4.4"
dependencies:
serialize-javascript: "npm:^6.0.1"
smob: "npm:^1.0.0"
terser: "npm:^5.17.4"
peerDependencies:
rollup: ^2.0.0||^3.0.0||^4.0.0
peerDependenciesMeta:
rollup:
optional: true
checksum: 10c0/b9cb6c8f02ac1c1344019e9fb854321b74f880efebc41b6bdd84f18331fce0f4a2aadcdb481042245cd3f409b429ac363af71f9efec4a2024731d67d32af36ee
languageName: node
linkType: hard

"@rollup/plugin-typescript@npm:^12.1.1":
version: 12.1.1
resolution: "@rollup/plugin-typescript@npm:12.1.1"
Expand Down Expand Up @@ -13787,6 +13804,13 @@ __metadata:
languageName: node
linkType: hard

"smob@npm:^1.0.0":
version: 1.5.0
resolution: "smob@npm:1.5.0"
checksum: 10c0/a1067f23265812de8357ed27312101af49b89129eb973e3f26ab5856ea774f88cace13342e66e32470f933ccfa916e0e9d0f7ca8bbd4f92dfab2af45c15956c2
languageName: node
linkType: hard

"snake-case@npm:^3.0.4":
version: 3.0.4
resolution: "snake-case@npm:3.0.4"
Expand Down Expand Up @@ -14272,7 +14296,7 @@ __metadata:
languageName: node
linkType: hard

"terser@npm:^5.10.0, terser@npm:^5.15.1, terser@npm:^5.26.0":
"terser@npm:^5.10.0, terser@npm:^5.15.1, terser@npm:^5.17.4, terser@npm:^5.26.0":
version: 5.36.0
resolution: "terser@npm:5.36.0"
dependencies:
Expand Down

0 comments on commit c7d3f61

Please sign in to comment.