Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: style use string instead of js import (#7786)
  • Loading branch information
poyoho committed Apr 22, 2022
1 parent d7540c8 commit ba43c29
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/playground/worker/__tests__/es/es-worker.spec.ts
Expand Up @@ -60,7 +60,7 @@ if (isBuild) {
// assert correct files
test('inlined code generation', async () => {
const files = fs.readdirSync(assetsDir)
expect(files.length).toBe(22)
expect(files.length).toBe(21)
const index = files.find((f) => f.includes('main-module'))
const content = fs.readFileSync(path.resolve(assetsDir, index), 'utf-8')
const worker = files.find((f) => f.includes('my-worker'))
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/worker/__tests__/iife/worker.spec.ts
Expand Up @@ -63,7 +63,7 @@ if (isBuild) {
// assert correct files
test('inlined code generation', async () => {
const files = fs.readdirSync(assetsDir)
expect(files.length).toBe(13)
expect(files.length).toBe(12)
const index = files.find((f) => f.includes('main-module'))
const content = fs.readFileSync(path.resolve(assetsDir, index), 'utf-8')
const worker = files.find((f) => f.includes('my-worker'))
Expand Down
Expand Up @@ -9,7 +9,7 @@ if (isBuild) {
test('sourcemap generation for web workers', async () => {
const files = fs.readdirSync(assetsDir)
// should have 2 worker chunk
expect(files.length).toBe(25)
expect(files.length).toBe(24)
const index = files.find((f) => f.includes('main-module'))
const content = fs.readFileSync(path.resolve(assetsDir, index), 'utf-8')
const indexSourcemap = getSourceMapUrl(content)
Expand Down
Expand Up @@ -9,7 +9,7 @@ if (isBuild) {
test('sourcemap generation for web workers', async () => {
const files = fs.readdirSync(assetsDir)
// should have 2 worker chunk
expect(files.length).toBe(13)
expect(files.length).toBe(12)
const index = files.find((f) => f.includes('main-module'))
const content = fs.readFileSync(path.resolve(assetsDir, index), 'utf-8')
const indexSourcemap = getSourceMapUrl(content)
Expand Down
Expand Up @@ -9,7 +9,7 @@ if (isBuild) {
test('sourcemap generation for web workers', async () => {
const files = fs.readdirSync(assetsDir)
// should have 2 worker chunk
expect(files.length).toBe(25)
expect(files.length).toBe(24)
const index = files.find((f) => f.includes('main-module'))
const content = fs.readFileSync(path.resolve(assetsDir, index), 'utf-8')
const indexSourcemap = getSourceMapUrl(content)
Expand Down
11 changes: 9 additions & 2 deletions packages/vite/src/node/plugins/html.ts
Expand Up @@ -391,8 +391,15 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
addToHTMLProxyCache(config, filePath, inlineModuleIndex, {
code: styleNode.content
})
js += `\nimport "${id}?html-proxy&index=${inlineModuleIndex}.css"`
shouldRemove = true
js += `\nimport "${id}?html-proxy&inline-css&index=${inlineModuleIndex}.css"`

// will transform in `applyHtmlTransforms`
s.overwrite(
styleNode.loc.start.offset,
styleNode.loc.end.offset,
`__VITE_INLINE_CSS__${cleanUrl(id)}_${inlineModuleIndex}__`,
{ contentOnly: true }
)
}

if (shouldRemove) {
Expand Down

0 comments on commit ba43c29

Please sign in to comment.