vite/playground/css/main.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

129 lines
3.6 KiB
JavaScript
Raw Normal View History

import './minify.css'
import './imported.css'
import './sugarss.sss'
import './sass.scss'
import './less.less'
import './stylus.styl'
import './manual-chunk.css'
2024-01-12 09:07:22 +00:00
import urlCss from './url-imported.css?url'
appendLinkStylesheet(urlCss)
import rawCss from './raw-imported.css?raw'
text('.raw-imported-css', rawCss)
2020-12-22 20:34:02 +00:00
import mod from './mod.module.css'
document.querySelector('.modules').classList.add(mod['apply-color'])
2020-12-22 20:34:02 +00:00
text('.modules-code', JSON.stringify(mod, null, 2))
import sassMod from './mod.module.scss'
document.querySelector('.modules-sass').classList.add(sassMod['apply-color'])
2020-12-22 20:34:02 +00:00
text('.modules-sass-code', JSON.stringify(sassMod, null, 2))
import composesPathResolvingMod from './composes-path-resolving.module.css'
document
.querySelector('.path-resolved-modules-css')
.classList.add(...composesPathResolvingMod['path-resolving-css'].split(' '))
document
.querySelector('.path-resolved-modules-sass')
.classList.add(...composesPathResolvingMod['path-resolving-sass'].split(' '))
document
.querySelector('.path-resolved-modules-less')
.classList.add(...composesPathResolvingMod['path-resolving-less'].split(' '))
text(
'.path-resolved-modules-code',
JSON.stringify(composesPathResolvingMod, null, 2),
)
import inlineMod from './inline.module.css?inline'
text('.modules-inline', inlineMod)
import charset from './charset.css?inline'
2022-04-11 18:13:37 +00:00
text('.charset-css', charset)
import './layered/index.css'
import './dep.css'
import './glob-dep.css'
2024-01-11 13:21:58 +00:00
// eslint-disable-next-line i/order
2022-07-01 03:17:19 +00:00
import { barModuleClasses } from '@vitejs/test-css-js-dep'
document
.querySelector('.css-js-dep-module')
.classList.add(barModuleClasses.cssJsDepModule)
2020-12-22 20:34:02 +00:00
function text(el, text) {
document.querySelector(el).textContent = text
}
2024-01-12 09:07:22 +00:00
function appendLinkStylesheet(href) {
const link = document.createElement('link')
link.rel = 'stylesheet'
link.href = href
document.head.appendChild(link)
}
2020-12-22 20:34:02 +00:00
if (import.meta.hot) {
import.meta.hot.accept('./mod.module.css', (newMod) => {
const list = document.querySelector('.modules').classList
list.remove(mod.applyColor)
list.add(newMod.applyColor)
text('.modules-code', JSON.stringify(newMod.default, null, 2))
})
import.meta.hot.accept('./mod.module.scss', (newMod) => {
const list = document.querySelector('.modules-sass').classList
list.remove(mod.applyColor)
list.add(newMod.applyColor)
text('.modules-sass-code', JSON.stringify(newMod.default, null, 2))
})
}
2020-12-30 23:47:35 +00:00
// async
import('./async')
if (import.meta.env.DEV) {
import('./async-treeshaken')
}
// inlined
import inlined from './inlined.css?inline'
text('.inlined-code', inlined)
// glob
const glob = import.meta.glob('./glob-import/*.css', { query: '?inline' })
Promise.all(
Object.keys(glob).map((key) => glob[key]().then((i) => i.default)),
).then((res) => {
text('.imported-css-glob', JSON.stringify(res, null, 2))
})
// globEager
const globEager = import.meta.glob('./glob-import/*.css', {
eager: true,
query: '?inline',
})
text('.imported-css-globEager', JSON.stringify(globEager, null, 2))
2023-08-16 11:54:32 +00:00
import postcssSourceInput from './postcss-source-input.css?inline&query=foo'
text('.postcss-source-input', postcssSourceInput)
2022-07-01 03:08:47 +00:00
// The file is jsfile.css.js, and we should be able to import it without extension
import jsFileMessage from './jsfile.css'
text('.jsfile-css-js', jsFileMessage)
import '#alias'
import aliasContent from '#alias?inline'
2022-07-01 03:08:47 +00:00
text('.aliased-content', aliasContent)
import aliasModule from '#alias-module'
document
.querySelector('.aliased-module')
.classList.add(aliasModule.aliasedModule)
import './unsupported.css'
import './async/index'
import('./same-name/sub1/sub')
import('./same-name/sub2/sub')