Skip to content
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
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ playground/html/valid.html
playground/external/public/slash@3.0.0.js
playground/ssr-html/public/slash@3.0.0.js
playground/worker/classic-worker.js
playground/css/weapp.wxss
25 changes: 23 additions & 2 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2380,7 +2380,20 @@ const makeModernScssWorker = (
? fileURLToPath(context.containingUrl)
: options.filename
const resolved = await internalCanonicalize(url, importer)
return resolved ? pathToFileURL(resolved) : null
if (
resolved &&
// only limit to these extensions because:
// - for the `@import`/`@use`s written in file loaded by `load` function,
// the `canonicalize` function of that `importer` is called first
// - the `load` function of an importer is only called for the importer
// that returned a non-null result from its `canonicalize` function
(resolved.endsWith('.css') ||
resolved.endsWith('.scss') ||
resolved.endsWith('.sass'))
) {
return pathToFileURL(resolved)
}
return null
},
async load(canonicalUrl) {
const ext = path.extname(canonicalUrl.pathname)
Expand Down Expand Up @@ -2469,7 +2482,15 @@ const makeModernCompilerScssWorker = (
url,
cleanScssBugUrl(importer),
)
return resolved ? pathToFileURL(resolved) : null
if (
resolved &&
(resolved.endsWith('.css') ||
resolved.endsWith('.scss') ||
resolved.endsWith('.sass'))
) {
return pathToFileURL(resolved)
}
return null
},
async load(canonicalUrl) {
const ext = path.extname(canonicalUrl.pathname)
Expand Down
1 change: 1 addition & 0 deletions playground/css/nested/_index.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@use 'sass:string';
@use '/nested/root-relative'; // root relative path
@use '../weapp.wxss'; // test user's custom importer in a file loaded by vite's custom importer

@import './css-in-scss.css';

Expand Down
2 changes: 1 addition & 1 deletion playground/css/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default defineConfig({
importers: [
{
canonicalize(url) {
return url === 'virtual-dep'
return url === 'virtual-dep' || url.endsWith('.wxss')
? new URL('custom-importer:virtual-dep')
: null
},
Expand Down
1 change: 1 addition & 0 deletions playground/css/weapp.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is not css
Loading