mirror of
https://github.com/vitejs/vite.git
synced 2024-11-21 14:48:41 +00:00
feat(css): support resolving stylesheets from exports map (#7817)
Co-authored-by: bluwy <bjornlu.dev@gmail.com>
This commit is contained in:
parent
ce18eba39f
commit
108aadf728
@ -731,6 +731,7 @@ function createCSSResolvers(config: ResolvedConfig): CSSAtImportResolvers {
|
||||
(cssResolve = config.createResolver({
|
||||
extensions: ['.css'],
|
||||
mainFields: ['style'],
|
||||
conditions: ['style'],
|
||||
tryIndex: false,
|
||||
preferRelative: true,
|
||||
}))
|
||||
@ -743,6 +744,7 @@ function createCSSResolvers(config: ResolvedConfig): CSSAtImportResolvers {
|
||||
(sassResolve = config.createResolver({
|
||||
extensions: ['.scss', '.sass', '.css'],
|
||||
mainFields: ['sass', 'style'],
|
||||
conditions: ['sass', 'style'],
|
||||
tryIndex: true,
|
||||
tryPrefix: '_',
|
||||
preferRelative: true,
|
||||
@ -756,6 +758,7 @@ function createCSSResolvers(config: ResolvedConfig): CSSAtImportResolvers {
|
||||
(lessResolve = config.createResolver({
|
||||
extensions: ['.less', '.css'],
|
||||
mainFields: ['less', 'style'],
|
||||
conditions: ['less', 'style'],
|
||||
tryIndex: false,
|
||||
preferRelative: true,
|
||||
}))
|
||||
|
@ -289,6 +289,14 @@ test('@import dependency w/ sass entry', async () => {
|
||||
expect(await getColor('.css-dep-sass')).toBe('orange')
|
||||
})
|
||||
|
||||
test('@import dependency w/ style export mapping', async () => {
|
||||
expect(await getColor('.css-dep-exports')).toBe('purple')
|
||||
})
|
||||
|
||||
test('@import dependency w/ sass export mapping', async () => {
|
||||
expect(await getColor('.css-dep-exports-sass')).toBe('orange')
|
||||
})
|
||||
|
||||
test('@import dependency w/out package scss', async () => {
|
||||
expect(await getColor('.sass-dep')).toBe('lavender')
|
||||
})
|
||||
|
1
playground/css/css-dep-exports/index.js
Normal file
1
playground/css/css-dep-exports/index.js
Normal file
@ -0,0 +1 @@
|
||||
throw new Error('should not be imported')
|
12
playground/css/css-dep-exports/package.json
Normal file
12
playground/css/css-dep-exports/package.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "@vitejs/test-css-dep-exports",
|
||||
"private": true,
|
||||
"version": "1.0.0",
|
||||
"exports": {
|
||||
".": {
|
||||
"sass": "./style.scss",
|
||||
"style": "./style.css",
|
||||
"import": "./index.js"
|
||||
}
|
||||
}
|
||||
}
|
3
playground/css/css-dep-exports/style.css
Normal file
3
playground/css/css-dep-exports/style.css
Normal file
@ -0,0 +1,3 @@
|
||||
.css-dep-exports {
|
||||
color: purple;
|
||||
}
|
3
playground/css/css-dep-exports/style.scss
Normal file
3
playground/css/css-dep-exports/style.scss
Normal file
@ -0,0 +1,3 @@
|
||||
.css-dep-exports-sass {
|
||||
color: orange;
|
||||
}
|
@ -1 +1,2 @@
|
||||
@import '@vitejs/test-css-dep';
|
||||
@import '@vitejs/test-css-dep-exports';
|
||||
|
@ -133,6 +133,13 @@
|
||||
@import dependency w/ sass entrypoints: this should be orange
|
||||
</p>
|
||||
|
||||
<p class="css-dep-exports">
|
||||
@import dependency w/ style export mapping: this should be purple
|
||||
</p>
|
||||
<p class="css-dep-exports-sass">
|
||||
@import dependency w/ sass export mapping: this should be orange
|
||||
</p>
|
||||
|
||||
<p class="dir-dep">PostCSS dir-dependency: this should be grey</p>
|
||||
<p class="dir-dep-2">
|
||||
PostCSS dir-dependency (file 2): this should be grey too
|
||||
|
@ -13,6 +13,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/test-css-dep": "link:./css-dep",
|
||||
"@vitejs/test-css-dep-exports": "link:./css-dep-exports",
|
||||
"@vitejs/test-css-js-dep": "file:./css-js-dep",
|
||||
"fast-glob": "^3.2.12",
|
||||
"less": "^4.1.3",
|
||||
|
@ -1,6 +1,7 @@
|
||||
@import '=/nested'; // alias + custom index resolving -> /nested/_index.scss
|
||||
@import '=/nested/partial'; // sass convention: omitting leading _ for partials
|
||||
@import '@vitejs/test-css-dep'; // package w/ sass entry points
|
||||
@import '@vitejs/test-css-dep-exports'; // package with a sass export mapping
|
||||
@import 'virtual-dep'; // virtual file added through importer
|
||||
@import '=/pkg-dep'; // package w/out sass field
|
||||
@import '=/weapp.wxss'; // wxss file
|
||||
|
@ -370,6 +370,7 @@ importers:
|
||||
playground/css:
|
||||
specifiers:
|
||||
'@vitejs/test-css-dep': link:./css-dep
|
||||
'@vitejs/test-css-dep-exports': link:./css-dep-exports
|
||||
'@vitejs/test-css-js-dep': file:./css-js-dep
|
||||
fast-glob: ^3.2.12
|
||||
less: ^4.1.3
|
||||
@ -379,6 +380,7 @@ importers:
|
||||
sugarss: ^4.0.1
|
||||
devDependencies:
|
||||
'@vitejs/test-css-dep': link:css-dep
|
||||
'@vitejs/test-css-dep-exports': link:css-dep-exports
|
||||
'@vitejs/test-css-js-dep': file:playground/css/css-js-dep
|
||||
fast-glob: 3.2.12
|
||||
less: 4.1.3
|
||||
@ -413,6 +415,9 @@ importers:
|
||||
playground/css/css-dep:
|
||||
specifiers: {}
|
||||
|
||||
playground/css/css-dep-exports:
|
||||
specifiers: {}
|
||||
|
||||
playground/css/css-js-dep:
|
||||
specifiers: {}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user