Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sveltejs/vite-plugin-svelte

Package Overview
Dependencies
Maintainers
4
Versions
109
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sveltejs/vite-plugin-svelte - npm Package Compare versions

Comparing version 1.0.0-next.6 to 1.0.0-next.7

6

CHANGELOG.md
# @sveltejs/vite-plugin-svelte
## 1.0.0-next.7
### Minor Changes
- [#32](https://github.com/sveltejs/vite-plugin-svelte/pull/32) [`113bb7d`](https://github.com/sveltejs/vite-plugin-svelte/commit/113bb7dc330a7517085d12d1d0758a376a12253f) Thanks [@dominikg](https://github.com/dominikg)! - Reduced cache usage, share css cache between SSR and client
## 1.0.0-next.6

@@ -4,0 +10,0 @@

5

dist/index.d.ts

@@ -184,7 +184,2 @@ import { Plugin as Plugin_2 } from 'vite';

/**
* do not return cached transform data
* @default false
*/
disableTransformCache?: boolean;
/**
* use vite as extra css preprocessor EXPERIMENTAL!

@@ -191,0 +186,0 @@ * @default false

93

dist/index.js

@@ -131,20 +131,21 @@ var __create = Object.create;

// src/handleHotUpdate.ts
async function handleHotUpdate(compileSvelte, ctx, svelteRequest, cache) {
async function handleHotUpdate(compileSvelte, ctx, svelteRequest, cache, options) {
const {read, server} = ctx;
const cachedCompileData = cache.getCompileData(svelteRequest, false);
if (!cachedCompileData) {
const cachedJS = cache.getJS(svelteRequest);
if (!cachedJS) {
log.debug(`handleHotUpdate first call ${svelteRequest.id}`);
return;
}
const cachedCss = cache.getCSS(svelteRequest);
const content = await read();
const compileData = await compileSvelte(svelteRequest, content, cachedCompileData.options);
cache.setCompileData(compileData);
const compileData = await compileSvelte(svelteRequest, content, options);
cache.update(compileData);
const affectedModules = new Set();
const cssModule = server.moduleGraph.getModuleById(svelteRequest.cssId);
const mainModule = server.moduleGraph.getModuleById(svelteRequest.id);
if (cssModule && cssChanged(cachedCompileData, compileData)) {
if (cssModule && cssChanged(cachedCss, compileData.compiled.css)) {
log.debug("handleHotUpdate css changed");
affectedModules.add(cssModule);
}
if (mainModule && jsChanged(cachedCompileData, compileData)) {
if (mainModule && jsChanged(cachedJS, compileData.compiled.js, svelteRequest.filename)) {
log.debug("handleHotUpdate js changed");

@@ -163,8 +164,7 @@ affectedModules.add(mainModule);

function cssChanged(prev, next) {
var _a, _b;
return !isCodeEqual((_a = prev.compiled.css) == null ? void 0 : _a.code, (_b = next.compiled.css) == null ? void 0 : _b.code);
return !isCodeEqual(prev == null ? void 0 : prev.code, next == null ? void 0 : next.code);
}
function jsChanged(prev, next) {
const prevJs = prev.compiled.js.code;
const nextJs = next.compiled.js.code;
function jsChanged(prev, next, filename) {
const prevJs = prev == null ? void 0 : prev.code;
const nextJs = next == null ? void 0 : next.code;
const isStrictEqual = isCodeEqual(prevJs, nextJs);

@@ -176,3 +176,3 @@ if (isStrictEqual) {

if (!isStrictEqual && isLooseEqual) {
log.warn(`ignoring compiler output js change for ${next.filename} as it is equal to previous output after normalization`);
log.warn(`ignoring compiler output js change for ${filename} as it is equal to previous output after normalization`);
}

@@ -348,14 +348,7 @@ return !isLooseEqual;

compiled.js.dependencies = dependencies;
const result = {
filename,
return {
normalizedFilename,
cssId,
code,
preprocessed,
compiled,
compilerOptions: finalCompilerOptions,
options,
ssr
};
return result;
};

@@ -482,3 +475,2 @@ function buildMakeHot(options) {

"hot",
"disableTransformCache",
"disableCssHmr",

@@ -568,23 +560,20 @@ "useVitePreprocess"

constructor() {
this._compile = new Map();
this._compileSSR = new Map();
this._css = new Map();
this._js = new Map();
}
selectCache(ssr) {
return ssr ? this._compileSSR : this._compile;
update(compileData) {
const id = compileData.normalizedFilename;
this._css.set(id, compileData.compiled.css);
if (!compileData.ssr) {
this._js.set(id, compileData.compiled.js);
}
}
getCompileData(svelteRequest, errorOnMissing = true) {
const cache = this.selectCache(svelteRequest.ssr);
const id = svelteRequest.normalizedFilename;
if (cache.has(id)) {
return cache.get(id);
getCSS(svelteRequest) {
return this._css.get(svelteRequest.normalizedFilename);
}
getJS(svelteRequest) {
if (!svelteRequest.ssr) {
return this._js.get(svelteRequest.normalizedFilename);
}
if (errorOnMissing) {
throw new Error(`${id} has no corresponding entry in the ${svelteRequest.ssr ? "ssr" : ""}cache. This is a @sveltejs/vite-plugin-svelte internal error, please open an issue.`);
}
}
setCompileData(compileData) {
const cache = this.selectCache(!!compileData.ssr);
const id = compileData.normalizedFilename;
cache.set(id, compileData);
}
};

@@ -658,3 +647,2 @@

load(id, ssr) {
var _a;
const svelteRequest = requestParser(id, !!ssr);

@@ -668,6 +656,6 @@ if (!svelteRequest) {

if (query.type === "style") {
const compileData = cache.getCompileData(svelteRequest, false);
if ((_a = compileData == null ? void 0 : compileData.compiled) == null ? void 0 : _a.css) {
const css = cache.getCSS(svelteRequest);
if (css) {
log.debug(`load returns css for ${filename}`);
return compileData.compiled.css;
return css;
}

@@ -716,3 +704,2 @@ }

async transform(code, id, ssr) {
var _a;
const svelteRequest = requestParser(id, !!ssr);

@@ -724,7 +711,9 @@ if (!svelteRequest) {

const {filename, query} = svelteRequest;
const cachedCompileData = cache.getCompileData(svelteRequest, false);
if (query.svelte) {
if (query.type === "style" && ((_a = cachedCompileData == null ? void 0 : cachedCompileData.compiled) == null ? void 0 : _a.css)) {
log.debug(`transform returns css for ${filename}`);
return cachedCompileData.compiled.css;
if (query.type === "style") {
const css = cache.getCSS(svelteRequest);
if (css) {
log.debug(`transform returns css for ${filename}`);
return css;
}
}

@@ -734,8 +723,4 @@ log.error("failed to transform tagged svelte request", svelteRequest);

}
if (cachedCompileData && !options.disableTransformCache) {
log.debug(`transform returns cached js for ${filename}`);
return cachedCompileData.compiled.js;
}
const compileData = await compileSvelte(svelteRequest, code, options);
cache.setCompileData(compileData);
cache.update(compileData);
log.debug(`transform returns compiled js for ${filename}`);

@@ -753,3 +738,3 @@ return compileData.compiled.js;

log.debug("handleHotUpdate", svelteRequest);
return handleHotUpdate(compileSvelte, ctx, svelteRequest, cache);
return handleHotUpdate(compileSvelte, ctx, svelteRequest, cache, options);
},

@@ -756,0 +741,0 @@ transformIndexHtml(html, ctx) {

{
"name": "@sveltejs/vite-plugin-svelte",
"version": "1.0.0-next.6",
"version": "1.0.0-next.7",
"license": "MIT",

@@ -5,0 +5,0 @@ "author": "dominikg",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc