Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(css): pure css chunk removal + manifest entry with multiple css f…
…iles fix #1776 BREAKING CHANGE: the "css" property of build manifest entries is now an array because it is possible for an entry to link to multiple generated css files.
- Loading branch information
Showing
9 changed files
with
71 additions
and
4 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
packages/playground/css-codesplit/__tests__/css-codesplit.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import fs from 'fs' | ||
import path from 'path' | ||
import { findAssetFile, getColor, isBuild, testDir } from '../../testUtils' | ||
|
||
test('should load both stylesheets', async () => { | ||
expect(await getColor('h1')).toBe('red') | ||
expect(await getColor('h2')).toBe('blue') | ||
}) | ||
|
||
if (isBuild) { | ||
test('should remove empty chunk', async () => { | ||
expect(findAssetFile(/style.*\.js$/)).toBe('') | ||
expect(findAssetFile('main.*.js$')).toMatch(`/* empty css`) | ||
expect(findAssetFile('other.*.js$')).toMatch(`/* empty css`) | ||
}) | ||
|
||
test('should generate correct manifest', async () => { | ||
const manifest = JSON.parse( | ||
fs.readFileSync(path.join(testDir, 'dist', 'manifest.json'), 'utf-8') | ||
) | ||
expect(manifest['index.html'].css.length).toBe(2) | ||
expect(manifest['other.js'].css.length).toBe(1) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<script type="module" src="/main.js"></script> | ||
<div id="app"></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
h1 { | ||
color: red; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import './style.css' | ||
import './main.css' | ||
|
||
document.getElementById( | ||
'app' | ||
).innerHTML = `<h1>This should be red</h1><h2>This should be blue</h2>` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import './style.css' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "test-css-codesplit", | ||
"private": true, | ||
"version": "0.0.0", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"debug": "node --inspect-brk ../../vite/bin/vite", | ||
"serve": "vite preview" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
h2 { | ||
color: blue; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const { resolve } = require('path') | ||
|
||
module.exports = { | ||
build: { | ||
manifest: true, | ||
rollupOptions: { | ||
input: { | ||
main: resolve(__dirname, './index.html'), | ||
other: resolve(__dirname, './other.js') | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters