Skip to content

Commit a82fd9f

Browse files
committed
Improve rollup conf
The app couldn't run in dev mode without these changes.
1 parent 6eafe9d commit a82fd9f

5 files changed

Lines changed: 41 additions & 157 deletions

File tree

config/rollup.mjs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import fs from 'fs';
12
import { babel } from '@rollup/plugin-babel';
23
import commonjs from '@rollup/plugin-commonjs';
4+
import json from '@rollup/plugin-json';
35
import postcss from 'rollup-plugin-postcss';
46
import replace from '@rollup/plugin-replace';
57
import resolve from '@rollup/plugin-node-resolve';
@@ -14,7 +16,7 @@ import livereload from 'rollup-plugin-livereload';
1416
const isDev = process.env.ROLLUP_WATCH === 'true';
1517

1618
export default {
17-
input: 'src/index-build.js',
19+
input: isDev ? 'src/index.js' : 'src/index-build.js',
1820
output: {
1921
name: 'waybackDiff',
2022
file: 'build/app.js',
@@ -38,19 +40,30 @@ export default {
3840
extensions: ['.css'],
3941
plugins: [cssnano()]
4042
}),
43+
json(),
4144
babel({
4245
babelrc: false,
4346
exclude: 'node_modules/**',
4447
babelHelpers: 'bundled',
4548
presets: ['@babel/preset-env', '@babel/preset-react'],
4649
plugins: ['@babel/plugin-proposal-export-default-from']
4750
}),
48-
!isDev && terser(), // only minify in production
51+
terser(),
4952
isDev && serve({
5053
open: true,
5154
contentBase: ['build', 'public'],
5255
host: '0.0.0.0',
53-
port: 5000
56+
port: 5000,
57+
historyApiFallback: true,
58+
//
59+
// To enable https you need:
60+
// mkdir cert
61+
// openssl req -x509 -newkey rsa:4096 -nodes -keyout cert/key.pem -out cert/cert.pem -days 36
62+
//
63+
// https: {
64+
// key: fs.readFileSync('cert/key.pem'),
65+
// cert: fs.readFileSync('cert/cert.pem')
66+
// }
5467
}),
5568
isDev && livereload({ watch: 'build' })
5669
].filter(Boolean)

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"@babel/preset-react": "^7.28",
2929
"@rollup/plugin-babel": "^6.1.0",
3030
"@rollup/plugin-commonjs": "^26.0.1",
31+
"@rollup/plugin-json": "^6.1.0",
3132
"@rollup/plugin-node-resolve": "^15.0.1",
3233
"@rollup/plugin-replace": "^5.0.2",
3334
"@rollup/plugin-terser": "^0.4.0",
@@ -44,7 +45,7 @@
4445
"eslint-plugin-react": "^7.35",
4546
"jest": "^30.0.0",
4647
"jest-environment-jsdom": "^30.0.0",
47-
"jsdom": "^27.0.0",
48+
"jsdom": "^26.0.0",
4849
"postcss": "^8.5.6",
4950
"rollup": "4.31.0",
5051
"rollup-plugin-livereload": "^2.0.5",

public/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
manifest.json provides metadata used when your web app is added to the
99
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
1010
-->
11-
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
11+
<link rel="manifest" href="/manifest.json">
1212
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
1313
<!--
1414
Notice the use of %PUBLIC_URL% in the tags above.
@@ -26,5 +26,7 @@
2626
You need to enable JavaScript to run this app.
2727
</noscript>
2828
<div id="wayback-diff">This</div>
29+
<!-- Include your Rollup bundle -->
30+
<script type="module" src="/app.js"></script>
2931
</body>
3032
</html>

src/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ import DiffContainer from './components/diff-container.jsx';
88
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
99
import SunburstContainer from './components/sunburst/sunburst-container.jsx';
1010

11-
const conf = require('./conf.json');
11+
import conf from './conf.json';
1212
const root = createRoot(document.getElementById('wayback-diff'));
1313

14+
// /hello endpoint is to test that React routing works.
15+
1416
root.render(
1517
<StrictMode>
1618
<Router>
1719
<Switch>
20+
<Route path="/hello" component={() => <div>Hello, this is static text!</div>} />
21+
1822
<Route path='/diff/([0-9]{14})/([0-9]{14})/(.+)' render={({ match, location }) =>
1923
<DiffContainer url={match.params[2] + location.search} timestampA={match.params[0]}
2024
loader={null}

0 commit comments

Comments
 (0)