Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Add bundle size reporting to PRs (#1332)

sarayourfrienda92edbf53e48
diff --git a/.github/workflows/bundle_size.yml b/.github/workflows/bundle_size.yml
new file mode 100644
index 000000000..901a56312
--- /dev/null
+++ b/.github/workflows/bundle_size.yml
@@ -0,0 +1,47 @@
+name: Compressed Size
+
+on:
+ pull_request:
+ paths:
+ - "**.ts"
+ - "**.js"
+ - "**.vue"
+ - "**.css"
+ - "**.scss"
+ # Changes to any dependency
+ - "pnpm-lock.yaml"
+ # This file configures ESLint. Changes could affect the outcome.
+ - "**.eslint*"
+ # This file configures Prettier. Changes could affect the outcome.
+ - "**.prettier*"
+ # This file configures TypeScript. Changes could affect the outcome.
+ - "**.tsconfig*"
+ # This file configures Nuxt (and therefore the build). Changes could affect the outcome.
+ - "nuxt.config.ts"
+ # This file configures Tailwind and could affect the style outcome.
+ - "tailwind.config.js"
+ # Changes to this workflow file should always verify the changes are successful.
+ - ".github/workflows/bundle_size.yml"
+
+# Cancels all previous workflow runs for pull requests that have not completed.
+concurrency:
+ # The concurrency group contains the workflow name and the branch name for pull requests
+ # or the commit hash for any other events.
+ group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
+ cancel-in-progress: true
+
+jobs:
+ build:
+ name: Check
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v2
+
+ - uses: ./.github/actions/setup-node-env
+
+ - uses: preactjs/[email protected]
+ with:
+ repo-token: "${{ secrets.GITHUB_TOKEN }}"
+ # Only measure changes in the client, we don't care much about the size of the server bundles (I don't think?)
+ pattern: "./.nuxt/dist/client/**/*.{modern.js,js,css}"
diff --git a/nuxt.config.ts b/nuxt.config.ts
index 6dd601b32..c8d3939a6 100644
--- a/nuxt.config.ts
+++ b/nuxt.config.ts
@@ -108,6 +108,26 @@ const head = {
],
}
+const baseProdName = process.env.CI ? '[name]' : '[contenthash:7]'
+
+const filenames: NonNullable<NuxtConfig['build']>['filenames'] = {
+ app: ({ isDev, isModern }) =>
+ isDev
+ ? `[name]${isModern ? '.modern' : ''}.js`
+ : `${baseProdName}${isModern ? '.modern' : ''}.js`,
+ chunk: ({ isDev, isModern }) =>
+ isDev
+ ? `[name]${isModern ? '.modern' : ''}.js`
+ : `${baseProdName}${isModern ? '.modern' : ''}.js`,
+ css: ({ isDev }) => (isDev ? '[name].css' : `css/${baseProdName}.css`),
+ img: ({ isDev }) =>
+ isDev ? '[path][name].[ext]' : `img/${baseProdName}.[ext]`,
+ font: ({ isDev }) =>
+ isDev ? '[path][name].[ext]' : `fonts/${baseProdName}.[ext]`,
+ video: ({ isDev }) =>
+ isDev ? '[path][name].[ext]' : `videos/${baseProdName}.[ext]`,
+}
+
const config: NuxtConfig = {
// eslint-disable-next-line no-undef
version: pkg.version, // used to purge cache :)
@@ -225,6 +245,7 @@ const config: NuxtConfig = {
dst: 'index.js',
},
],
+ filenames,
friendlyErrors: false,
postcss: {
plugins: {