add rollup and babel-plugin to bundle
This commit is contained in:
parent
e79be9201d
commit
ea6706d43d
|
@ -0,0 +1 @@
|
||||||
|
import{jsx}from"react/jsx-runtime";import{useLocation,Switch,Route,Redirect}from"react-router-dom";var __assign=function(){return(__assign=Object.assign||function(t){for(var r,e=1,o=arguments.length;e<o;e++)for(var n in r=arguments[e])Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n]);return t}).apply(this,arguments)},RouterView=function(t){var r=t.routes,e=t.onEnter,t=useLocation().pathname,o="",n=!0;return e(t,function(t){n=!0,t&&(o=t)}),jsx(Switch,{children:r.map(function(r,t){return r.auth?n?o?jsx(Redirect,{to:o},t):jsx(Route,{path:r.path,render:function(t){return jsx(r.component,__assign({},t,{routes:r.routes}),void 0)}},t):void 0:jsx(Route,{path:r.path,render:function(t){return jsx(r.component,__assign({},t,{routes:r.routes}),void 0)}},t)})},void 0)};export{RouterView};
|
|
@ -1,38 +0,0 @@
|
||||||
import { jsx as _jsx } from "react/jsx-runtime";
|
|
||||||
import { Switch, useLocation, useRouteMatch, Route, Redirect, } from 'react-router-dom';
|
|
||||||
const RouterView = ({ routes, onEnter, }) => {
|
|
||||||
const { pathname } = useLocation();
|
|
||||||
const match = useRouteMatch();
|
|
||||||
console.log('当前页面路径:' + pathname);
|
|
||||||
console.log('路径匹配', match);
|
|
||||||
let redirectPath = '';
|
|
||||||
let agreeToGo = true;
|
|
||||||
function next(path) {
|
|
||||||
agreeToGo = true;
|
|
||||||
if (path) {
|
|
||||||
redirectPath = path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
onEnter(pathname, next);
|
|
||||||
return (_jsx(Switch, { children: routes.map((route, index) => {
|
|
||||||
// If auth needed.
|
|
||||||
if (route.auth) {
|
|
||||||
// If `next()` called.
|
|
||||||
if (agreeToGo) {
|
|
||||||
// Need to redirect.
|
|
||||||
if (redirectPath) {
|
|
||||||
return _jsx(Redirect, { to: redirectPath }, index);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// OK to render.
|
|
||||||
return (_jsx(Route, { path: route.path, render: (props) => (_jsx(route.component, Object.assign({}, props, { routes: route.routes }), void 0)) }, index));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// No need for auth.
|
|
||||||
return (_jsx(Route, { path: route.path, render: (props) => (_jsx(route.component, Object.assign({}, props, { routes: route.routes }), void 0)) }, index));
|
|
||||||
}
|
|
||||||
}) }, void 0));
|
|
||||||
};
|
|
||||||
export { RouterView };
|
|
|
@ -1 +0,0 @@
|
||||||
export {};
|
|
|
@ -15,10 +15,17 @@
|
||||||
"react-router-dom": "^5.3.0"
|
"react-router-dom": "^5.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@babel/core": "^7.15.8",
|
||||||
|
"@babel/preset-env": "^7.15.8",
|
||||||
"@types/react": "^17.0.31",
|
"@types/react": "^17.0.31",
|
||||||
"@types/react-dom": "^17.0.10",
|
"@types/react-dom": "^17.0.10",
|
||||||
"@types/react-router-dom": "^5.3.1",
|
"@types/react-router-dom": "^5.3.1",
|
||||||
"react": "^17.0.2",
|
"react": "^17.0.2",
|
||||||
|
"rollup": "^2.58.0",
|
||||||
|
"rollup-plugin-babel": "^4.4.0",
|
||||||
|
"rollup-plugin-buble": "^0.19.8",
|
||||||
|
"rollup-plugin-typescript2": "^0.30.0",
|
||||||
|
"rollup-plugin-uglify": "^6.0.4",
|
||||||
"typescript": "^4.4.4"
|
"typescript": "^4.4.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
import babel from 'rollup-plugin-babel';
|
||||||
|
import { uglify } from 'rollup-plugin-uglify';
|
||||||
|
import typescript from 'rollup-plugin-typescript2';
|
||||||
|
import buble from 'rollup-plugin-buble';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
input: 'src/index.tsx',
|
||||||
|
output: {
|
||||||
|
file: 'dist/index.js',
|
||||||
|
format: 'es',
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
typescript(),
|
||||||
|
babel({
|
||||||
|
exclude: 'node_modules/**',
|
||||||
|
}),
|
||||||
|
uglify(),
|
||||||
|
buble(),
|
||||||
|
],
|
||||||
|
};
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "ESNext",
|
"target": "es5",
|
||||||
// "useDefineForClassFields": true,
|
// "useDefineForClassFields": true,
|
||||||
// "lib": ["DOM", "DOM.Iterable", "ESNext"],
|
// "lib": ["DOM", "DOM.Iterable", "ESNext"],
|
||||||
// "allowJs": false,
|
// "allowJs": false,
|
||||||
|
|
Loading…
Reference in New Issue