Skip to content

Commit

Permalink
fix: resolve @import of the proxied <style> (#7031)
Browse files Browse the repository at this point in the history
  • Loading branch information
ygj6 committed Feb 23, 2022
1 parent 8fd8f6e commit c7aad02
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/playground/assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,13 @@ <h3 class="import-css">@import</h3>
@import url('./css/import.css');
</style>

<h3 class="foo-public">
@import CSS from publicDir should load (this should be red)
</h3>
<style>
@import '/foo.css';
</style>

<script type="module">
import './css/fonts.css'
import './css/css-url.css'
Expand Down
3 changes: 3 additions & 0 deletions packages/playground/assets/static/foo.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.foo-public {
color: red;
}
5 changes: 5 additions & 0 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,9 +686,14 @@ async function compileCSS(
postcssConfig && postcssConfig.plugins ? postcssConfig.plugins.slice() : []

if (needInlineImport) {
const isHTMLProxy = htmlProxyRE.test(id)
postcssPlugins.unshift(
(await import('postcss-import')).default({
async resolve(id, basedir) {
const publicFile = checkPublicFile(id, config)
if (isHTMLProxy && publicFile) {
return publicFile
}
const resolved = await atImportResolvers.css(
id,
path.join(basedir, '*')
Expand Down

0 comments on commit c7aad02

Please sign in to comment.