diff --git a/.github/workflows/size.yml b/.github/workflows/size.yml new file mode 100644 index 000000000..bb1e153d8 --- /dev/null +++ b/.github/workflows/size.yml @@ -0,0 +1,68 @@ +name: size +on: + # this action will error unless run in a pr context + pull_request: + pull_request_target: + +jobs: + # Build current and upload stats.json + # You may replace this with your own build method. All that + # is required is that the stats.json be an artifact + build-head: + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + with: + ref: ${{ github.event.pull_request.head.ref }} + - run: corepack enable + - uses: actions/setup-node@v4 + with: + node-version: 18 + cache: "pnpm" + - run: pnpm install + - run: pnpm build + - name: Upload stats.json + uses: actions/upload-artifact@v3 + with: + name: head-stats + path: ./stats.json + + # Build base for comparison and upload stats.json + # You may replace this with your own build method. All that + # is required is that the stats.json be an artifact + build-base: + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + with: + ref: ${{ github.base_ref }} + - run: corepack enable + - uses: actions/setup-node@v4 + with: + node-version: 18 + cache: "pnpm" + - run: pnpm install + - run: pnpm build + - name: Upload stats.json + uses: actions/upload-artifact@v3 + with: + name: base-stats + path: ./stats.json + + # run the action against the stats.json files + compare: + runs-on: ubuntu-latest + needs: [build-base, build-head] + permissions: + pull-requests: write + steps: + - uses: actions/download-artifact@v3 + - uses: twk3/rollup-size-compare-action@v1.0.0 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + current-stats-json-path: ./head-stats/stats.json + base-stats-json-path: ./base-stats/stats.json diff --git a/.gitignore b/.gitignore index 9c591c11b..2aeecfa8d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ dist nuxt-app .pnpm-store coverage +stats.json diff --git a/build.config.ts b/build.config.ts index f05e034fa..b88bed1db 100644 --- a/build.config.ts +++ b/build.config.ts @@ -1,6 +1,7 @@ import { defineBuildConfig } from 'unbuild' import type { InputPluginOption } from 'rollup' import { purgePolyfills } from 'unplugin-purge-polyfills' +import { visualizer } from 'rollup-plugin-visualizer' export default defineBuildConfig({ declaration: true, @@ -10,6 +11,7 @@ export default defineBuildConfig({ plugins.push(purgePolyfills.rollup({ logLevel: 'verbose', })) + plugins.push(visualizer({ template: 'raw-data' })) }, }, rollup: { diff --git a/package.json b/package.json index aa506d55a..8b874c308 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,7 @@ "pkg-pr-new": "^0.0.39", "pkg-types": "^1.3.0", "rollup": "^4.30.0", + "rollup-plugin-visualizer": "^5.13.1", "scule": "^1.3.0", "semver": "^7.6.3", "std-env": "^3.8.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 414f3d375..6f7e4de2e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -118,6 +118,9 @@ importers: rollup: specifier: ^4.30.0 version: 4.30.0 + rollup-plugin-visualizer: + specifier: ^5.13.1 + version: 5.13.1(rollup@4.30.0) scule: specifier: ^1.3.0 version: 1.3.0