Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support vite #42

Merged
merged 7 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ on:
jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
builder: ['vite', 'webpack']

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
Expand All @@ -24,3 +29,5 @@ jobs:

- name: Run tests
run: pnpm run test
env:
NUXT_BUNDLE_ANALYSIS_BUILDER: ${{ matrix.builder }}
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ By combining this script with a github actions, it is possible to send bundle si
npx -p nuxt-bundle-analysis generate
```

2. Setting nuxt.config.js and Build.
2. Setting nuxt.config.js and Build. (If you are using webpack.)
Set nuxt.config.js as follows so that bundle statistics are output.
After configuration and build, `.nuxt/stats.client.json` will be output.

Expand Down Expand Up @@ -51,12 +51,14 @@ See [here](#Options) for options.

## Options

| property | type | description | default |
| :----------------------- | :----- | :------------------------------------------------------------ | :---------------------- |
| `statsFile` | string | The path to the json file containing bundle statistics. | .nuxt/stats/client.json |
| `buildOutputDirectory` | string | Directory generated by `nuxt build` | .nuxt |
| `minimumChangeThreshold` | number | The threshold under which pages will be considered unchanged. | 0 |
| `clientDir` | string | The directory where the client chunk is generated. | dist/client |
| property | type | description | default |
| :----------------------- | :----- | :--------------------------------------------------------------------------------------------------------------- | :---------------------- |
| `statsFile` | string | The path to the json file containing bundle statistics. (Use for `builder: webpack`.) | .nuxt/stats/client.json |
| `buildOutputDirectory` | string | Directory generated by `nuxt build` | .nuxt |
| `minimumChangeThreshold` | number | The threshold under which pages will be considered unchanged. | 0 |
| `clientDir` | string | The directory where the client chunk is generated. (Use for `builder: webpack`.) | dist/client |
| `builder` | string | Sets the `builder` of nuxt.(`webpack` or `vite`) <br /> It can also be set using `NUXT_BUNDLE_ANALYSIS_BUILDER`. | `webpack` |
| `outputDirectory` | string | The directory where the output files are generated. | `.output` |

## GitHub Actions Sample

Expand Down
1 change: 1 addition & 0 deletions build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { defineBuildConfig } from 'unbuild';

export default defineBuildConfig({
entries: [
'src/vite/report.ts',
'src/compare.ts',
'src/generate.ts',
'src/report.ts',
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"scripts": {
"test": "pnpm build && pnpm build:playground && pnpm dev:prepare && pnpm report && pnpm compare && vitest run",
"test:update": "pnpm build && pnpm build:playground && pnpm dev:prepare && pnpm report && pnpm compare && vitest -u",
"test:vite": "NUXT_BUNDLE_ANALYSIS_BUILDER=\"vite\" pnpm run test",
"minor": "npm version minor",
"build": "unbuild",
"build:playground": "pnpm --filter playground build",
Expand Down Expand Up @@ -42,10 +43,13 @@
],
"dependencies": {
"@discoveryjs/json-ext": "^0.6.1",
"defu": "^6.1.4",
"destr": "^2.0.3",
"filesize": "^8.0.7",
"globby": "^14.0.2",
"inquirer": "^8.2.4",
"mkdirp": "^1.0.4",
"pathe": "^1.1.2",
"pkg-types": "^1.1.3"
},
"devDependencies": {
Expand Down
6 changes: 5 additions & 1 deletion playground/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { defineNuxtConfig } from 'nuxt/config';

const builder = (process.env.NUXT_BUNDLE_ANALYSIS_BUILDER || 'webpack') as
| 'webpack'
| 'vite';

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
ssr: false,
telemetry: false,
builder: 'webpack',
builder: builder,
webpack: {
analyze: {
generateStatsFile: true,
Expand Down
Loading