-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #222 from umijs/feat/umi-plugin-routes
feat: add umi-plugin-routes
- Loading branch information
Showing
10 changed files
with
79 additions
and
36 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
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
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 |
---|---|---|
|
@@ -2,10 +2,6 @@ | |
"name": "umi-plugin-dva", | ||
"version": "0.3.3", | ||
"main": "./lib/index.js", | ||
"scripts": { | ||
"test": "ruban test", | ||
"debug": "ruban debug" | ||
}, | ||
"dependencies": { | ||
"dva": "^2.1.0", | ||
"dva-loading": "^1.0.4", | ||
|
@@ -14,9 +10,9 @@ | |
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/umijs/umi/tree/master/packages/umi-plugin-yunfengdie" | ||
"url": "https://github.com/umijs/umi/tree/master/packages/umi-plugin-dva" | ||
}, | ||
"homepage": "https://github.com/umijs/umi/tree/master/packages/umi-plugin-yunfengdie", | ||
"homepage": "https://github.com/umijs/umi/tree/master/packages/umi-plugin-dva", | ||
"authors": [ | ||
"chencheng <[email protected]> (https://github.com/sorrycc)" | ||
], | ||
|
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,23 @@ | ||
{ | ||
"name": "umi-plugin-routes", | ||
"version": "0.1.0", | ||
"main": "./lib/index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/umijs/umi/tree/master/packages/umi-plugin-routes" | ||
}, | ||
"homepage": "https://github.com/umijs/umi/tree/master/packages/umi-plugin-routes", | ||
"authors": [ | ||
"chencheng <[email protected]> (https://github.com/sorrycc)" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/umijs/umi/issues" | ||
}, | ||
"files": [ | ||
"lib", | ||
"src" | ||
], | ||
"dependencies": { | ||
"is-plain-object": "^2.0.4" | ||
} | ||
} |
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,51 @@ | ||
import assert from 'assert'; | ||
import isPlainObject from 'is-plain-object'; | ||
|
||
function optsToArray(item) { | ||
if (!item) return []; | ||
if (Array.isArray(item)) { | ||
return item; | ||
} else { | ||
return [item]; | ||
} | ||
} | ||
|
||
export default function(api, opts) { | ||
api.register('modifyRoutes', ({ memo }) => { | ||
// opts.exclude | ||
memo = memo.filter(route => { | ||
for (const exclude of optsToArray(opts.exclude)) { | ||
if (typeof exclude === 'function' && exclude(route)) { | ||
return false; | ||
} | ||
if (exclude instanceof RegExp && exclude.test(route.component)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}); | ||
|
||
// opts.include | ||
for (const include of optsToArray(opts.include)) { | ||
if (isPlainObject(include)) { | ||
memo = [...memo, include]; | ||
} | ||
if (typeof include === 'string') { | ||
throw new Error( | ||
'opts.include with string not support, please wait for next version.', | ||
); | ||
} | ||
} | ||
|
||
// opts.update | ||
if (opts.update) { | ||
assert( | ||
typeof opts.update === 'function', | ||
`opts.update should be function, but got ${opts.update}`, | ||
); | ||
memo = opts.update(memo); | ||
} | ||
|
||
return memo; | ||
}); | ||
} |
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