-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4538fb8
commit e10a91e
Showing
13 changed files
with
11,006 additions
and
10,218 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 |
---|---|---|
|
@@ -5,7 +5,6 @@ npm-debug.log* | |
package-lock.json | ||
.DS_Store | ||
.cache | ||
.rdoc-dist | ||
.vscode | ||
|
||
*.bak | ||
|
10,171 changes: 0 additions & 10,171 deletions
10,171
example/router-redux-rematch/package-lock.json
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,52 +1,32 @@ | ||
{ | ||
"name": "react-dynamic-loadable", | ||
"version": "2.0.4", | ||
"private": true, | ||
"description": "A higher order component for loading components with dynamic imports.", | ||
"main": "lib/cjs/index.js", | ||
"module": "lib/esm/index.js", | ||
"typings": "types/index.d.ts", | ||
"workspaces": [ | ||
"packages/*", | ||
"example/*" | ||
], | ||
"scripts": { | ||
"watch": "tsbb watch --target react", | ||
"build": "tsbb build --target react", | ||
"watch": "yarn workspace react-dynamic-loadable tsbb watch --target react", | ||
"build": "yarn workspace react-dynamic-loadable tsbb build --target react", | ||
"prepare": "npm run lint && npm run build", | ||
"lint": "NODE_ENV=production eslint src --ext jsx" | ||
"lint": "cross-env NODE_ENV=production eslint packages/core/src --ext jsx" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/jaywcjlove/react-dynamic-loadable.git" | ||
}, | ||
"keywords": [ | ||
"react", | ||
"loading", | ||
"imports", | ||
"dynamic", | ||
"dynamic-loadable", | ||
"code-splitting", | ||
"loadable" | ||
], | ||
"files": [ | ||
"types", | ||
"lib", | ||
"DynamicLoadablePlugin.js" | ||
], | ||
"jest": {}, | ||
"author": "Kenny Wong <[email protected]> (https://github.com/jaywcjlove)", | ||
"license": "MIT", | ||
"peerDependencies": { | ||
"react": ">=16.9.0" | ||
}, | ||
"devDependencies": { | ||
"babel-eslint": "10.0.3", | ||
"cross-env": "7.0.2", | ||
"cross-env": "7.0.3", | ||
"eslint": "^7.15.0", | ||
"eslint-config-airbnb": "^18.2.1", | ||
"eslint-plugin-import": "^2.22.1", | ||
"eslint-plugin-jsx-a11y": "^6.4.1", | ||
"eslint-plugin-react": "^7.21.5", | ||
"eslint-plugin-react-hooks": "^4.2.0", | ||
"react": "16.12.0", | ||
"tsbb": "1.7.8" | ||
}, | ||
"dependencies": { | ||
"@babel/runtime": "^7.12.5" | ||
} | ||
} | ||
} |
File renamed without changes.
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
File renamed without changes.
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,94 @@ | ||
|
||
react-dynamic-loadable | ||
--- | ||
|
||
A higher order component for loading components with dynamic imports. | ||
|
||
## Install | ||
|
||
```bash | ||
npm install react-dynamic-loadable --save | ||
``` | ||
|
||
## Simple Example | ||
|
||
> [Simple Example code](./example/simple) | ||
```js | ||
import loadable from 'react-dynamic-loadable'; | ||
import Loading from './my-loading-component'; | ||
|
||
// Add Loading component. | ||
loadable.setDefaultLoadingComponent(<div>Loading</div>); | ||
|
||
const LoadableComponent = loadable({ | ||
component: () => import('./my-component'), | ||
// LoadingComponent: () => Loading, | ||
}); | ||
|
||
export default class App extends React.Component { | ||
render() { | ||
return <LoadableComponent/>; | ||
} | ||
} | ||
|
||
``` | ||
|
||
## Example | ||
|
||
Use [Redux](https://github.com/reactjs/redux) (**[@rematch](https://github.com/rematch/rematch)**), [React Router](https://github.com/ReactTraining/react-router) [Example](./example/router-redux-rematch). | ||
|
||
> [Example code](./example/router-redux-rematch) | ||
```js | ||
import React from 'react'; | ||
import { model } from '@rematch/core'; | ||
import loadable from 'react-dynamic-loadable'; | ||
|
||
const dynamicWrapper = (models, component) => loadable({ | ||
models: () => models.map((m) => { | ||
return import(`./models/${m}.js`).then((md) => { | ||
model({ name: m, ...md[m] || md.default }); | ||
}); | ||
}), | ||
component, | ||
LoadingComponent: () => <span>loading....</span>, | ||
}); | ||
|
||
export const getRouterData = () => { | ||
const conf = { | ||
'/': { | ||
component: dynamicWrapper(['user'], () => import('./layouts/BasicLayout')), | ||
}, | ||
'/home': { | ||
component: dynamicWrapper([], () => import('./routes/Home')), | ||
}, | ||
'/login': { | ||
component: dynamicWrapper(['user'], () => import('./routes/Login')), | ||
}, | ||
}; | ||
return conf; | ||
}; | ||
``` | ||
|
||
## Server-Side Rendering | ||
|
||
```js | ||
// webpack.config.js | ||
import { DynamicLoadablePlugin } from 'react-dynamic-loadable/DynamicLoadablePlugin'; | ||
|
||
export default { | ||
plugins: [ | ||
new DynamicLoadablePlugin({ | ||
filename: './dist/loadable-assets.json', | ||
exclude: /.(js|css)$/ | ||
}), | ||
], | ||
}; | ||
``` | ||
|
||
|
||
```js | ||
import { getBundles } from 'react-dynamic-loadable/DynamicLoadablePlugin'; | ||
let bundles = getBundles(stats, modules); | ||
``` |
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,43 @@ | ||
{ | ||
"name": "react-dynamic-loadable", | ||
"version": "2.0.4", | ||
"description": "A higher order component for loading components with dynamic imports.", | ||
"main": "lib/cjs/index.js", | ||
"module": "lib/esm/index.js", | ||
"typings": "types/index.d.ts", | ||
"scripts": { | ||
"watch": "tsbb watch --target react", | ||
"build": "tsbb build --target react", | ||
"prepare": "npm run lint && npm run build" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/jaywcjlove/react-dynamic-loadable.git" | ||
}, | ||
"keywords": [ | ||
"react", | ||
"loading", | ||
"imports", | ||
"dynamic", | ||
"dynamic-loadable", | ||
"code-splitting", | ||
"loadable" | ||
], | ||
"files": [ | ||
"types", | ||
"lib", | ||
"src", | ||
"DynamicLoadablePlugin.js" | ||
], | ||
"author": "Kenny Wong <[email protected]> (https://github.com/jaywcjlove)", | ||
"license": "MIT", | ||
"peerDependencies": { | ||
"react": ">=16.9.0" | ||
}, | ||
"devDependencies": { | ||
"react": "16.12.0" | ||
}, | ||
"dependencies": { | ||
"@babel/runtime": "^7.12.5" | ||
} | ||
} |
File renamed without changes.
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
Oops, something went wrong.