Skip to content

Commit

Permalink
add react-router-dom cdn webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
lucia-gomez committed Mar 26, 2024
1 parent 0ce00f0 commit 9959343
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
1 change: 1 addition & 0 deletions media_commons_booking_app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions media_commons_booking_app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"react-bootstrap": "^2.4.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.45.2",
"react-router": "^6.22.3",
"react-router-dom": "^6.22.3",
"react-transition-group": "^4.4.2",
"tailwind-datepicker-react": "^1.4.2",
Expand Down
12 changes: 12 additions & 0 deletions media_commons_booking_app/src/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@
crossorigin="anonymous"
/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/flowbite/1.8.1/datepicker.min.js"></script>
<!-- <script
src="https://cdnjs.cloudflare.com/ajax/libs/react-router-dom/6.22.3/react-router-dom.production.min.js"
integrity="sha512-eFKluaAyNJr8h7VL24su8w9qVFlNeLEI6nroW/ltJoh79cMIqXbHbJ+rKRZxalcTWiUPecOnSDnjVKsyAOA0xQ=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/react-router/6.22.3/react-router.production.min.js"
integrity="sha512-8GcWjbp4e2GeKa8Fz1Z3mqWvkiVrk6waiVdBG96PsOg30I9rjaOWDgD58A5umDn8KNs0OAxAYliKtX/r1mSy/A=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
></script> -->
</head>
<body>
<section id="index">
Expand Down
17 changes: 11 additions & 6 deletions media_commons_booking_app/src/client/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import { RouterProvider, createHashRouter } from 'react-router-dom';
'use client';

import { RouterProvider, createMemoryRouter } from 'react-router-dom';

import AdminPage from './routes/admin/adminPage';
import BookingForm from './routes/booking/BookingForm';
import ErrorPage from './errorPage';
import LandingPage from './routes/booking/formPages/LandingPage';
import PAPage from './routes/pa/PAPage';
import React from 'react';
import ReactDOM from 'react-dom';
import Root from './routes/root';
import SelectRoomPage from './routes/booking/formPages/SelectRoomPage';
import UserRolePage from './routes/booking/formPages/UserRolePage';
import UserSectionPage from './routes/booking/formPages/UserSectionPage';
import { createRoot } from 'react-dom/client';

console.log('TEST IN INDEX.JS');

const router = createHashRouter([
const router = createMemoryRouter([
{
path: '/',
element: <Root />,
Expand Down Expand Up @@ -52,9 +56,10 @@ const router = createHashRouter([
},
]);

ReactDOM.render(
const container = document.getElementById('index');
const root = createRoot(container);
root.render(
<React.StrictMode>
<RouterProvider router={router} />
</React.StrictMode>,
document.getElementById('index')
</React.StrictMode>
);
16 changes: 15 additions & 1 deletion media_commons_booking_app/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,20 @@ const DynamicCdnWebpackPluginConfig = {
version: packageVersion,
url: `https://unpkg.com/@types/react@${packageVersion}/index.d.ts`,
};
case 'react-router-dom':
return {
name: packageName,
var: 'ReactRouterDOM',
version: packageVersion,
url: `https://cdnjs.cloudflare.com/ajax/libs/react-router-dom/${packageVersion}/react-router-dom.production.min.js`,
};
case 'react-router':
return {
name: packageName,
var: 'ReactRouter',
version: packageVersion,
url: `https://cdnjs.cloudflare.com/ajax/libs/react-router/${packageVersion}/react-router.production.min.js`,
};
// return defaults/null depending if Dynamic CDN plugin finds package
default:
return moduleDetails;
Expand All @@ -267,7 +281,7 @@ const clientConfigs = clientEntrypoints.map((clientEntrypoint) => {
}),
new HtmlWebpackPlugin({
template: clientEntrypoint.template,
filename: `${clientEntrypoint.filename}.html`,
filename: `${clientEntrypoint.filename}${isProd ? '' : '-impl'}.html`,
inlineSource: '^/.*(js|css)$', // embed all js and css inline, exclude packages from dynamic cdn insertion
scriptLoading: 'blocking',
inject: 'body',
Expand Down

0 comments on commit 9959343

Please sign in to comment.