Skip to content

Commit

Permalink
fix: only analyze client-side bundle sizes
Browse files Browse the repository at this point in the history
Uses the temporary fix proposed by @jeantil in vercel/next.js#15481.
  • Loading branch information
nicholaschiang committed Jul 27, 2020
1 parent 44cf741 commit 27eb3e8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 40 deletions.
26 changes: 18 additions & 8 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
const path = require('path');
const withImages = require('next-images');
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
});
const { locales } = require('./lib/intl/config.json');

// prettier-ignore
module.exports = withBundleAnalyzer(withImages({
module.exports = withImages({
sassOptions: {
includePaths: [
path.resolve(__dirname, 'node_modules'),
Expand Down Expand Up @@ -54,13 +50,27 @@ module.exports = withBundleAnalyzer(withImages({
//
// @see {@link https://github.com/UnlyEd/next-right-now/pull/42}
// @see {@link https://github.com/pillarjs/path-to-regexp/issues/223}
source: `/:locale((?!${locales.join('|')}|favicon|api|sw.js)[^/]+)(.*)`,
source: `/:locale((?!${locales.join(
'|'
)}|favicon|api|sw.js)[^/]+)(.*)`,
destination: '/api/redirect',
},
];
},
},
webpack(config) {
webpack(config, { isServer }) {
if (!isServer && process.env.ANALYZE === 'true') {
// Only run the bundle analyzer for the client-side chunks.
// @see {@link https://github.com/vercel/next.js/issues/15481}
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
config.plugins.push(
new BundleAnalyzerPlugin({
analyzerMode: 'static',
reportFilename: './analyze/client.html',
generateStatsFile: true,
})
);
}
config.module.rules.push({
test: /\.hbs$/,
use: 'raw-loader',
Expand All @@ -83,4 +93,4 @@ module.exports = withBundleAnalyzer(withImages({
SENDGRID_API_KEY: process.env.SENDGRID_API_KEY,
BRAMBLE_API_KEY: process.env.BRAMBLE_API_KEY,
},
}));
});
34 changes: 3 additions & 31 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"url": "https://github.com/tutorbookapp/tutorbook/issues"
},
"devDependencies": {
"@next/bundle-analyzer": "^9.4.4",
"@types/accept-language-parser": "^1.5.1",
"@types/jest": "^25.2.3",
"@types/node": "^14.0.26",
Expand Down Expand Up @@ -75,6 +74,7 @@
"ts-loader": "^7.0.5",
"typescript": "^3.9.7",
"webpack": "^4.44.0",
"webpack-bundle-analyzer": "^3.8.0",
"webpack-cli": "^3.3.12"
},
"dependencies": {
Expand Down

0 comments on commit 27eb3e8

Please sign in to comment.