Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): improve plugin builds #749

Merged
merged 3 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions cli/src/lib/plugin/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,23 +276,34 @@ module.exports = ({ env: webpackEnv, config, paths }) => {
},
}),
},
// 'asset/resource' fixes fonts, but 'file-loader' breaks css modules
// when used for all asset types. So use each for respective files
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: 'asset/resource',
generator: {
filename: 'static/media/[name].[hash][ext]',
},
},
// "file" loader makes sure those assets get served by WebpackDevServer.
// When you `import` an asset, you get its (virtual) filename.
// In production, they would get copied to the `build` folder.
// This loader doesn't use a "test" so it will catch all modules
// that fall through the other loaders.
{
loader: require.resolve('file-loader'),
// Exclude `js` files to keep "css" loader working as it injects
// its runtime that would otherwise be processed through "file" loader.
// Also exclude `html` and `json` extensions so they get processed
// by webpacks internal loaders.
exclude: [
/^$/,
/\.(js|mjs|jsx|ts|tsx)$/,
/\.html$/,
/\.json$/,
],
type: 'asset/resource',
options: {
name: 'static/media/[name].[hash:8].[ext]',
},
},
],
},
Expand Down
2 changes: 1 addition & 1 deletion pwa/src/lib/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export function register(config) {
window.addEventListener('load', () => {
// By compiling the dev SW to the 'public' dir, this URL works in
// both dev and production modes
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`
const swUrl = new URL('service-worker.js', publicUrl)

if (isLocalhost) {
// This is running on localhost. Let's check if a service worker still exists or not.
Expand Down
6 changes: 5 additions & 1 deletion pwa/src/service-worker/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,12 @@ export function setUpServiceWorker() {
)

// Network-first caching by default
// (and for static assets while in development)
// * NOTE: there may be lazy-loading errors while offline in dev mode
registerRoute(
({ url }) => urlMeetsAppShellCachingCriteria(url),
({ url }) =>
urlMeetsAppShellCachingCriteria(url) ||
(!PRODUCTION_ENV && fileExtensionRegexp.test(url.pathname)),
new NetworkFirst({ cacheName: 'app-shell' })
)

Expand Down