diff --git a/packages/playground/css/__tests__/css.spec.ts b/packages/playground/css/__tests__/css.spec.ts index f1eb66e097ad86..fe49dec9118eb0 100644 --- a/packages/playground/css/__tests__/css.spec.ts +++ b/packages/playground/css/__tests__/css.spec.ts @@ -356,3 +356,19 @@ test('minify css', async () => { expect(cssFile).toMatch('rgba(') expect(cssFile).not.toMatch('#ffff00b3') }) + + +test('?raw', async () => {; + expect(await page.textContent('.raw-imported-css')).toBe( + require('fs').readFileSync(require.resolve('../imported.css'), 'utf-8') + ) + expect(await page.textContent('.raw-imported-sass')).toBe( + require('fs').readFileSync(require.resolve('../sass.scss'), 'utf-8') + ) + expect(await page.textContent('.raw-imported-less')).toBe( + require('fs').readFileSync(require.resolve('../less.less'), 'utf-8') + ) + expect(await page.textContent('.raw-imported-stylus')).toBe( + require('fs').readFileSync(require.resolve('../stylus.styl'), 'utf-8') + ) +}); diff --git a/packages/playground/css/index.html b/packages/playground/css/index.html index 7a79bb1629f989..f52d6da572c44d 100644 --- a/packages/playground/css/index.html +++ b/packages/playground/css/index.html @@ -104,6 +104,12 @@

CSS

Inlined import - this should NOT be red.


+
+  

Raw Support

+

+  

+  

+  

 
 
 
diff --git a/packages/playground/css/main.js b/packages/playground/css/main.js
index 24a278c8687940..ababa5a85ce4e7 100644
--- a/packages/playground/css/main.js
+++ b/packages/playground/css/main.js
@@ -12,6 +12,18 @@ text('.imported-less', less)
 import stylus from './stylus.styl'
 text('.imported-stylus', stylus)
 
+import rawCss from './imported.css?raw'
+text('.raw-imported-css', rawCss)
+
+import rawSass from './sass.scss?raw'
+text('.raw-imported-sass', rawSass)
+
+import rawLess from './less.less?raw'
+text('.raw-imported-less', rawLess)
+
+import rawStylus from './stylus.styl?raw'
+text('.raw-imported-stylus', rawStylus)
+
 import mod from './mod.module.css'
 document.querySelector('.modules').classList.add(mod['apply-color'])
 text('.modules-code', JSON.stringify(mod, null, 2))
diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts
index a7cd3fd6cc11fa..e1fd30329ed007 100644
--- a/packages/vite/src/node/plugins/css.ts
+++ b/packages/vite/src/node/plugins/css.ts
@@ -24,7 +24,7 @@ import {
 } from 'rollup'
 import { dataToEsm } from '@rollup/pluginutils'
 import chalk from 'chalk'
-import { CLIENT_PUBLIC_PATH } from '../constants'
+import { CLIENT_PUBLIC_PATH, SPECIAL_QUERY_RE } from '../constants'
 import { ResolveFn, ViteDevServer } from '../'
 import {
   getAssetFilename,
@@ -161,7 +161,7 @@ export function cssPlugin(config: ResolvedConfig): Plugin {
     },
 
     async transform(raw, id) {
-      if (!isCSSRequest(id) || commonjsProxyRE.test(id)) {
+      if (!isCSSRequest(id) || commonjsProxyRE.test(id) || SPECIAL_QUERY_RE.test(id)) {
         return
       }