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.14 to 1.0.0-next.15

18

CHANGELOG.md
# @sveltejs/vite-plugin-svelte
## 1.0.0-next.15
### Major Changes
- change default value of compilerOptions.hydratable to false ([#122](https://github.com/sveltejs/vite-plugin-svelte/pull/122))
This is done to align with svelte compiler defaults and improve output in non-ssr scenarios.
Add `{compilerOptions: {hydratable: true}}` to vite-plugin-svelte config if you need hydration (eg. for ssr)
### Minor Changes
- add config option `experimental.dynamicCompileOptions` for finegrained control over compileOptions ([#122](https://github.com/sveltejs/vite-plugin-svelte/pull/122))
### Patch Changes
- resolve vite.root option correctly (fixes [#113](https://github.com/sveltejs/vite-plugin-svelte/issues/113)) ([#115](https://github.com/sveltejs/vite-plugin-svelte/pull/115))
## 1.0.0-next.14

@@ -4,0 +22,0 @@

@@ -81,2 +81,21 @@ import { Plugin } from 'vite';

generateMissingPreprocessorSourcemaps?: boolean;
/**
* function to update compilerOptions before compilation
*
* data.filename is the file to be compiled,
* data.code is the already preprocessed code
* data.compileOptions are the compilerOptions that are going to be used
*
* to change one, you should return an object with the changes you need, eg:
*
* ```
* ({filename,compileOptions}) => { if( compileWithHydratable(filename) && !compileOptions.hydratable ){ return {hydratable: true}}}
* ```
* @default undefined
*/
dynamicCompileOptions?: (data: {
filename: string;
code: string;
compileOptions: Partial<CompileOptions>;
}) => Promise<Partial<CompileOptions> | void> | Partial<CompileOptions> | void;
}

@@ -83,0 +102,0 @@ declare type ModuleFormat = NonNullable<CompileOptions['format']>;

56

dist/index.js

@@ -270,6 +270,7 @@ var __create = Object.create;

var _createCompileSvelte = (makeHot) => async function compileSvelte(svelteRequest, code, options) {
var _a, _b;
const { filename, normalizedFilename, cssId, ssr } = svelteRequest;
const { emitCss = true } = options;
const dependencies = [];
const finalCompilerOptions = __spreadProps(__spreadValues({}, options.compilerOptions), {
const compileOptions = __spreadProps(__spreadValues({}, options.compilerOptions), {
filename,

@@ -281,3 +282,3 @@ generate: ssr ? "ssr" : "dom"

log.debug(`setting cssHash ${hash} for ${normalizedFilename}`);
finalCompilerOptions.cssHash = () => hash;
compileOptions.cssHash = () => hash;
}

@@ -290,5 +291,15 @@ let preprocessed;

if (preprocessed.map)
finalCompilerOptions.sourcemap = preprocessed.map;
compileOptions.sourcemap = preprocessed.map;
}
const compiled = compile(preprocessed ? preprocessed.code : code, finalCompilerOptions);
const finalCode = preprocessed ? preprocessed.code : code;
const dynamicCompileOptions = await ((_b = (_a = options.experimental) == null ? void 0 : _a.dynamicCompileOptions) == null ? void 0 : _b.call(_a, {
filename,
code: finalCode,
compileOptions
}));
if (dynamicCompileOptions && log.debug.enabled) {
log.debug(`dynamic compile options for ${filename}: ${JSON.stringify(dynamicCompileOptions)}`);
}
const finalCompileOptions = dynamicCompileOptions ? __spreadValues(__spreadValues({}, compileOptions), dynamicCompileOptions) : compileOptions;
const compiled = compile(finalCode, finalCompileOptions);
if (emitCss && compiled.css.code) {

@@ -306,3 +317,3 @@ compiled.js.code += `

originalCode: code,
compileOptions: finalCompilerOptions
compileOptions: finalCompileOptions
});

@@ -418,2 +429,5 @@ }

// src/utils/options.ts
import { normalizePath as normalizePath2 } from "vite";
// src/utils/load-svelte-config.ts

@@ -508,2 +522,3 @@ import path from "path";

// src/utils/options.ts
import path2 from "path";
var knownOptions = new Set([

@@ -534,4 +549,3 @@ "configFile",

css: !emitCss,
dev: !isProduction,
hydratable: true
dev: !isProduction
}

@@ -595,3 +609,3 @@ };

experimental: __spreadValues(__spreadValues({}, (svelteConfig == null ? void 0 : svelteConfig.experimental) || {}), (inlineOptions == null ? void 0 : inlineOptions.experimental) || {}),
root: viteConfig.root || process.cwd(),
root: viteConfig.root,
isProduction: viteEnv.mode === "production",

@@ -607,5 +621,8 @@ isBuild: viteEnv.command === "build",

async function resolveOptions(inlineOptions = {}, viteConfig, viteEnv) {
const viteConfigWithResolvedRoot = __spreadProps(__spreadValues({}, viteConfig), {
root: resolveViteRoot(viteConfig)
});
const defaultOptions = buildDefaultOptions(viteEnv.mode === "production", inlineOptions);
const svelteConfig = await loadSvelteConfig(viteConfig, inlineOptions) || {};
const resolvedOptions = mergeOptions(defaultOptions, svelteConfig, inlineOptions, viteConfig, viteEnv);
const svelteConfig = await loadSvelteConfig(viteConfigWithResolvedRoot, inlineOptions) || {};
const resolvedOptions = mergeOptions(defaultOptions, svelteConfig, inlineOptions, viteConfigWithResolvedRoot, viteEnv);
enforceOptionsForProduction(resolvedOptions);

@@ -615,2 +632,5 @@ enforceOptionsForHmr(resolvedOptions);

}
function resolveViteRoot(viteConfig) {
return normalizePath2(viteConfig.root ? path2.resolve(viteConfig.root) : process.cwd());
}
function buildExtraViteConfig(options, config) {

@@ -719,4 +739,4 @@ var _a, _b, _c, _d;

}
getDependants(path4) {
const dependants = this._dependants.get(path4);
getDependants(path5) {
const dependants = this._dependants.get(path5);
return dependants ? [...dependants] : [];

@@ -728,3 +748,3 @@ }

import fs3 from "fs";
import path2 from "path";
import path3 from "path";
function setupWatchers(options, cache, requestParser) {

@@ -768,3 +788,3 @@ const { server, configFile: svelteConfigFile } = options;

};
const possibleSvelteConfigs = knownSvelteConfigNames.map((cfg) => path2.join(root, cfg));
const possibleSvelteConfigs = knownSvelteConfigNames.map((cfg) => path3.join(root, cfg));
const restartOnConfigAdd = (filename) => {

@@ -799,3 +819,3 @@ if (possibleSvelteConfigs.includes(filename)) {

// src/utils/resolve.ts
import path3 from "path";
import path4 from "path";
import fs4 from "fs";

@@ -805,6 +825,6 @@ import relative from "require-relative";

if (importer && isBareImport(importee)) {
const importeePkgFile = relative.resolve(`${importee}/package.json`, path3.dirname(importer));
const importeePkgFile = relative.resolve(`${importee}/package.json`, path4.dirname(importer));
const importeePkg = JSON.parse(fs4.readFileSync(importeePkgFile, { encoding: "utf-8" }));
if (importeePkg.svelte) {
return path3.resolve(path3.dirname(importeePkgFile), importeePkg.svelte);
return path4.resolve(path4.dirname(importeePkgFile), importeePkg.svelte);
}

@@ -814,3 +834,3 @@ }

function isBareImport(importee) {
if (!importee || importee[0] === "." || importee[0] === "\0" || path3.isAbsolute(importee)) {
if (!importee || importee[0] === "." || importee[0] === "\0" || path4.isAbsolute(importee)) {
return false;

@@ -817,0 +837,0 @@ }

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

@@ -65,11 +65,11 @@ "author": "dominikg",

"devDependencies": {
"@types/debug": "^4.1.6",
"@types/debug": "^4.1.7",
"@types/diff-match-patch": "^1.0.32",
"diff-match-patch": "^1.0.5",
"esbuild": "^0.12.15",
"rollup": "^2.53.3",
"svelte": "^3.40.0",
"esbuild": "^0.12.16",
"rollup": "^2.55.0",
"svelte": "^3.41.0",
"tsup": "^4.12.5",
"vite": "^2.4.3"
"vite": "^2.4.4"
}
}

@@ -18,3 +18,4 @@ import { CompileOptions, ResolvedOptions } from './options';

const dependencies = [];
const finalCompilerOptions: CompileOptions = {
const compileOptions: CompileOptions = {
...options.compilerOptions,

@@ -27,3 +28,3 @@ filename,

log.debug(`setting cssHash ${hash} for ${normalizedFilename}`);
finalCompilerOptions.cssHash = () => hash;
compileOptions.cssHash = () => hash;
}

@@ -36,7 +37,23 @@

if (preprocessed.dependencies) dependencies.push(...preprocessed.dependencies);
if (preprocessed.map) finalCompilerOptions.sourcemap = preprocessed.map;
if (preprocessed.map) compileOptions.sourcemap = preprocessed.map;
}
const finalCode = preprocessed ? preprocessed.code : code;
const dynamicCompileOptions = await options.experimental?.dynamicCompileOptions?.({
filename,
code: finalCode,
compileOptions
});
if (dynamicCompileOptions && log.debug.enabled) {
log.debug(
`dynamic compile options for ${filename}: ${JSON.stringify(dynamicCompileOptions)}`
);
}
const finalCompileOptions = dynamicCompileOptions
? {
...compileOptions,
...dynamicCompileOptions
}
: compileOptions;
const compiled = compile(finalCode, finalCompileOptions);
const compiled = compile(preprocessed ? preprocessed.code : code, finalCompilerOptions);
if (emitCss && compiled.css.code) {

@@ -55,3 +72,3 @@ // TODO properly update sourcemap?

originalCode: code,
compileOptions: finalCompilerOptions
compileOptions: finalCompileOptions
});

@@ -65,2 +82,3 @@ }

normalizedFilename,
// @ts-ignore
compiled,

@@ -67,0 +85,0 @@ ssr,

/* eslint-disable no-unused-vars */
import { ConfigEnv, UserConfig, ViteDevServer } from 'vite';
import { ConfigEnv, UserConfig, ViteDevServer, normalizePath } from 'vite';
import { log } from './log';

@@ -15,2 +15,3 @@ import { loadSvelteConfig } from './load-svelte-config';

} from 'svelte/types/compiler/preprocess';
import path from 'path';

@@ -47,4 +48,3 @@ const knownOptions = new Set([

css: !emitCss,
dev: !isProduction,
hydratable: true
dev: !isProduction
}

@@ -136,3 +136,3 @@ };

},
root: viteConfig.root || process.cwd(),
root: viteConfig.root!,
isProduction: viteEnv.mode === 'production',

@@ -155,4 +155,8 @@ isBuild: viteEnv.command === 'build',

): Promise<ResolvedOptions> {
const viteConfigWithResolvedRoot = {
...viteConfig,
root: resolveViteRoot(viteConfig)
};
const defaultOptions = buildDefaultOptions(viteEnv.mode === 'production', inlineOptions);
const svelteConfig = (await loadSvelteConfig(viteConfig, inlineOptions)) || {};
const svelteConfig = (await loadSvelteConfig(viteConfigWithResolvedRoot, inlineOptions)) || {};
const resolvedOptions = mergeOptions(

@@ -162,3 +166,3 @@ defaultOptions,

inlineOptions,
viteConfig,
viteConfigWithResolvedRoot,
viteEnv

@@ -172,2 +176,9 @@ );

// vite passes unresolved `root`option to config hook but we need the resolved value, so do it here
// https://github.com/sveltejs/vite-plugin-svelte/issues/113
// https://github.com/vitejs/vite/blob/43c957de8a99bb326afd732c962f42127b0a4d1e/packages/vite/src/node/config.ts#L293
function resolveViteRoot(viteConfig: UserConfig): string | undefined {
return normalizePath(viteConfig.root ? path.resolve(viteConfig.root) : process.cwd());
}
export function buildExtraViteConfig(

@@ -308,2 +319,22 @@ options: ResolvedOptions,

generateMissingPreprocessorSourcemaps?: boolean;
/**
* function to update compilerOptions before compilation
*
* data.filename is the file to be compiled,
* data.code is the already preprocessed code
* data.compileOptions are the compilerOptions that are going to be used
*
* to change one, you should return an object with the changes you need, eg:
*
* ```
* ({filename,compileOptions}) => { if( compileWithHydratable(filename) && !compileOptions.hydratable ){ return {hydratable: true}}}
* ```
* @default undefined
*/
dynamicCompileOptions?: (data: {
filename: string;
code: string;
compileOptions: Partial<CompileOptions>;
}) => Promise<Partial<CompileOptions> | void> | Partial<CompileOptions> | void;
}

@@ -310,0 +341,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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