Gathering detailed insights and metrics for rollup-plugin-svelte
Gathering detailed insights and metrics for rollup-plugin-svelte
Gathering detailed insights and metrics for rollup-plugin-svelte
Gathering detailed insights and metrics for rollup-plugin-svelte
@types/rollup-plugin-svelte-svg
TypeScript definitions for rollup-plugin-svelte-svg
rollup-plugin-svelte-hot
Compile Svelte components with HMR support for Rollup or Nollup
rollup-plugin-svelte-svg
Import SVG images as Svelte Components
svelte-hmr
Bundler agnostic HMR utils for Svelte 3
npm install rollup-plugin-svelte
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
505 Stars
267 Commits
79 Forks
20 Watching
3 Branches
55 Contributors
Updated on 22 Oct 2024
Minified
Minified + Gzipped
JavaScript (97.5%)
Svelte (1.54%)
HTML (0.59%)
TypeScript (0.37%)
Cumulative downloads
Total Downloads
Last day
-22%
15,009
Compared to previous day
Last week
-0.7%
101,096
Compared to previous week
Last month
14.4%
413,788
Compared to previous month
Last year
-0.6%
4,279,772
Compared to previous year
2
7
Undecided yet what bundler to use? We suggest using SvelteKit or Vite with vite-plugin-svelte.
Compile Svelte components.
1npm install --save-dev svelte rollup-plugin-svelte
Note that we need to install Svelte as well as the plugin, as it's a 'peer dependency'.
1// rollup.config.js 2import svelte from 'rollup-plugin-svelte'; 3import resolve from '@rollup/plugin-node-resolve'; 4 5export default { 6 input: 'src/main.js', 7 output: { 8 file: 'public/bundle.js', 9 format: 'iife' 10 }, 11 plugins: [ 12 svelte({ 13 // By default, all ".svelte" files are compiled 14 extensions: ['.my-custom-extension'], 15 16 // You can restrict which files are compiled 17 // using `include` and `exclude` 18 include: 'src/components/**/*.svelte', 19 20 // Optionally, preprocess components with svelte.preprocess: 21 // https://svelte.dev/docs#compile-time-svelte-preprocess 22 preprocess: { 23 style: ({ content }) => { 24 return transformStyles(content); 25 } 26 }, 27 28 // Emit CSS as "files" for other plugins to process. default is true 29 emitCss: false, 30 31 // Warnings are normally passed straight to Rollup. You can 32 // optionally handle them here, for example to squelch 33 // warnings with a particular code 34 onwarn: (warning, handler) => { 35 // e.g. don't warn on <marquee> elements, cos they're cool 36 if (warning.code === 'a11y-distracting-elements') return; 37 38 // let Rollup handle all other warnings normally 39 handler(warning); 40 }, 41 42 // You can pass any of the Svelte compiler options 43 compilerOptions: { 44 45 // By default, the client-side compiler is used. You 46 // can also use the server-side rendering compiler 47 generate: 'ssr', 48 49 // ensure that extra attributes are added to head 50 // elements for hydration (used with generate: 'ssr') 51 hydratable: true, 52 53 // You can optionally set 'customElement' to 'true' to compile 54 // your components to custom elements (aka web elements) 55 customElement: false 56 } 57 }), 58 // see NOTICE below 59 resolve({ 60 browser: true, 61 exportConditions: ['svelte'], 62 extensions: ['.svelte'] 63 }), 64 // ... 65 ] 66}
NOTICE: You will need additional Rollup plugins.
Alone, this plugin translates Svelte components into CSS and JavaScript files.
You will need to include@rollup/plugin-node-resolve
– and probably@rollup/plugin-commonjs
– in your Rollup config.
If you are using the preprocess
feature, then your callback responses may — in addition to the code
and map
values described in the Svelte compile docs — also optionally include a dependencies
array. This should be the paths of additional files that the preprocessor result in some way depends upon. In Rollup 0.61+ in watch mode, any changes to these additional files will also trigger re-builds.
svelte
exports conditionIf you're importing a component from your node_modules folder, and that component's package.json
has a "svelte"
property in its exports
condition...
1{ 2 "name": "some-component", 3 4 // this means 'some-component' resolves to 'some-component/src/SomeComponent.svelte' 5 "exports": { 6 ".": { 7 "svelte": "./src/MyComponent.svelte" 8 } 9 } 10}
...then this plugin together with @rollup/plugin-node-resolve
(and its exportConditions
option containing the 'svelte'
condition – see configuration example above) 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 the "svelte"
property in the exports
of your package.json
.
If you are publishing a package containing multiple components, you can create an index.js
file that re-exports all the components, like this:
1export { default as Component1 } from './Component1.svelte'; 2export { default as Component2 } from './Component2.svelte';
and so on. Then, in package.json
, set the svelte
condition to point to this index.js
file. Or you may create an export for each individual Svelte file. Using a single index.js
which exports all files will allow multiple components to be imported with a single line, but may load more slowly during development. An export per file may load more quickly during development but require a separate import statement for each file.
By default (when emitCss: true
) the CSS styles will be emitted into a virtual file, allowing another Rollup plugin – for example, rollup-plugin-css-only
, rollup-plugin-postcss
, etc. – to take responsibility for the new stylesheet. In fact, emitting CSS files requires that you use a Rollup plugin to handle the CSS. Otherwise, your build(s) will fail! This is because this plugin will add an import
statement to import the emitted CSS file. It's not valid JS to import a CSS file into a JS file, but it allows the CSS to be linked to its respective JS file and is a common pattern that other Rollup CSS plugins know how to handle.
If you set emitCss: false
and your Svelte components contain <style>
tags, the compiler will add JavaScript that injects those styles into the page when the component is rendered. That's not the default, because it adds weight to your JavaScript, prevents styles from being fetched in parallel with your code, and can even cause CSP violations.
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
3 existing vulnerabilities detected
Details
Reason
3 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 4
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
Found 4/20 approved changesets -- score normalized to 2
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More