
Product
Introducing Scala and Kotlin Support in Socket
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
esm-loader-svelte
Advanced tools
Node.js ESModule Loader for importing and loading
Svelte (.svelte
) and SvelteKit files, and
transpiling on the fly.
Warning! Using experimental Node.js features and flags, API will likely change. This may be helpful for development and testing, but should not be used in production.
npm install --save-dev esm-loader-svelte
We want to import a .svelte
file with Node.js:
<!-- Component.svelte -->
<script>
const words = 'Hello'
</script>
<h1>{words} World!</h1>
<style>
h1 {
color: blue;
}
</style>
// index.js
import Component from './Component.svelte'
// render(Component) to DOM, etc.
# node >= 20.7
cat << EOF > ./register.js
import { register } from 'node:module'
register('esm-loader-svelte', import.meta.url)
EOF
NODE_OPTIONS="--import ./register.js" node index.js
# node < 20.7
NODE_OPTIONS="--loader esm-loader-svelte" node index.js
This loader can be configured, and chained with other loaders, using node-esm-loader.
npm install --save-dev node-esm-loader
// .loaderrc.js
export default {
loaders: ['esm-loader-svelte'],
}
# node >= 20.7
NODE_OPTIONS="--import node-esm-loader/register" node index.js
# node < 20.7
NODE_OPTIONS="--loader node-esm-loader" node index.js
// .loaderrc.js
export default {
loaders: [
{
loader: 'esm-loader-svelte',
options: {
debug: true,
},
},
],
}
Preprocessing options can be supplied, for usage with something like SvelteKit's svelte-preprocess.
Supply preprocessing options via node-esm-loader
config file .loaderrc.js
:
// .loaderrc.js
import preprocess from 'svelte-preprocess'
import { resolve } from 'node:path'
export default {
loaders: [
{
loader: 'esm-loader-svelte',
options: {
preprocess: preprocess({
postcss: true,
typescript: {
tsconfigDirectory: resolve('./'),
tsconfigFile: 'tsconfig.json',
},
}),
},
},
],
}
If options.preprocess
is NOT found in .loaderrc.js
, then we will try to
load a SvelteKit svelte.config.js
file, and use the preprocess
settings
found therein:
// svelte.config.js
import preprocess from 'svelte-preprocess'
import { resolve } from 'node:path'
export default {
kit: ...,
preprocess: preprocess({
postcss: true,
typescript: {
tsconfigDirectory: resolve('./'),
tsconfigFile: 'tsconfig.json',
}
})
}
To further support loading SvelteKit, you may be interested in chaining additional loaders. If you are testing a SvelteKit app, we suggest using vitest instead.
Svelte does not run some lifecycle events on the server under Node.js:
onMount
, beforeUpdate
, afterUpdate
.
FAQs
Chainable ESModule Loader for Svelte and SvelteKit
The npm package esm-loader-svelte receives a total of 23 weekly downloads. As such, esm-loader-svelte popularity was classified as not popular.
We found that esm-loader-svelte demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.