Skip to content

Commit

Permalink
chore(size-limit): check also for next-app dist folder (#1972)
Browse files Browse the repository at this point in the history
* chore(size-limit): check also for next-app dist folder

* ci: build examples before running check size

* ci: check-size just after builds
  • Loading branch information
belgattitude authored Oct 20, 2022
1 parent 47a0295 commit 55a285b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ jobs:
- name: Build next-i18next
run: npm run build

- name: Check dist for ecmascript compliance
run: npm run check-dist
- name: Build examples
run: npm run build:examples

- name: Check size limits
run: npm run check-size

- name: Check dist for ecmascript compliance
run: npm run check-dist

- name: Unit tests
run: npm test

Expand Down
42 changes: 39 additions & 3 deletions .size-limit.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,38 @@
const fullEsmMaxSize = "23KB";
const fullCjsMaxSize = "46KB";

const getSimpleExamplePageLimits = () => {
const dir = './examples/simple/.next'
let manifest;
try {
manifest = require(`${dir}/build-manifest.json`);
} catch (e) {
throw new Error(
'Cannot find a NextJs build folder, did you forget to run build:examples ?'
);
}
const limitCfg = {
defaultSize: '90kb',
pages: {
'/': '85kb',
'/404': '90kb',
'/_app': '100kb',
'/_error': '80Kb',
'/second-page': '85Kb'
},
};
let pageLimits = [];
for (const [uri, paths] of Object.entries(manifest.pages)) {
pageLimits.push({
name: `Example app: page '${uri}'`,
limit: limitCfg.pages?.[uri] ?? limitCfg.defaultSize,
webpack: false,
path: paths.map(p => `${dir}/${p}`)
});
}
return pageLimits;
}

const modifyWebpackConfig = config => {
config.resolve = {};
config.resolve.fallback = { "path": false, "fs": false };
Expand All @@ -16,7 +48,7 @@ const modifyWebpackConfig = config => {
*/
module.exports = [
// ###################################################
// ESM full bundle
// Dist ESM full bundle
// ###################################################
{
name: "ESM (import everything *)",
Expand All @@ -26,7 +58,7 @@ module.exports = [
modifyWebpackConfig,
},
// ###################################################
// Commonjs full bundle
// Fist commonjs full bundle
// ###################################################
{
name: "CJS (require everything *)",
Expand All @@ -35,5 +67,9 @@ module.exports = [
webpack: true,
limit: fullCjsMaxSize,
modifyWebpackConfig,
}
},
// ###################################################
// Example apps
// ###################################################
...getSimpleExamplePageLimits(),
];
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"build:esm": "BABEL_ENV=esm babel src --extensions '.ts,.tsx' --out-dir dist/esm --copy-files",
"build:types": "tsc --noEmit false --declaration --emitDeclarationOnly --outDir dist/types",
"build": "npm run clean && npm run build:cjs && npm run build:es && npm run build:esm && npm run build:types",
"build:examples": "run-s build:example:*",
"build:example:simple": "cd examples/simple && npm run build",
"build:example:ssg": "cd examples/ssg && npm run build",
"install:example:simple": "cd examples/simple && npm install",
Expand Down Expand Up @@ -131,9 +132,9 @@
"npm-run-all": "^4.1.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"size-limit": "8.1.0",
"start-server-and-test": "^1.14.0",
"typescript": "^4.7.4",
"size-limit": "8.1.0",
"webpack": "5.74.0"
},
"dependencies": {
Expand Down

0 comments on commit 55a285b

Please sign in to comment.