Skip to content

Commit

Permalink
feat: 🎸 add bundle analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
TeXmeijin committed Feb 15, 2024
1 parent 6ffb881 commit 98c9b9f
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 5 deletions.
93 changes: 93 additions & 0 deletions .github/workflows/example-bundle-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: 'Next.js Bundle Analysis'

on:
pull_request:
paths:
- 'example-nextjs-app/**'
- '!**.md'
workflow_dispatch:

defaults:
run:
# change this if your nextjs app does not live at the root of the repo
working-directory: ./example-nextjs-app

env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

jobs:
analyze:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up node
uses: actions/setup-node@v3
with:
node-version: '20'

- run: yarn install --frozen-lockfile

- name: Build next.js app
run: yarn build

# Here's the first place where next-bundle-analysis' own script is used
# This step pulls the raw bundle stats for the current bundle
- name: Analyze bundle
run: npx -p nextjs-bundle-analysis report

- name: Upload bundle
uses: actions/upload-artifact@v3
with:
name: bundle
path: example-nextjs-app/.next/analyze/__bundle_analysis.json
if-no-files-found: error

- name: Download base branch bundle stats
uses: dawidd6/action-download-artifact@v2
if: success() && github.event.number
with:
workflow: nextjs_bundle_analysis.yml
branch: ${{ github.event.pull_request.base.ref }}
name: bundle
path: example-nextjs-app/.next/analyze/base/bundle
if_no_artifact_found: warn
search_artifacts: true

- name: Compare with base branch bundle
if: success() && github.event.number
run: ls -laR .next/analyze/base/bundle && npx -p nextjs-bundle-analysis compare

- name: Get comment body
id: get-comment-body
if: success() && github.event.number
run: |
body=$(cat .next/analyze/__bundle_analysis_comment.txt)
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo ::set-output name=body::$body
- name: Find Comment
uses: peter-evans/find-comment@v1
if: success() && github.event.number
id: fc
with:
issue-number: ${{ github.event.number }}
body-includes: '<!-- __NEXTJS_BUNDLE -->'

- name: Create Comment
uses: peter-evans/[email protected]
if: success() && github.event.number && steps.fc.outputs.comment-id == 0
with:
issue-number: ${{ github.event.number }}
body: ${{ steps.get-comment-body.outputs.body }}

- name: Update Comment
uses: peter-evans/[email protected]
if: success() && github.event.number && steps.fc.outputs.comment-id != 0
with:
issue-number: ${{ github.event.number }}
body: ${{ steps.get-comment-body.outputs.body }}
comment-id: ${{ steps.fc.outputs.comment-id }}
edit-mode: replace
3 changes: 1 addition & 2 deletions example-nextjs-app/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import Image from "next/image";
import {Text} from "@texmeijin/ui-library-example";

export default function Home() {
return (
<main className="flex min-h-screen flex-col items-center justify-between p-24">
<div className="z-10 max-w-5xl w-full items-center justify-between font-mono text-sm lg:flex">
<p className="fixed left-0 top-0 flex w-full justify-center border-b border-gray-300 bg-gradient-to-b from-zinc-200 pb-6 pt-8 backdrop-blur-2xl dark:border-neutral-800 dark:bg-zinc-800/30 dark:from-inherit lg:static lg:w-auto lg:rounded-xl lg:border lg:bg-gray-200 lg:p-4 lg:dark:bg-zinc-800/30">
Get started by editing&nbsp;
<Text>src/app/page.tsx</Text>
{/*<Text>src/app/page.tsx</Text>*/}
</p>
<div className="fixed bottom-0 left-0 flex h-48 w-full items-end justify-center bg-gradient-to-t from-white via-white dark:from-black dark:via-black lg:static lg:h-auto lg:w-auto lg:bg-none">
<a
Expand Down
5 changes: 2 additions & 3 deletions example-nextjs-app/src/app/with-editor/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import {Editor} from "@/app/with-editor/editor";

type Props = {}

const page = (props: Props) => {
return (
<div className={'p-8'}>
<Editor></Editor>
hoge
{/*<Editor></Editor>*/}
</div>
)
};
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { cname } from './utils/cname/cname'
export { RichTextEditor } from './components/RichTextEditor/RichTextEditor'
export { Text } from './components/Text/Text'

0 comments on commit 98c9b9f

Please sign in to comment.