Skip to content

Commit

Permalink
fix webpack react-router
Browse files Browse the repository at this point in the history
  • Loading branch information
lucia-gomez committed Mar 27, 2024
1 parent 0ce00f0 commit decf70a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 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.

7 changes: 4 additions & 3 deletions media_commons_booking_app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"open": "clasp open --addon",
"setup:https": "mkdirp certs && mkcert -key-file ./certs/key.pem -cert-file ./certs/cert.pem localhost 127.0.0.1",
"build:local": "cross-env NODE_ENV=development CALENDAR_ENV=development webpack",
"build:dev": "cross-env NODE_ENV=production CALENDAR_ENV=development webpack",
"build:staging": "cross-env NODE_ENV=production CALENDAR_ENV=development webpack",
"build": "cross-env NODE_ENV=production CALENDAR_ENV=production webpack",
"build:dev": "cross-env NODE_ENV=production CALENDAR_ENV=development webpack --mode=production",
"build:staging": "cross-env NODE_ENV=production CALENDAR_ENV=development webpack --mode=production",
"build": "cross-env NODE_ENV=production CALENDAR_ENV=production webpack --mode=production",
"deploy:local": "rimraf dist && npm run build:local && npx clasp push",
"deploy:dev": "rimraf dist && npm run build:dev && npx clasp push",
"deploy:staging": "rimraf dist && npm run build:staging && npx clasp push",
Expand Down 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
13 changes: 7 additions & 6 deletions media_commons_booking_app/src/client/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { RouterProvider, createHashRouter } from 'react-router-dom';
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';

const router = createHashRouter([
const router = createMemoryRouter([
{
path: '/',
element: <Root />,
Expand Down Expand Up @@ -52,9 +52,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>
);
9 changes: 8 additions & 1 deletion media_commons_booking_app/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ const DynamicCdnWebpackPluginConfig = {
if (!isProd && packageName === 'react') {
return null;
}
if (
packageName === 'react-router-dom' ||
packageName === 'react-router' ||
packageName === '@remix-run/router'
) {
return null;
}

// define custom CDN configuration for new packages
// "name" should match the package being imported
Expand Down Expand Up @@ -267,7 +274,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 decf70a

Please sign in to comment.