progress to code-splitting
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
export { default as Form } from '../src/client/components/forms/Form';
|
||||
export { default as Text } from '../src/client/components/forms/field-types/Text';
|
||||
export { default as Group } from '../src/client/components/forms/field-types/Group';
|
||||
export { default as Select } from '../src/client/components/forms/field-types/Select';
|
||||
export { default as Checkbox } from '../src/client/components/forms/field-types/Checkbox';
|
||||
export { default as Submit } from '../src/client/components/forms/Submit';
|
||||
|
||||
2
admin/views.js
Normal file
2
admin/views.js
Normal file
@@ -0,0 +1,2 @@
|
||||
export { default as Edit } from '../src/client/components/views/collections/Edit/Default';
|
||||
export { default as List } from '../src/client/components/views/collections/List/Default';
|
||||
@@ -1,14 +1,12 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Group } from '../../../../../../../field-types';
|
||||
import { Group } from '../../../../../../../admin/forms';
|
||||
|
||||
const CustomGroup = (props) => {
|
||||
return (
|
||||
<div className="custom-group">
|
||||
<Group {...props} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
const CustomGroup = (props) => (
|
||||
<div className="custom-group">
|
||||
<Group {...props} />
|
||||
</div>
|
||||
);
|
||||
|
||||
CustomGroup.defaultProps = {
|
||||
value: '',
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
export { default as Group } from './src/client/components/forms/field-types/Group';
|
||||
export { default as Select } from './src/client/components/forms/field-types/Select';
|
||||
@@ -9,7 +9,7 @@ const sanitizeConfig = require('../utilities/sanitizeConfig');
|
||||
|
||||
const configPath = findConfig();
|
||||
|
||||
module.exports = () => {
|
||||
const build = () => {
|
||||
try {
|
||||
const unsanitizedConfig = getConfig();
|
||||
const config = sanitizeConfig(unsanitizedConfig);
|
||||
@@ -38,8 +38,12 @@ module.exports = () => {
|
||||
console.log(err);
|
||||
console.error(`Error: can't find the configuration file located at ${configPath}.`);
|
||||
}
|
||||
|
||||
// Need to get the path to the config file if it's been passed as an arg to the build command
|
||||
// If it hasn't been passed, just check the root of the project
|
||||
// If not in either place, return an error
|
||||
};
|
||||
|
||||
// when build.js is launched directly
|
||||
if (module.id === require.main.id) {
|
||||
build();
|
||||
}
|
||||
|
||||
|
||||
module.exports = build;
|
||||
|
||||
@@ -4,7 +4,7 @@ const args = require('minimist')(process.argv.slice(2));
|
||||
const build = require('./build');
|
||||
|
||||
const scriptIndex = args._.findIndex(
|
||||
x => x === 'build' || x === 'test',
|
||||
(x) => x === 'build' || x === 'test',
|
||||
);
|
||||
|
||||
const script = scriptIndex === -1 ? args._[0] : args._[scriptIndex];
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import React, { Suspense, lazy, useState, useEffect } from 'react';
|
||||
import {
|
||||
Route, Switch, withRouter, Redirect, useHistory,
|
||||
} from 'react-router-dom';
|
||||
@@ -6,21 +6,22 @@ import { useConfig } from './providers/Config';
|
||||
import List from './views/collections/List';
|
||||
import { useAuthentication } from './providers/Authentication';
|
||||
import DefaultTemplate from './templates/Default';
|
||||
import Dashboard from './views/Dashboard';
|
||||
import ForgotPassword from './views/ForgotPassword';
|
||||
import Login from './views/Login';
|
||||
import Logout from './views/Logout';
|
||||
import NotFound from './views/NotFound';
|
||||
import Verify from './views/Verify';
|
||||
import CreateFirstUser from './views/CreateFirstUser';
|
||||
import Edit from './views/collections/Edit';
|
||||
import EditGlobal from './views/Global';
|
||||
import { requests } from '../api';
|
||||
import ResetPassword from './views/ResetPassword';
|
||||
import Unauthorized from './views/Unauthorized';
|
||||
import Account from './views/Account';
|
||||
import Loading from './elements/Loading';
|
||||
|
||||
const Dashboard = lazy(() => import('./views/Dashboard'));
|
||||
const ForgotPassword = lazy(() => import('./views/ForgotPassword'));
|
||||
const Login = lazy(() => import('./views/Login'));
|
||||
const Logout = lazy(() => import('./views/Logout'));
|
||||
const NotFound = lazy(() => import('./views/NotFound'));
|
||||
const Verify = lazy(() => import('./views/Verify'));
|
||||
const CreateFirstUser = lazy(() => import('./views/CreateFirstUser'));
|
||||
const Edit = lazy(() => import('./views/collections/Edit'));
|
||||
const EditGlobal = lazy(() => import('./views/Global'));
|
||||
const ResetPassword = lazy(() => import('./views/ResetPassword'));
|
||||
const Unauthorized = lazy(() => import('./views/Unauthorized'));
|
||||
const Account = lazy(() => import('./views/Account'));
|
||||
|
||||
const Routes = () => {
|
||||
const history = useHistory();
|
||||
const [initialized, setInitialized] = useState(null);
|
||||
@@ -43,186 +44,188 @@ const Routes = () => {
|
||||
}, [history]);
|
||||
|
||||
return (
|
||||
<Route
|
||||
path={routes.admin}
|
||||
render={({ match }) => {
|
||||
if (initialized === false) {
|
||||
return (
|
||||
<Switch>
|
||||
<Route path={`${match.url}/create-first-user`}>
|
||||
<CreateFirstUser setInitialized={setInitialized} />
|
||||
</Route>
|
||||
<Route>
|
||||
<Redirect to={`${match.url}/create-first-user`} />
|
||||
</Route>
|
||||
</Switch>
|
||||
);
|
||||
}
|
||||
<Suspense fallback={<Loading />}>
|
||||
<Route
|
||||
path={routes.admin}
|
||||
render={({ match }) => {
|
||||
if (initialized === false) {
|
||||
return (
|
||||
<Switch>
|
||||
<Route path={`${match.url}/create-first-user`}>
|
||||
<CreateFirstUser setInitialized={setInitialized} />
|
||||
</Route>
|
||||
<Route>
|
||||
<Redirect to={`${match.url}/create-first-user`} />
|
||||
</Route>
|
||||
</Switch>
|
||||
);
|
||||
}
|
||||
|
||||
if (initialized === true) {
|
||||
return (
|
||||
<Switch>
|
||||
<Route path={`${match.url}/login`}>
|
||||
<Login />
|
||||
</Route>
|
||||
<Route path={`${match.url}/logout`}>
|
||||
<Logout />
|
||||
</Route>
|
||||
<Route path={`${match.url}/logout-inactivity`}>
|
||||
<Logout inactivity />
|
||||
</Route>
|
||||
<Route path={`${match.url}/forgot`}>
|
||||
<ForgotPassword />
|
||||
</Route>
|
||||
<Route path={`${match.url}/reset/:token`}>
|
||||
<ResetPassword />
|
||||
</Route>
|
||||
if (initialized === true) {
|
||||
return (
|
||||
<Switch>
|
||||
<Route path={`${match.url}/login`}>
|
||||
<Login />
|
||||
</Route>
|
||||
<Route path={`${match.url}/logout`}>
|
||||
<Logout />
|
||||
</Route>
|
||||
<Route path={`${match.url}/logout-inactivity`}>
|
||||
<Logout inactivity />
|
||||
</Route>
|
||||
<Route path={`${match.url}/forgot`}>
|
||||
<ForgotPassword />
|
||||
</Route>
|
||||
<Route path={`${match.url}/reset/:token`}>
|
||||
<ResetPassword />
|
||||
</Route>
|
||||
|
||||
{collections.map((collection) => {
|
||||
if (collection?.auth?.emailVerification) {
|
||||
return (
|
||||
<Route
|
||||
key={`${collection.slug}-verify`}
|
||||
path={`${match.url}/${collection.slug}/verify/:token`}
|
||||
exact
|
||||
>
|
||||
<Verify />
|
||||
</Route>
|
||||
);
|
||||
}
|
||||
return null;
|
||||
})}
|
||||
{collections.map((collection) => {
|
||||
if (collection?.auth?.emailVerification) {
|
||||
return (
|
||||
<Route
|
||||
key={`${collection.slug}-verify`}
|
||||
path={`${match.url}/${collection.slug}/verify/:token`}
|
||||
exact
|
||||
>
|
||||
<Verify />
|
||||
</Route>
|
||||
);
|
||||
}
|
||||
return null;
|
||||
})}
|
||||
|
||||
<Route
|
||||
render={() => {
|
||||
if (user) {
|
||||
if (canAccessAdmin) {
|
||||
return (
|
||||
<DefaultTemplate>
|
||||
<Switch>
|
||||
<Route
|
||||
path={`${match.url}/`}
|
||||
exact
|
||||
>
|
||||
<Dashboard />
|
||||
</Route>
|
||||
|
||||
<Route path={`${match.url}/account`}>
|
||||
<Account />
|
||||
</Route>
|
||||
|
||||
{collections.map((collection) => (
|
||||
<Route
|
||||
render={() => {
|
||||
if (user) {
|
||||
if (canAccessAdmin) {
|
||||
return (
|
||||
<DefaultTemplate>
|
||||
<Switch>
|
||||
<Route
|
||||
key={`${collection.slug}-list`}
|
||||
path={`${match.url}/collections/${collection.slug}`}
|
||||
path={`${match.url}/`}
|
||||
exact
|
||||
render={(routeProps) => {
|
||||
if (permissions?.[collection.slug]?.read?.permission) {
|
||||
return (
|
||||
<List
|
||||
{...routeProps}
|
||||
collection={collection}
|
||||
/>
|
||||
);
|
||||
}
|
||||
>
|
||||
<Dashboard />
|
||||
</Route>
|
||||
|
||||
return <Unauthorized />;
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
<Route path={`${match.url}/account`}>
|
||||
<Account />
|
||||
</Route>
|
||||
|
||||
{collections.map((collection) => (
|
||||
<Route
|
||||
key={`${collection.slug}-create`}
|
||||
path={`${match.url}/collections/${collection.slug}/create`}
|
||||
exact
|
||||
render={(routeProps) => {
|
||||
if (permissions?.[collection.slug]?.create?.permission) {
|
||||
return (
|
||||
<Edit
|
||||
{...routeProps}
|
||||
collection={collection}
|
||||
/>
|
||||
);
|
||||
}
|
||||
{collections.map((collection) => (
|
||||
<Route
|
||||
key={`${collection.slug}-list`}
|
||||
path={`${match.url}/collections/${collection.slug}`}
|
||||
exact
|
||||
render={(routeProps) => {
|
||||
if (permissions?.[collection.slug]?.read?.permission) {
|
||||
return (
|
||||
<List
|
||||
{...routeProps}
|
||||
collection={collection}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return <Unauthorized />;
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
return <Unauthorized />;
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
|
||||
{collections.map((collection) => (
|
||||
<Route
|
||||
key={`${collection.slug}-edit`}
|
||||
path={`${match.url}/collections/${collection.slug}/:id`}
|
||||
exact
|
||||
render={(routeProps) => {
|
||||
if (permissions?.[collection.slug]?.read?.permission) {
|
||||
return (
|
||||
<Edit
|
||||
isEditing
|
||||
{...routeProps}
|
||||
collection={collection}
|
||||
/>
|
||||
);
|
||||
}
|
||||
{collections.map((collection) => (
|
||||
<Route
|
||||
key={`${collection.slug}-create`}
|
||||
path={`${match.url}/collections/${collection.slug}/create`}
|
||||
exact
|
||||
render={(routeProps) => {
|
||||
if (permissions?.[collection.slug]?.create?.permission) {
|
||||
return (
|
||||
<Edit
|
||||
{...routeProps}
|
||||
collection={collection}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return <Unauthorized />;
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
return <Unauthorized />;
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
|
||||
{globals && globals.map((global) => (
|
||||
<Route
|
||||
key={`${global.slug}`}
|
||||
path={`${match.url}/globals/${global.slug}`}
|
||||
exact
|
||||
render={(routeProps) => {
|
||||
if (permissions?.[global.slug]?.read?.permission) {
|
||||
return (
|
||||
<EditGlobal
|
||||
{...routeProps}
|
||||
global={global}
|
||||
/>
|
||||
);
|
||||
}
|
||||
{collections.map((collection) => (
|
||||
<Route
|
||||
key={`${collection.slug}-edit`}
|
||||
path={`${match.url}/collections/${collection.slug}/:id`}
|
||||
exact
|
||||
render={(routeProps) => {
|
||||
if (permissions?.[collection.slug]?.read?.permission) {
|
||||
return (
|
||||
<Edit
|
||||
isEditing
|
||||
{...routeProps}
|
||||
collection={collection}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return <Unauthorized />;
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
return <Unauthorized />;
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
|
||||
<Route path={`${match.url}*`}>
|
||||
<NotFound />
|
||||
</Route>
|
||||
</Switch>
|
||||
</DefaultTemplate>
|
||||
);
|
||||
{globals && globals.map((global) => (
|
||||
<Route
|
||||
key={`${global.slug}`}
|
||||
path={`${match.url}/globals/${global.slug}`}
|
||||
exact
|
||||
render={(routeProps) => {
|
||||
if (permissions?.[global.slug]?.read?.permission) {
|
||||
return (
|
||||
<EditGlobal
|
||||
{...routeProps}
|
||||
global={global}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return <Unauthorized />;
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
|
||||
<Route path={`${match.url}*`}>
|
||||
<NotFound />
|
||||
</Route>
|
||||
</Switch>
|
||||
</DefaultTemplate>
|
||||
);
|
||||
}
|
||||
|
||||
if (canAccessAdmin === false) {
|
||||
return <Unauthorized />;
|
||||
}
|
||||
|
||||
return <Loading />;
|
||||
}
|
||||
|
||||
if (canAccessAdmin === false) {
|
||||
return <Unauthorized />;
|
||||
if (user === undefined) {
|
||||
return <Loading />;
|
||||
}
|
||||
return <Redirect to={`${match.url}/login`} />;
|
||||
}}
|
||||
/>
|
||||
<Route path={`${match.url}*`}>
|
||||
<NotFound />
|
||||
</Route>
|
||||
</Switch>
|
||||
);
|
||||
}
|
||||
|
||||
return <Loading />;
|
||||
}
|
||||
|
||||
if (user === undefined) {
|
||||
return <Loading />;
|
||||
}
|
||||
return <Redirect to={`${match.url}/login`} />;
|
||||
}}
|
||||
/>
|
||||
<Route path={`${match.url}*`}>
|
||||
<NotFound />
|
||||
</Route>
|
||||
</Switch>
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}}
|
||||
/>
|
||||
return null;
|
||||
}}
|
||||
/>
|
||||
</Suspense>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
// const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
||||
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
||||
const path = require('path');
|
||||
const webpack = require('webpack');
|
||||
const getStyleLoaders = require('./getStyleLoaders');
|
||||
@@ -81,7 +81,7 @@ module.exports = (config) => {
|
||||
},
|
||||
},
|
||||
plugins: [
|
||||
// new BundleAnalyzerPlugin(),
|
||||
new BundleAnalyzerPlugin(),
|
||||
new HtmlWebpackPlugin({
|
||||
template: config.admin && config.admin.indexHTML
|
||||
? path.join(config.paths.configDir, config.admin.indexHTML)
|
||||
|
||||
Reference in New Issue
Block a user