Skip to content

Commit 8208282

Browse files
committed
fix css
1 parent 8db8c13 commit 8208282

File tree

2 files changed

+105
-11
lines changed

2 files changed

+105
-11
lines changed

packages/core/src/plugins/EntryChunkPlugin.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ class EntryChunkPlugin {
111111
compilation.hooks.processAssets.tap(PLUGIN_NAME, (assets) => {
112112
if (!this.enabledImportMetaUrlShim) return;
113113

114-
const chunkAsset = Object.keys(assets);
114+
const chunkAsset = Object.keys(assets).filter((name) =>
115+
JS_EXTENSIONS_PATTERN.test(name),
116+
);
115117
for (const name of chunkAsset) {
116118
compilation.updateAsset(name, (old) => {
117119
const oldSource = old.source().toString();

tests/integration/style/css/index.test.ts

Lines changed: 102 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,132 @@ import { expect, test } from 'vitest';
44

55
test('should extract css successfully in bundle', async () => {
66
const fixturePath = join(__dirname, 'bundle');
7-
const { contents } = await buildAndGetResults({ fixturePath, type: 'css' });
8-
const esmFiles = Object.keys(contents.esm);
9-
expect(esmFiles).toMatchInlineSnapshot(`
7+
const { contents, files } = await buildAndGetResults({
8+
fixturePath,
9+
type: 'css',
10+
});
11+
12+
expect(files.esm).toMatchInlineSnapshot(`
1013
[
1114
"<ROOT>/tests/integration/style/css/bundle/dist/esm/static/css/index.css",
1215
]
1316
`);
1417

15-
const cjsFiles = Object.keys(contents.cjs);
16-
expect(cjsFiles).toMatchInlineSnapshot(`
18+
expect(contents.esm).toMatchInlineSnapshot(`
19+
{
20+
"<ROOT>/tests/integration/style/css/bundle/dist/esm/static/css/index.css": "@import url(https://cdnjs.cloudflare.com/ajax/libs/modern-normalize/1.1.0/modern-normalize.css);
21+
@import url(https://cdnjs.cloudflare.com/ajax/libs/modern-normalize/1.0.0/modern-normalize.css);
22+
.lib1 {
23+
color: red;
24+
}
25+
26+
.lib2 {
27+
color: green;
28+
}
29+
30+
.import {
31+
background-image: url("https://cdnjs.cloudflare.com/ajax/libs/modern-normalize/1.1.0/modern-normalize.css");
32+
}
33+
34+
",
35+
}
36+
`);
37+
38+
expect(files.cjs).toMatchInlineSnapshot(`
1739
[
1840
"<ROOT>/tests/integration/style/css/bundle/dist/cjs/static/css/index.css",
1941
]
2042
`);
43+
44+
expect(contents.cjs).toMatchInlineSnapshot(`
45+
{
46+
"<ROOT>/tests/integration/style/css/bundle/dist/cjs/static/css/index.css": "@import url(https://cdnjs.cloudflare.com/ajax/libs/modern-normalize/1.1.0/modern-normalize.css);
47+
@import url(https://cdnjs.cloudflare.com/ajax/libs/modern-normalize/1.0.0/modern-normalize.css);
48+
.lib1 {
49+
color: red;
50+
}
51+
52+
.lib2 {
53+
color: green;
54+
}
55+
56+
.import {
57+
background-image: url("https://cdnjs.cloudflare.com/ajax/libs/modern-normalize/1.1.0/modern-normalize.css");
58+
}
59+
60+
",
61+
}
62+
`);
2163
});
2264

2365
test('should extract css successfully in bundle-false', async () => {
2466
const fixturePath = join(__dirname, 'bundle-false');
25-
const { contents } = await buildAndGetResults({ fixturePath, type: 'css' });
26-
const esmFiles = Object.keys(contents.esm);
27-
expect(esmFiles).toMatchInlineSnapshot(`
67+
const { contents, files } = await buildAndGetResults({
68+
fixturePath,
69+
type: 'css',
70+
});
71+
72+
expect(files.esm).toMatchInlineSnapshot(`
2873
[
2974
"<ROOT>/tests/integration/style/css/bundle-false/dist/esm/import.css",
3075
"<ROOT>/tests/integration/style/css/bundle-false/dist/esm/lib1.css",
3176
"<ROOT>/tests/integration/style/css/bundle-false/dist/esm/lib2.css",
3277
]
3378
`);
79+
expect(contents.esm).toMatchInlineSnapshot(`
80+
{
81+
"<ROOT>/tests/integration/style/css/bundle-false/dist/esm/import.css": "@import "https://cdnjs.cloudflare.com/ajax/libs/modern-normalize/1.1.0/modern-normalize.css";
82+
@import "https://cdnjs.cloudflare.com/ajax/libs/modern-normalize/1.0.0/modern-normalize.css";
83+
@import "lib1.css";
84+
@import "lib2.css";
85+
86+
.import {
87+
background-image: url("https://cdnjs.cloudflare.com/ajax/libs/modern-normalize/1.1.0/modern-normalize.css");
88+
}
89+
90+
",
91+
"<ROOT>/tests/integration/style/css/bundle-false/dist/esm/lib1.css": ".lib1 {
92+
color: red;
93+
}
94+
95+
",
96+
"<ROOT>/tests/integration/style/css/bundle-false/dist/esm/lib2.css": ".lib2 {
97+
color: green;
98+
}
99+
100+
",
101+
}
102+
`);
34103

35-
const cjsFiles = Object.keys(contents.cjs);
36-
expect(cjsFiles).toMatchInlineSnapshot(`
104+
expect(files.cjs).toMatchInlineSnapshot(`
37105
[
38106
"<ROOT>/tests/integration/style/css/bundle-false/dist/cjs/import.css",
39107
"<ROOT>/tests/integration/style/css/bundle-false/dist/cjs/lib1.css",
40108
"<ROOT>/tests/integration/style/css/bundle-false/dist/cjs/lib2.css",
41109
]
42110
`);
111+
expect(contents.cjs).toMatchInlineSnapshot(`
112+
{
113+
"<ROOT>/tests/integration/style/css/bundle-false/dist/cjs/import.css": "@import "https://cdnjs.cloudflare.com/ajax/libs/modern-normalize/1.1.0/modern-normalize.css";
114+
@import "https://cdnjs.cloudflare.com/ajax/libs/modern-normalize/1.0.0/modern-normalize.css";
115+
@import "lib1.css";
116+
@import "lib2.css";
117+
118+
.import {
119+
background-image: url("https://cdnjs.cloudflare.com/ajax/libs/modern-normalize/1.1.0/modern-normalize.css");
120+
}
121+
122+
",
123+
"<ROOT>/tests/integration/style/css/bundle-false/dist/cjs/lib1.css": ".lib1 {
124+
color: red;
125+
}
126+
127+
",
128+
"<ROOT>/tests/integration/style/css/bundle-false/dist/cjs/lib2.css": ".lib2 {
129+
color: green;
130+
}
131+
132+
",
133+
}
134+
`);
43135
});

0 commit comments

Comments
 (0)