@vanilla-extract/vite-plugin
Advanced tools
Comparing version 0.0.0-vite-plugin-new-20231220084042 to 0.0.0-vite-plugin-new-20231226032342
@@ -6,3 +6,2 @@ 'use strict'; | ||
var path = require('path'); | ||
var assert = require('assert'); | ||
var integration = require('@vanilla-extract/integration'); | ||
@@ -12,57 +11,4 @@ | ||
function _interopNamespace(e) { | ||
if (e && e.__esModule) return e; | ||
var n = Object.create(null); | ||
if (e) { | ||
Object.keys(e).forEach(function (k) { | ||
if (k !== 'default') { | ||
var d = Object.getOwnPropertyDescriptor(e, k); | ||
Object.defineProperty(n, k, d.get ? d : { | ||
enumerable: true, | ||
get: function () { return e[k]; } | ||
}); | ||
} | ||
}); | ||
} | ||
n["default"] = e; | ||
return Object.freeze(n); | ||
} | ||
var path__default = /*#__PURE__*/_interopDefault(path); | ||
var assert__default = /*#__PURE__*/_interopDefault(assert); | ||
// Mostly copied from vite's implementation | ||
// https://github.com/vitejs/vite/blob/efec70f816b80e55b64255b32a5f120e1cf4e4be/packages/vite/src/node/plugins/css.ts | ||
const resolvePostcssConfig = async config => { | ||
var _config$css; | ||
// inline postcss config via vite config | ||
const inlineOptions = (_config$css = config.css) === null || _config$css === void 0 ? void 0 : _config$css.postcss; | ||
const inlineOptionsIsString = typeof inlineOptions === 'string'; | ||
if (inlineOptions && !inlineOptionsIsString) { | ||
const options = { | ||
...inlineOptions | ||
}; | ||
delete options.plugins; | ||
return { | ||
options, | ||
// @ts-expect-error TODO: incompatible types? | ||
plugins: inlineOptions.plugins || [] | ||
}; | ||
} else { | ||
try { | ||
const searchPath = typeof inlineOptions === 'string' ? inlineOptions : config.root; | ||
const postCssConfig = await (await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('postcss-load-config')); })).default({}, searchPath); | ||
return { | ||
options: postCssConfig.options, | ||
plugins: postCssConfig.plugins | ||
}; | ||
} catch (e) { | ||
if (!/No PostCSS Config found/.test(e.message)) { | ||
throw e; | ||
} | ||
return null; | ||
} | ||
} | ||
}; | ||
const virtualExtCss = '.vanilla.css'; | ||
@@ -76,9 +22,19 @@ function vanillaExtractPlugin({ | ||
let server; | ||
let postCssConfig; | ||
let packageName; | ||
let compiler; | ||
const cssMap = new Map(); | ||
const getAbsoluteFileId = source => integration.normalizePath(path__default["default"].resolve(config.root, source)); | ||
const cssImportSpecifier = filePath => `${filePath}${virtualExtCss}`; | ||
const invalidateModule = absoluteId => { | ||
const getAbsoluteFileId = filePath => { | ||
let resolvedId = filePath; | ||
if (filePath.startsWith(config.root) || path__default["default"].isAbsolute(filePath) && filePath.includes('node_modules')) { | ||
resolvedId = filePath; | ||
} else { | ||
// in SSR mode we can have paths like /app/styles.css.ts | ||
resolvedId = path__default["default"].join(config.root, filePath); | ||
} | ||
return integration.normalizePath(resolvedId); | ||
}; | ||
const fileIdToVirtualId = id => `${id}${virtualExtCss}`; | ||
const virtualIdToFileId = virtualId => virtualId.replace(virtualExtCss, ''); | ||
function invalidateModule(absoluteId) { | ||
if (!server) return; | ||
const { | ||
@@ -94,15 +50,5 @@ moduleGraph | ||
} | ||
}; | ||
const processCss = async css => { | ||
assert__default["default"](postCssConfig); | ||
const postCssResult = await (await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('postcss')); })).default(postCssConfig.plugins).process(css, { | ||
...postCssConfig.options, | ||
from: undefined, | ||
map: false | ||
}); | ||
return postCssResult.css; | ||
}; | ||
} | ||
return { | ||
name: 'vanilla-extract', | ||
enforce: 'pre', | ||
configureServer(_server) { | ||
@@ -121,14 +67,9 @@ server = _server; | ||
packageName = integration.getPackageInfo(config.root).name; | ||
if (config.command === 'serve') { | ||
postCssConfig = await resolvePostcssConfig(config); | ||
} | ||
if (emitCssInSsr === 'compiler') { | ||
var _config$inlineConfig$; | ||
compiler = integration.createCompiler({ | ||
debug: true, | ||
root: config.root, | ||
identifiers: identifiers !== null && identifiers !== void 0 ? identifiers : config.mode === 'production' ? 'short' : 'debug', | ||
cssImportSpecifier, | ||
vitePlugins: ((_config$inlineConfig$ = config.inlineConfig.plugins) !== null && _config$inlineConfig$ !== void 0 ? _config$inlineConfig$ : []).flat() | ||
// Prevent an infinite loop where the child compiler creates a new child compiler | ||
identifiers: identifiers ?? (config.mode === 'production' ? 'short' : 'debug'), | ||
cssImportSpecifier: fileIdToVirtualId, | ||
vitePlugins: config.inlineConfig.plugins?.flat() | ||
// Prevent an infinite loop where the compiler creates a new instance of the plugin, which creates a new compiler etc. | ||
.filter(plugin => typeof plugin === 'object' && plugin !== null && 'name' in plugin && plugin.name !== 'vanilla-extract') | ||
@@ -140,9 +81,7 @@ }); | ||
const [validId, query] = source.split('?'); | ||
if (!validId.endsWith(virtualExtCss)) { | ||
return; | ||
} | ||
if (!validId.endsWith(virtualExtCss)) return; | ||
// Absolute paths seem to occur often in monorepos, where files are | ||
// imported from outside the config root. | ||
const absoluteId = source.startsWith(config.root) ? source : getAbsoluteFileId(validId); | ||
const absoluteId = getAbsoluteFileId(validId); | ||
@@ -152,3 +91,3 @@ // There should always be an entry in the `cssMap` here. | ||
// a file in their app using the .vanilla.js/.vanilla.css extension | ||
if (cssMap.has(absoluteId)) { | ||
if (compiler?.getCssForFile(virtualIdToFileId(absoluteId)) || cssMap.has(absoluteId)) { | ||
// Keep the original query string for HMR. | ||
@@ -160,6 +99,12 @@ return absoluteId + (query ? `?${query}` : ''); | ||
const [validId] = id.split('?'); | ||
if (!validId.endsWith(virtualExtCss)) return; | ||
if (compiler) { | ||
const absoluteId = getAbsoluteFileId(validId); | ||
let { | ||
css: _css | ||
} = compiler.getCssForFile(virtualIdToFileId(absoluteId)) ?? {}; | ||
return _css; | ||
} | ||
const css = cssMap.get(validId); | ||
if (typeof css === 'string' && validId.endsWith(virtualExtCss)) { | ||
return css; | ||
} | ||
return css; | ||
}, | ||
@@ -171,30 +116,24 @@ async transform(code, id) { | ||
} | ||
const identOption = identifiers !== null && identifiers !== void 0 ? identifiers : config.mode === 'production' ? 'short' : 'debug'; | ||
if (compiler) { | ||
const absoluteVirtualId = cssImportSpecifier(validId); | ||
const absoluteId = getAbsoluteFileId(validId); | ||
console.time(`[compiler] ${validId}`); | ||
const { | ||
source, | ||
watchFiles | ||
} = await compiler.processVanillaFile(validId); | ||
let { | ||
css | ||
} = compiler.getCssForFile(validId); | ||
source: _source, | ||
watchFiles: _watchFiles | ||
} = await compiler.processVanillaFile(absoluteId, { | ||
outputCss: true | ||
}); | ||
console.timeEnd(`[compiler] ${validId}`); | ||
if (postCssConfig) { | ||
css = await processCss(css); | ||
} | ||
for (const file of watchFiles) { | ||
for (const file of _watchFiles) { | ||
// In start mode, we need to prevent the file from rewatching itself. | ||
// If it's a `build --watch`, it needs to watch everything. | ||
if (config.command === 'build' || integration.normalizePath(file) !== validId) { | ||
if (config.command === 'build' || integration.normalizePath(file) !== absoluteId) { | ||
this.addWatchFile(file); | ||
} | ||
} | ||
if (cssMap.has(absoluteVirtualId) && cssMap.get(absoluteVirtualId) !== css) { | ||
invalidateModule(absoluteVirtualId); | ||
} | ||
cssMap.set(absoluteVirtualId, css); | ||
// We have to invalidate the virtual module, not the real one we just transformed | ||
invalidateModule(fileIdToVirtualId(validId)); | ||
return { | ||
code: source, | ||
code: _source, | ||
map: { | ||
@@ -205,2 +144,3 @@ mappings: '' | ||
} | ||
const identOption = identifiers ?? (config.mode === 'production' ? 'short' : 'debug'); | ||
if (!emitCssInSsr) { | ||
@@ -235,10 +175,6 @@ return integration.transform({ | ||
const absoluteId = getAbsoluteFileId(rootRelativeId); | ||
let cssSource = source; | ||
if (postCssConfig) { | ||
cssSource = await processCss(cssSource); | ||
} | ||
if (cssMap.has(absoluteId) && cssMap.get(absoluteId) !== cssSource) { | ||
if (cssMap.has(absoluteId) && cssMap.get(absoluteId) !== source) { | ||
invalidateModule(absoluteId); | ||
} | ||
cssMap.set(absoluteId, cssSource); | ||
cssMap.set(absoluteId, source); | ||
@@ -264,2 +200,5 @@ // We use the root relative id here to ensure file contents (content-hashes) | ||
}; | ||
}, | ||
buildEnd() { | ||
compiler?.close(); | ||
} | ||
@@ -266,0 +205,0 @@ }; |
@@ -6,3 +6,2 @@ 'use strict'; | ||
var path = require('path'); | ||
var assert = require('assert'); | ||
var integration = require('@vanilla-extract/integration'); | ||
@@ -12,57 +11,4 @@ | ||
function _interopNamespace(e) { | ||
if (e && e.__esModule) return e; | ||
var n = Object.create(null); | ||
if (e) { | ||
Object.keys(e).forEach(function (k) { | ||
if (k !== 'default') { | ||
var d = Object.getOwnPropertyDescriptor(e, k); | ||
Object.defineProperty(n, k, d.get ? d : { | ||
enumerable: true, | ||
get: function () { return e[k]; } | ||
}); | ||
} | ||
}); | ||
} | ||
n["default"] = e; | ||
return Object.freeze(n); | ||
} | ||
var path__default = /*#__PURE__*/_interopDefault(path); | ||
var assert__default = /*#__PURE__*/_interopDefault(assert); | ||
// Mostly copied from vite's implementation | ||
// https://github.com/vitejs/vite/blob/efec70f816b80e55b64255b32a5f120e1cf4e4be/packages/vite/src/node/plugins/css.ts | ||
const resolvePostcssConfig = async config => { | ||
var _config$css; | ||
// inline postcss config via vite config | ||
const inlineOptions = (_config$css = config.css) === null || _config$css === void 0 ? void 0 : _config$css.postcss; | ||
const inlineOptionsIsString = typeof inlineOptions === 'string'; | ||
if (inlineOptions && !inlineOptionsIsString) { | ||
const options = { | ||
...inlineOptions | ||
}; | ||
delete options.plugins; | ||
return { | ||
options, | ||
// @ts-expect-error TODO: incompatible types? | ||
plugins: inlineOptions.plugins || [] | ||
}; | ||
} else { | ||
try { | ||
const searchPath = typeof inlineOptions === 'string' ? inlineOptions : config.root; | ||
const postCssConfig = await (await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('postcss-load-config')); })).default({}, searchPath); | ||
return { | ||
options: postCssConfig.options, | ||
plugins: postCssConfig.plugins | ||
}; | ||
} catch (e) { | ||
if (!/No PostCSS Config found/.test(e.message)) { | ||
throw e; | ||
} | ||
return null; | ||
} | ||
} | ||
}; | ||
const virtualExtCss = '.vanilla.css'; | ||
@@ -76,9 +22,19 @@ function vanillaExtractPlugin({ | ||
let server; | ||
let postCssConfig; | ||
let packageName; | ||
let compiler; | ||
const cssMap = new Map(); | ||
const getAbsoluteFileId = source => integration.normalizePath(path__default["default"].resolve(config.root, source)); | ||
const cssImportSpecifier = filePath => `${filePath}${virtualExtCss}`; | ||
const invalidateModule = absoluteId => { | ||
const getAbsoluteFileId = filePath => { | ||
let resolvedId = filePath; | ||
if (filePath.startsWith(config.root) || path__default["default"].isAbsolute(filePath) && filePath.includes('node_modules')) { | ||
resolvedId = filePath; | ||
} else { | ||
// in SSR mode we can have paths like /app/styles.css.ts | ||
resolvedId = path__default["default"].join(config.root, filePath); | ||
} | ||
return integration.normalizePath(resolvedId); | ||
}; | ||
const fileIdToVirtualId = id => `${id}${virtualExtCss}`; | ||
const virtualIdToFileId = virtualId => virtualId.replace(virtualExtCss, ''); | ||
function invalidateModule(absoluteId) { | ||
if (!server) return; | ||
const { | ||
@@ -94,15 +50,5 @@ moduleGraph | ||
} | ||
}; | ||
const processCss = async css => { | ||
assert__default["default"](postCssConfig); | ||
const postCssResult = await (await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('postcss')); })).default(postCssConfig.plugins).process(css, { | ||
...postCssConfig.options, | ||
from: undefined, | ||
map: false | ||
}); | ||
return postCssResult.css; | ||
}; | ||
} | ||
return { | ||
name: 'vanilla-extract', | ||
enforce: 'pre', | ||
configureServer(_server) { | ||
@@ -121,14 +67,9 @@ server = _server; | ||
packageName = integration.getPackageInfo(config.root).name; | ||
if (config.command === 'serve') { | ||
postCssConfig = await resolvePostcssConfig(config); | ||
} | ||
if (emitCssInSsr === 'compiler') { | ||
var _config$inlineConfig$; | ||
compiler = integration.createCompiler({ | ||
debug: true, | ||
root: config.root, | ||
identifiers: identifiers !== null && identifiers !== void 0 ? identifiers : config.mode === 'production' ? 'short' : 'debug', | ||
cssImportSpecifier, | ||
vitePlugins: ((_config$inlineConfig$ = config.inlineConfig.plugins) !== null && _config$inlineConfig$ !== void 0 ? _config$inlineConfig$ : []).flat() | ||
// Prevent an infinite loop where the child compiler creates a new child compiler | ||
identifiers: identifiers ?? (config.mode === 'production' ? 'short' : 'debug'), | ||
cssImportSpecifier: fileIdToVirtualId, | ||
vitePlugins: config.inlineConfig.plugins?.flat() | ||
// Prevent an infinite loop where the compiler creates a new instance of the plugin, which creates a new compiler etc. | ||
.filter(plugin => typeof plugin === 'object' && plugin !== null && 'name' in plugin && plugin.name !== 'vanilla-extract') | ||
@@ -140,9 +81,7 @@ }); | ||
const [validId, query] = source.split('?'); | ||
if (!validId.endsWith(virtualExtCss)) { | ||
return; | ||
} | ||
if (!validId.endsWith(virtualExtCss)) return; | ||
// Absolute paths seem to occur often in monorepos, where files are | ||
// imported from outside the config root. | ||
const absoluteId = source.startsWith(config.root) ? source : getAbsoluteFileId(validId); | ||
const absoluteId = getAbsoluteFileId(validId); | ||
@@ -152,3 +91,3 @@ // There should always be an entry in the `cssMap` here. | ||
// a file in their app using the .vanilla.js/.vanilla.css extension | ||
if (cssMap.has(absoluteId)) { | ||
if (compiler?.getCssForFile(virtualIdToFileId(absoluteId)) || cssMap.has(absoluteId)) { | ||
// Keep the original query string for HMR. | ||
@@ -160,6 +99,12 @@ return absoluteId + (query ? `?${query}` : ''); | ||
const [validId] = id.split('?'); | ||
if (!validId.endsWith(virtualExtCss)) return; | ||
if (compiler) { | ||
const absoluteId = getAbsoluteFileId(validId); | ||
let { | ||
css: _css | ||
} = compiler.getCssForFile(virtualIdToFileId(absoluteId)) ?? {}; | ||
return _css; | ||
} | ||
const css = cssMap.get(validId); | ||
if (typeof css === 'string' && validId.endsWith(virtualExtCss)) { | ||
return css; | ||
} | ||
return css; | ||
}, | ||
@@ -171,30 +116,24 @@ async transform(code, id) { | ||
} | ||
const identOption = identifiers !== null && identifiers !== void 0 ? identifiers : config.mode === 'production' ? 'short' : 'debug'; | ||
if (compiler) { | ||
const absoluteVirtualId = cssImportSpecifier(validId); | ||
const absoluteId = getAbsoluteFileId(validId); | ||
console.time(`[compiler] ${validId}`); | ||
const { | ||
source, | ||
watchFiles | ||
} = await compiler.processVanillaFile(validId); | ||
let { | ||
css | ||
} = compiler.getCssForFile(validId); | ||
source: _source, | ||
watchFiles: _watchFiles | ||
} = await compiler.processVanillaFile(absoluteId, { | ||
outputCss: true | ||
}); | ||
console.timeEnd(`[compiler] ${validId}`); | ||
if (postCssConfig) { | ||
css = await processCss(css); | ||
} | ||
for (const file of watchFiles) { | ||
for (const file of _watchFiles) { | ||
// In start mode, we need to prevent the file from rewatching itself. | ||
// If it's a `build --watch`, it needs to watch everything. | ||
if (config.command === 'build' || integration.normalizePath(file) !== validId) { | ||
if (config.command === 'build' || integration.normalizePath(file) !== absoluteId) { | ||
this.addWatchFile(file); | ||
} | ||
} | ||
if (cssMap.has(absoluteVirtualId) && cssMap.get(absoluteVirtualId) !== css) { | ||
invalidateModule(absoluteVirtualId); | ||
} | ||
cssMap.set(absoluteVirtualId, css); | ||
// We have to invalidate the virtual module, not the real one we just transformed | ||
invalidateModule(fileIdToVirtualId(validId)); | ||
return { | ||
code: source, | ||
code: _source, | ||
map: { | ||
@@ -205,2 +144,3 @@ mappings: '' | ||
} | ||
const identOption = identifiers ?? (config.mode === 'production' ? 'short' : 'debug'); | ||
if (!emitCssInSsr) { | ||
@@ -235,10 +175,6 @@ return integration.transform({ | ||
const absoluteId = getAbsoluteFileId(rootRelativeId); | ||
let cssSource = source; | ||
if (postCssConfig) { | ||
cssSource = await processCss(cssSource); | ||
} | ||
if (cssMap.has(absoluteId) && cssMap.get(absoluteId) !== cssSource) { | ||
if (cssMap.has(absoluteId) && cssMap.get(absoluteId) !== source) { | ||
invalidateModule(absoluteId); | ||
} | ||
cssMap.set(absoluteId, cssSource); | ||
cssMap.set(absoluteId, source); | ||
@@ -264,2 +200,5 @@ // We use the root relative id here to ensure file contents (content-hashes) | ||
}; | ||
}, | ||
buildEnd() { | ||
compiler?.close(); | ||
} | ||
@@ -266,0 +205,0 @@ }; |
import path from 'path'; | ||
import assert from 'assert'; | ||
import { getPackageInfo, createCompiler, cssFileFilter, normalizePath, transform, compile, processVanillaFile } from '@vanilla-extract/integration'; | ||
// Mostly copied from vite's implementation | ||
// https://github.com/vitejs/vite/blob/efec70f816b80e55b64255b32a5f120e1cf4e4be/packages/vite/src/node/plugins/css.ts | ||
const resolvePostcssConfig = async config => { | ||
var _config$css; | ||
// inline postcss config via vite config | ||
const inlineOptions = (_config$css = config.css) === null || _config$css === void 0 ? void 0 : _config$css.postcss; | ||
const inlineOptionsIsString = typeof inlineOptions === 'string'; | ||
if (inlineOptions && !inlineOptionsIsString) { | ||
const options = { | ||
...inlineOptions | ||
}; | ||
delete options.plugins; | ||
return { | ||
options, | ||
// @ts-expect-error TODO: incompatible types? | ||
plugins: inlineOptions.plugins || [] | ||
}; | ||
} else { | ||
try { | ||
const searchPath = typeof inlineOptions === 'string' ? inlineOptions : config.root; | ||
const postCssConfig = await (await import('postcss-load-config')).default({}, searchPath); | ||
return { | ||
options: postCssConfig.options, | ||
plugins: postCssConfig.plugins | ||
}; | ||
} catch (e) { | ||
if (!/No PostCSS Config found/.test(e.message)) { | ||
throw e; | ||
} | ||
return null; | ||
} | ||
} | ||
}; | ||
const virtualExtCss = '.vanilla.css'; | ||
@@ -47,9 +12,19 @@ function vanillaExtractPlugin({ | ||
let server; | ||
let postCssConfig; | ||
let packageName; | ||
let compiler; | ||
const cssMap = new Map(); | ||
const getAbsoluteFileId = source => normalizePath(path.resolve(config.root, source)); | ||
const cssImportSpecifier = filePath => `${filePath}${virtualExtCss}`; | ||
const invalidateModule = absoluteId => { | ||
const getAbsoluteFileId = filePath => { | ||
let resolvedId = filePath; | ||
if (filePath.startsWith(config.root) || path.isAbsolute(filePath) && filePath.includes('node_modules')) { | ||
resolvedId = filePath; | ||
} else { | ||
// in SSR mode we can have paths like /app/styles.css.ts | ||
resolvedId = path.join(config.root, filePath); | ||
} | ||
return normalizePath(resolvedId); | ||
}; | ||
const fileIdToVirtualId = id => `${id}${virtualExtCss}`; | ||
const virtualIdToFileId = virtualId => virtualId.replace(virtualExtCss, ''); | ||
function invalidateModule(absoluteId) { | ||
if (!server) return; | ||
const { | ||
@@ -65,15 +40,5 @@ moduleGraph | ||
} | ||
}; | ||
const processCss = async css => { | ||
assert(postCssConfig); | ||
const postCssResult = await (await import('postcss')).default(postCssConfig.plugins).process(css, { | ||
...postCssConfig.options, | ||
from: undefined, | ||
map: false | ||
}); | ||
return postCssResult.css; | ||
}; | ||
} | ||
return { | ||
name: 'vanilla-extract', | ||
enforce: 'pre', | ||
configureServer(_server) { | ||
@@ -92,14 +57,9 @@ server = _server; | ||
packageName = getPackageInfo(config.root).name; | ||
if (config.command === 'serve') { | ||
postCssConfig = await resolvePostcssConfig(config); | ||
} | ||
if (emitCssInSsr === 'compiler') { | ||
var _config$inlineConfig$; | ||
compiler = createCompiler({ | ||
debug: true, | ||
root: config.root, | ||
identifiers: identifiers !== null && identifiers !== void 0 ? identifiers : config.mode === 'production' ? 'short' : 'debug', | ||
cssImportSpecifier, | ||
vitePlugins: ((_config$inlineConfig$ = config.inlineConfig.plugins) !== null && _config$inlineConfig$ !== void 0 ? _config$inlineConfig$ : []).flat() | ||
// Prevent an infinite loop where the child compiler creates a new child compiler | ||
identifiers: identifiers ?? (config.mode === 'production' ? 'short' : 'debug'), | ||
cssImportSpecifier: fileIdToVirtualId, | ||
vitePlugins: config.inlineConfig.plugins?.flat() | ||
// Prevent an infinite loop where the compiler creates a new instance of the plugin, which creates a new compiler etc. | ||
.filter(plugin => typeof plugin === 'object' && plugin !== null && 'name' in plugin && plugin.name !== 'vanilla-extract') | ||
@@ -111,9 +71,7 @@ }); | ||
const [validId, query] = source.split('?'); | ||
if (!validId.endsWith(virtualExtCss)) { | ||
return; | ||
} | ||
if (!validId.endsWith(virtualExtCss)) return; | ||
// Absolute paths seem to occur often in monorepos, where files are | ||
// imported from outside the config root. | ||
const absoluteId = source.startsWith(config.root) ? source : getAbsoluteFileId(validId); | ||
const absoluteId = getAbsoluteFileId(validId); | ||
@@ -123,3 +81,3 @@ // There should always be an entry in the `cssMap` here. | ||
// a file in their app using the .vanilla.js/.vanilla.css extension | ||
if (cssMap.has(absoluteId)) { | ||
if (compiler?.getCssForFile(virtualIdToFileId(absoluteId)) || cssMap.has(absoluteId)) { | ||
// Keep the original query string for HMR. | ||
@@ -131,6 +89,12 @@ return absoluteId + (query ? `?${query}` : ''); | ||
const [validId] = id.split('?'); | ||
if (!validId.endsWith(virtualExtCss)) return; | ||
if (compiler) { | ||
const absoluteId = getAbsoluteFileId(validId); | ||
let { | ||
css: _css | ||
} = compiler.getCssForFile(virtualIdToFileId(absoluteId)) ?? {}; | ||
return _css; | ||
} | ||
const css = cssMap.get(validId); | ||
if (typeof css === 'string' && validId.endsWith(virtualExtCss)) { | ||
return css; | ||
} | ||
return css; | ||
}, | ||
@@ -142,30 +106,24 @@ async transform(code, id) { | ||
} | ||
const identOption = identifiers !== null && identifiers !== void 0 ? identifiers : config.mode === 'production' ? 'short' : 'debug'; | ||
if (compiler) { | ||
const absoluteVirtualId = cssImportSpecifier(validId); | ||
const absoluteId = getAbsoluteFileId(validId); | ||
console.time(`[compiler] ${validId}`); | ||
const { | ||
source, | ||
watchFiles | ||
} = await compiler.processVanillaFile(validId); | ||
let { | ||
css | ||
} = compiler.getCssForFile(validId); | ||
source: _source, | ||
watchFiles: _watchFiles | ||
} = await compiler.processVanillaFile(absoluteId, { | ||
outputCss: true | ||
}); | ||
console.timeEnd(`[compiler] ${validId}`); | ||
if (postCssConfig) { | ||
css = await processCss(css); | ||
} | ||
for (const file of watchFiles) { | ||
for (const file of _watchFiles) { | ||
// In start mode, we need to prevent the file from rewatching itself. | ||
// If it's a `build --watch`, it needs to watch everything. | ||
if (config.command === 'build' || normalizePath(file) !== validId) { | ||
if (config.command === 'build' || normalizePath(file) !== absoluteId) { | ||
this.addWatchFile(file); | ||
} | ||
} | ||
if (cssMap.has(absoluteVirtualId) && cssMap.get(absoluteVirtualId) !== css) { | ||
invalidateModule(absoluteVirtualId); | ||
} | ||
cssMap.set(absoluteVirtualId, css); | ||
// We have to invalidate the virtual module, not the real one we just transformed | ||
invalidateModule(fileIdToVirtualId(validId)); | ||
return { | ||
code: source, | ||
code: _source, | ||
map: { | ||
@@ -176,2 +134,3 @@ mappings: '' | ||
} | ||
const identOption = identifiers ?? (config.mode === 'production' ? 'short' : 'debug'); | ||
if (!emitCssInSsr) { | ||
@@ -206,10 +165,6 @@ return transform({ | ||
const absoluteId = getAbsoluteFileId(rootRelativeId); | ||
let cssSource = source; | ||
if (postCssConfig) { | ||
cssSource = await processCss(cssSource); | ||
} | ||
if (cssMap.has(absoluteId) && cssMap.get(absoluteId) !== cssSource) { | ||
if (cssMap.has(absoluteId) && cssMap.get(absoluteId) !== source) { | ||
invalidateModule(absoluteId); | ||
} | ||
cssMap.set(absoluteId, cssSource); | ||
cssMap.set(absoluteId, source); | ||
@@ -235,2 +190,5 @@ // We use the root relative id here to ensure file contents (content-hashes) | ||
}; | ||
}, | ||
buildEnd() { | ||
compiler?.close(); | ||
} | ||
@@ -237,0 +195,0 @@ }; |
{ | ||
"name": "@vanilla-extract/vite-plugin", | ||
"version": "0.0.0-vite-plugin-new-20231220084042", | ||
"version": "0.0.0-vite-plugin-new-20231226032342", | ||
"description": "Zero-runtime Stylesheets-in-TypeScript", | ||
@@ -18,6 +18,3 @@ "main": "dist/vanilla-extract-vite-plugin.cjs.js", | ||
"dependencies": { | ||
"@vanilla-extract/integration": "0.0.0-vite-plugin-new-20231220084042", | ||
"outdent": "^0.8.0", | ||
"postcss": "^8.4.32", | ||
"postcss-load-config": "^4.0.1" | ||
"@vanilla-extract/integration": "0.0.0-vite-plugin-new-20231226032342" | ||
}, | ||
@@ -24,0 +21,0 @@ "devDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2
9
25573
566
+ Added@vanilla-extract/integration@0.0.0-vite-plugin-new-20231226032342(transitive)
- Removedoutdent@^0.8.0
- Removedpostcss@^8.4.32
- Removedpostcss-load-config@^4.0.1
- Removed@vanilla-extract/integration@0.0.0-vite-plugin-new-20231220084042(transitive)
- Removedlilconfig@3.1.3(transitive)
- Removedpostcss-load-config@4.0.2(transitive)
- Removedyaml@2.6.1(transitive)
Updated@vanilla-extract/integration@0.0.0-vite-plugin-new-20231226032342