
Security News
/Research
npm Phishing Email Targets Developers with Typosquatted Domain
A phishing attack targeted developers using a typosquatted npm domain (npnjs.com) to steal credentials via fake login pages - watch out for similar scams.
rollup-plugin-svelte
Advanced tools
Compile Svelte components.
npm install --save-dev rollup-plugin-svelte
// rollup.config.js
import * as fs from 'fs';
import svelte from 'rollup-plugin-svelte';
export default {
entry: 'src/main.js',
dest: 'public/bundle.js',
format: 'iife',
plugins: [
svelte({
// By default, all .html and .svelte files are compiled
extensions: [ '.my-custom-extension' ],
// You can restrict which files are compiled
// using `include` and `exclude`
include: 'src/components/**/*.html',
// By default, the client-side compiler is used. You
// can also use the server-side rendering compiler
generate: 'ssr',
// Extract CSS into a separate file (recommended).
// See note below
css: function ( css ) {
fs.writeFileSync( 'public/main.css', css );
}
})
]
}
pkg.svelte
and pkg["svelte.root"]
If you're importing a component from your node_modules folder, and that component's package.json has "svelte"
and/or "svelte.root"
properties...
{
"name": "some-component",
// this means 'some-component' resolves to 'some-component/src/SomeComponent.html'
"svelte": "src/MyComponent.html",
// this means 'my-component/Foo.html' resolves to 'some-component/src/Foo.html'
"svelte.root": "src"
}
...then this plugin will ensure that your app imports the uncompiled component source code. That will result in a smaller, faster app (because code is deduplicated, and shared functions get optimized quicker), and makes it less likely that you'll run into bugs caused by your app using a different version of Svelte to the component.
Conversely, if you're publishing a component to npm, you should ship the uncompiled source (together with the compiled distributable, for people who aren't using Svelte elsewhere in their app) and include these properties in your package.json.
If your Svelte components contain <style>
tags, by default the compiler will add JavaScript that injects those styles into the page when the component is rendered. That's not ideal, because it adds weight to your JavaScript, prevents styles from being fetched in parallel with your code, and can even cause CSP violations.
A better option is to extract the CSS into a separate file. Using the css
option as shown above would cause a public/main.css
file to be generated each time the bundle is built (or rebuilt, if you're using rollup-watch), with the normal scoping rules applied.
Alternatively, if you're handling styles in some other way and just want to prevent the CSS being added to your JavaScript bundle, use css: false
.
MIT
2.0.2
code
and map
in object passed to RollupFAQs
Compile Svelte components with Rollup
The npm package rollup-plugin-svelte receives a total of 94,922 weekly downloads. As such, rollup-plugin-svelte popularity was classified as popular.
We found that rollup-plugin-svelte demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers 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.
Security News
/Research
A phishing attack targeted developers using a typosquatted npm domain (npnjs.com) to steal credentials via fake login pages - watch out for similar scams.
Security News
Knip hits 500 releases with v5.62.0, refining TypeScript config detection and updating plugins as monthly npm downloads approach 12M.
Security News
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.