Skip to content

Commit f61a39e

Browse files
authored
chore: Add preload-webpack-plugin. (signalstickers#294)
1 parent 2705e3d commit f61a39e

File tree

6 files changed

+56
-7
lines changed

6 files changed

+56
-7
lines changed

babel.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@ module.exports = {
99
],
1010
plugins: [
1111
'react-hot-loader/babel'
12-
]
12+
],
13+
// Ensures Webpack comments are not prematurely removed by Babel. Comments
14+
// will still be stripped by the minifier in production builds.
15+
comments: true
1316
};

config/webpack.config.babel.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import FaviconsWebpackPlugin from 'favicons-webpack-plugin';
77
import FriendlyErrorsWebpackPlugin from 'friendly-errors-webpack-plugin';
88
import HtmlWebpackPlugin from 'html-webpack-plugin';
99
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
10+
// @ts-expect-error No declarations exist for this plugin.
11+
import PreloadWebpackPlugin from 'preload-webpack-plugin';
1012
import * as R from 'ramda';
1113
import webpack from 'webpack';
1214
import { FaviconWebpackPlugionOptions } from 'favicons-webpack-plugin/src/options';
@@ -231,8 +233,14 @@ export default (env: string, argv: any): webpack.Configuration => {
231233
inject: true
232234
}));
233235

236+
// Add resource hints to preload assets used in the initial chunk. This plugin
237+
// must be added after html-webpack-plugin.
238+
config.plugins.push(new PreloadWebpackPlugin({
239+
include: ['home']
240+
}));
241+
234242
config.plugins.push(new MiniCssExtractPlugin({
235-
filename: argv.mode === 'production' ? 'styles-[contenthash].css' : 'styles.css'
243+
filename: argv.mode === 'production' ? '[name]-[contenthash].css' : 'styles.css'
236244
}));
237245

238246
config.plugins.push(new webpack.LoaderOptionsPlugin({

package-lock.json

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
"json-loader": "^0.5.7",
9999
"mini-css-extract-plugin": "^0.9.0",
100100
"modernizr-loader": "^1.0.1",
101+
"preload-webpack-plugin": "^3.0.0-beta.3",
101102
"raw-loader": "^4.0.1",
102103
"react-hot-loader": "^4.12.21",
103104
"style-loader": "^1.2.1",

src/components/layout/AppLayout.tsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,25 @@ import {
2121

2222

2323
// Note: Each top-level route should be imported az a lazy-loaded component.
24-
const About = React.lazy(async () => import('components/about/About'));
25-
const Contribute = React.lazy(async () => import('components/contribute/Contribute'));
26-
const Home = React.lazy(async () => import('components/home/Home'));
27-
const Pack = React.lazy(async () => import('components/pack/StickerPackDetail'));
24+
const Home = React.lazy(async () => import(
25+
/* webpackChunkName: "home" */
26+
'components/home/Home'
27+
));
28+
29+
const Pack = React.lazy(async () => import(
30+
/* webpackChunkName: "detail" */
31+
'components/pack/StickerPackDetail'
32+
));
33+
34+
const Contribute = React.lazy(async () => import(
35+
/* webpackChunkName: "contribute" */
36+
'components/contribute/Contribute'
37+
));
38+
39+
const About = React.lazy(async () => import(
40+
/* webpackChunkName: "about" */
41+
'components/about/About'
42+
));
2843

2944

3045
// ----- Styles ----------------------------------------------------------------

src/index.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<meta name="twitter:site" content="@signalstickers" />
1212
<meta property="og:description" content="Community-organized gallery of sticker packs for Signal. Browse more than 1500 stickers, and propose your own!" />
1313
<meta property="og:image" content="https://raw.githubusercontent.com/signalstickers/signalstickers/master/src/assets/favicon.png" />
14-
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@100;200;300;400;500;600;700&display=block" rel="stylesheet">
14+
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Montserrat:wght@100;200;300;400;500;600;700" crossorigin="anonymous" />
1515
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
1616
<!-- Start Single Page Apps for GitHub Pages -->
1717
<script type="text/javascript">
@@ -44,6 +44,10 @@
4444
}(window.location))
4545
</script>
4646
<!-- End Single Page Apps for GitHub Pages -->
47+
48+
<!-- Resource Hints -->
49+
<link rel="preconnect" href="https://cdn-ca.signal.org" crossorigin="anonymous" />
50+
<link rel="preconnect" href="https://ping.signalstickers.com" />
4751
</head>
4852
<body>
4953
<noscript>You need to enable JavaScript to run this app.</noscript>

0 commit comments

Comments
 (0)