├── .eslintrc ├── .github ├── FUNDING.yml └── workflows │ └── ci.yml.bak ├── .gitignore ├── CHANGELOG.hot.md ├── CHANGELOG.md ├── LICENSE ├── README.md ├── index.d.ts ├── index.js ├── package.json ├── pnpm-lock.yaml └── test ├── filename-test └── src │ └── foo.svelte.dev │ ├── index.svelte │ └── main.js ├── index.js ├── node_modules ├── .gitkeep ├── esm-component │ ├── index.js │ ├── package.json │ └── src │ │ └── Component.svelte ├── esm-no-pkg-export │ ├── index.js │ └── package.json ├── widget │ ├── index.js │ ├── package.json │ └── src │ │ └── Widget.html └── widgets │ ├── index.js │ ├── package.json │ └── src │ └── Foo.html └── sourcemap-test ├── index.html └── src ├── Bar.svelte ├── Foo.svelte └── main.js /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "rules": { 4 | "indent": [ 2, "tab", { "SwitchCase": 1 } ], 5 | "quotes": [ 2, "single" ], 6 | "linebreak-style": [ 2, "unix" ], 7 | "semi": [ 2, "always" ], 8 | "keyword-spacing": [ 2, { "before": true, "after": true } ], 9 | "space-before-blocks": [ 2, "always" ], 10 | "no-mixed-spaces-and-tabs": [ 2, "smart-tabs" ], 11 | "no-cond-assign": [ 0 ] 12 | }, 13 | "env": { 14 | "es6": true, 15 | "browser": true, 16 | "mocha": true, 17 | "node": true 18 | }, 19 | "extends": "eslint:recommended", 20 | "parserOptions": { 21 | "ecmaVersion": 10, 22 | "sourceType": "module" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | open_collective: svelte 2 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml.bak: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | paths-ignore: 6 | - '*.md' 7 | - 'LICENSE' 8 | - 'index.d.ts' 9 | branches: 10 | - master 11 | pull_request: 12 | paths-ignore: 13 | - '*.md' 14 | - 'LICENSE' 15 | - 'index.d.ts' 16 | branches: 17 | - master 18 | 19 | jobs: 20 | test: 21 | name: Node.js v${{ matrix.nodejs }} (${{ matrix.os }}) 22 | runs-on: ${{ matrix.os }} 23 | timeout-minutes: 3 24 | strategy: 25 | matrix: 26 | nodejs: [10, 12, 14] 27 | os: [ubuntu-latest, windows-latest, macOS-latest] 28 | steps: 29 | - uses: actions/checkout@v2 30 | - uses: actions/setup-node@v1 31 | with: 32 | node-version: ${{ matrix.nodejs }} 33 | 34 | - name: Install 35 | run: npm ci 36 | 37 | - name: Linter 38 | if: matrix.os != 'windows-latest' 39 | run: npm run lint 40 | 41 | - name: Test 42 | run: npm test 43 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | !test/node_modules 4 | dist 5 | -------------------------------------------------------------------------------- /CHANGELOG.hot.md: -------------------------------------------------------------------------------- 1 | # rollup-plugin-svelte-hot changelog 2 | 3 | :warning: **NOTE** The [other Changelog](./CHANGELOG.md) is the one of the plugin this one is mimicking. :warning: 4 | 5 | ## 1.0.0 6 | 7 | * Rebase of rollup-plugin-svelte@7 8 | * Basic Vite support 9 | 10 | ## TODO 11 | 12 | Bring back previous changelog from rollup-plugin-svelte-hot... 13 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # rollup-plugin-svelte changelog 2 | 3 | :warning: **NOTE** This is the changelog of the upstream plugin. Changelog of the hot fork is [this one](./CHANGELOG.hot.md) (kept this way for mergeability reasons). :warning: 4 | 5 | ## 7.1.0 6 | 7 | * Preprocessor sourcemap support ([#157](https://github.com/sveltejs/rollup-plugin-svelte/pull/157)) 8 | 9 | ## 7.0.0 10 | 11 | * New minimum version requirements ([#138](https://github.com/sveltejs/rollup-plugin-svelte/pull/138), [#142](https://github.com/sveltejs/rollup-plugin-svelte/pull/142)): 12 | * Rollup 2+ 13 | * Svelte 3.5+ (Svelte 2 is no longer supported) 14 | * Node 10+ 15 | * Breaking: Offload CSS handling to Rollup — you will now need an external plugin like `rollup-plugin-css-only` to extract your styles to `.css` files [as demonstrated in the template](https://github.com/sveltejs/template/blob/5b1135c286f7a649daa99825a077586655051649/rollup.config.js#L48) ([#147](https://github.com/sveltejs/rollup-plugin-svelte/pull/147)) 16 | * Breaking: Options to be passed directly to the Svelte compiler must now go under a `compilerOptions` key in the plugin configuration object ([#145](https://github.com/sveltejs/rollup-plugin-svelte/pull/145)) 17 | * Extend `CompileOptions` interface directly ([#126](https://github.com/sveltejs/rollup-plugin-svelte/pull/126)) 18 | * Pass relative `filename` to svelte compiler ([#131](https://github.com/sveltejs/rollup-plugin-svelte/pull/131)) 19 | * Link `sourcemap` with source correctly ([#140](https://github.com/sveltejs/rollup-plugin-svelte/pull/140)) 20 | * Respect `sourcemapExcludeSources` Rollup config ([#93](https://github.com/sveltejs/rollup-plugin-svelte/pull/93)) 21 | * Keep all sourcemaps from chunk ([#44](https://github.com/sveltejs/rollup-plugin-svelte/pull/44)) 22 | 23 | ## 6.1.1 24 | 25 | * Use `require('svelte/compiler')` rather than `require('svelte/compiler.js')` to work with new Svelte exports map 26 | 27 | ## 6.1.0 28 | 29 | * feat: allow custom Svelte compilers via new `svelte` option: ([#124](https://github.com/sveltejs/rollup-plugin-svelte/pull/124)) 30 | * fix: use native `fs.existsSync` method: ([`50e03e5`](https://github.com/sveltejs/rollup-plugin-svelte/commit/50e03e5)) 31 | * chore: Power CI via GitHub Action ([`61ead9a..23e83a4`](https://github.com/sveltejs/rollup-plugin-svelte/compare/61ead9a..23e83a4)) 32 | 33 | ## 6.0.2 34 | 35 | * Added default value to CssWriter.write map option ([#135](https://github.com/sveltejs/rollup-plugin-svelte/pull/135)) 36 | * Do not warn about missing unused css selectors if both css and emitCss are false ([#127](https://github.com/sveltejs/rollup-plugin-svelte/pull/127)) 37 | 38 | ## 6.0.1 39 | 40 | * Fix types to allow `css: false` ([#125](https://github.com/sveltejs/rollup-plugin-svelte/pull/125)) 41 | 42 | ## 6.0.0 43 | 44 | * Breaking changes: 45 | * Rollup 1.19.2+ is now required 46 | * The path passed to `css.write()` is now relative to the destination directory. 47 | * Other changes: 48 | * Add types for `generate`, `customElement`, and `preprocess` options ([#111](https://github.com/sveltejs/rollup-plugin-svelte/pull/111), [#114](https://github.com/sveltejs/rollup-plugin-svelte/pull/114), and [#118](https://github.com/sveltejs/rollup-plugin-svelte/pull/118)) 49 | * Use Rollup's `emitFile` API ([#72](https://github.com/sveltejs/rollup-plugin-svelte/pull/72)) 50 | * Warn when `package.json` does not expose itself via `exports` ([#119](https://github.com/sveltejs/rollup-plugin-svelte/pull/119)) 51 | 52 | ## 5.2.3 53 | 54 | * Actually publish typings ([#110](https://github.com/sveltejs/rollup-plugin-svelte/issues/110)) 55 | 56 | ## 5.2.2 57 | 58 | * Handle files with `.svelte` in the middle of their filename ([#107](https://github.com/sveltejs/rollup-plugin-svelte/pull/107)) 59 | 60 | ## 5.2.1 61 | 62 | * Revert accidental change to Rollup peer dependency 63 | 64 | ## 5.2.0 65 | 66 | * Deterministic CSS bundle order ([#84](https://github.com/sveltejs/rollup-plugin-svelte/issues/84)) 67 | * Add typings ([#90](https://github.com/sveltejs/rollup-plugin-svelte/pull/90)) 68 | 69 | ## 5.1.1 70 | 71 | * Use Svelte 3's built-in logic for automatically determining the component name from its file path ([#74](https://github.com/rollup/rollup-plugin-svelte/issues/74)) 72 | 73 | ## 5.1.0 74 | 75 | * Support array of preprocessors in Svelte 3 76 | 77 | ## 5.0.3 78 | 79 | * Handle `onwarn` correctly in new Svelte 3 beta 80 | 81 | ## 5.0.2 82 | 83 | * Support latest Svelte 3 beta 84 | 85 | ## 5.0.1 86 | 87 | * Use `this.addWatchFile` if present ([#46](https://github.com/rollup/rollup-plugin-svelte/pull/46)) 88 | 89 | ## 5.0.0 90 | *2018-12-16* 91 | * Replace deprecated `ongenerate` hook, use Rollup's internal warning mechanism; requires rollup@0.60+ ([#45](https://github.com/rollup/rollup-plugin-svelte/issues/45)) 92 | 93 | ## 4.5.0 94 | 95 | * Pass `dependencies` through from preprocessors ([#40](https://github.com/rollup/rollup-plugin-svelte/issues/40)) 96 | 97 | ## 4.4.0 98 | 99 | * Support Svelte 3 alpha 100 | * Internal reorganisation 101 | 102 | ## 4.3.2 103 | 104 | * Remove deprecated `onerror` handler 105 | 106 | ## 4.3.1 107 | 108 | * Handle arbitrary file extensions ([#38](https://github.com/rollup/rollup-plugin-svelte/pull/38)) 109 | * Generate Windows-friendly import paths ([#38](https://github.com/rollup/rollup-plugin-svelte/pull/38)) 110 | 111 | ## 4.3.0 112 | 113 | * Append inline sourcemaps to virtual CSS files generated with `emitCss: true` ([#36](https://github.com/rollup/rollup-plugin-svelte/pull/36)) 114 | 115 | ## 4.2.1 116 | 117 | * Fix `emitCss` with style-less components ([#34](https://github.com/rollup/rollup-plugin-svelte/pull/34)) 118 | 119 | ## 4.2.0 120 | 121 | * Add `emitCss` option ([#32](https://github.com/rollup/rollup-plugin-svelte/pull/32)) 122 | 123 | ## 4.1.0 124 | 125 | * Support Svelte 1.60 and above ([#29](https://github.com/rollup/rollup-plugin-svelte/pull/29)) 126 | 127 | ## 4.0.0 128 | 129 | * Move `svelte` to `peerDependencies` ([#25](https://github.com/rollup/rollup-plugin-svelte/issues/25)) 130 | 131 | ## 3.3.0 132 | 133 | * Pass ID as `filename` to `preprocess` ([#24](https://github.com/rollup/rollup-plugin-svelte/pull/24)) 134 | 135 | ## 3.2.0 136 | 137 | * Support `preprocess` option ([#21](https://github.com/rollup/rollup-plugin-svelte/issues/21)) 138 | * Ignore unused CSS selector warnings if `css: false` ([#17](https://github.com/rollup/rollup-plugin-svelte/issues/17)) 139 | 140 | ## 3.1.0 141 | 142 | * Allow `shared` option to override default ([#16](https://github.com/rollup/rollup-plugin-svelte/pull/16)) 143 | * Use `this.warn` and `this.error`, so Rollup can handle failures 144 | 145 | ## 3.0.1 146 | 147 | * `svelte` should be a dependency, not a devDependency... 148 | 149 | ## 3.0.0 150 | 151 | * CSS sourcemaps ([#14](https://github.com/rollup/rollup-plugin-svelte/issues/14)) 152 | 153 | ## 2.0.3 154 | 155 | * Ignore virtual modules ([#13](https://github.com/rollup/rollup-plugin-svelte/issues/13)) 156 | 157 | ## 2.0.2 158 | 159 | * Only include `code` and `map` in object passed to Rollup 160 | 161 | ## 2.0.1 162 | 163 | * Prevent import of built-in modules from blowing up the resolver 164 | 165 | ## 2.0.0 166 | 167 | * Add support for `pkg.svelte` and `pkg['svelte.root']` 168 | 169 | ## 1.8.1 170 | 171 | * Handle components without ` -------------------------------------------------------------------------------- /test/filename-test/src/foo.svelte.dev/main.js: -------------------------------------------------------------------------------- 1 | import App from './index.svelte'; 2 | 3 | new App({ 4 | target: document.body 5 | }); -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | const path = require('path'); 3 | const { test } = require('uvu'); 4 | const assert = require('uvu/assert'); 5 | const { SourceMapConsumer } = require('source-map'); 6 | const { rollup } = require('rollup'); 7 | const sander = require('sander'); 8 | 9 | const plugin = require('..'); 10 | 11 | test('resolves using pkg.svelte', async () => { 12 | const p = plugin(); 13 | assert.is( 14 | await p.resolveId('widget', path.resolve('test/foo/main.js')), 15 | path.resolve('test/node_modules/widget/src/Widget.svelte') 16 | ); 17 | }); 18 | 19 | test('ignores built-in modules', async () => { 20 | const p = plugin(); 21 | assert.ok( 22 | await p.resolveId('path', path.resolve('test/foo/main.js')) == null 23 | ); 24 | }); 25 | 26 | test('ignores esm modules that do not export package.json', async () => { 27 | const p = plugin(); 28 | assert.ok( 29 | await p.resolveId('esm-no-pkg-export', path.resolve('test/foo/main.js')) == null 30 | ); 31 | }); 32 | 33 | test('resolves esm module that exports package.json', async () => { 34 | const p = plugin(); 35 | assert.is( 36 | await p.resolveId('esm-component', path.resolve('test/foo/main.js')), 37 | path.resolve('test/node_modules/esm-component/src/Component.svelte') 38 | ); 39 | }); 40 | 41 | test('ignores virtual modules', async () => { 42 | const p = plugin(); 43 | assert.ok( 44 | await p.resolveId('path', path.resolve('\0some-plugin-generated-module')) == null 45 | ); 46 | }); 47 | 48 | test('supports component name assignment', async () => { 49 | const p = plugin(); 50 | const index = await p.transform('', 'index.svelte'); 51 | 52 | assert.is.not(index.code.indexOf('class Index extends SvelteComponent'), -1); 53 | 54 | const card = await p.transform('', 'card/index.svelte'); 55 | assert.is(card.code.indexOf('class Index extends SvelteComponent'), -1); 56 | assert.is.not(card.code.indexOf('class Card extends SvelteComponent'), -1); 57 | }); 58 | 59 | test('creates a {code, map, dependencies} object, excluding the AST etc', async () => { 60 | const p = plugin(); 61 | const compiled = await p.transform('', 'test.svelte'); 62 | assert.equal(Object.keys(compiled), ['code', 'map', 'dependencies']); 63 | }); 64 | 65 | test('respects `sourcemapExcludeSources` Rollup option', async () => { 66 | sander.rimrafSync('test/sourcemap-test/dist'); 67 | sander.mkdirSync('test/sourcemap-test/dist'); 68 | 69 | const bundle = await rollup({ 70 | input: 'test/sourcemap-test/src/main.js', 71 | plugins: [ plugin({ emitCss: false }) ], 72 | external: ['svelte/internal'] 73 | }); 74 | 75 | const { output } = await bundle.generate({ 76 | format: 'iife', 77 | sourcemap: true, 78 | sourcemapExcludeSources: true, 79 | file: 'test/sourcemap-test/dist/bundle.js', 80 | globals: { 'svelte/internal': 'svelte' }, 81 | assetFileNames: '[name][extname]', 82 | }); 83 | 84 | const { map } = output[0]; 85 | 86 | assert.ok(map); 87 | assert.is(map.file, 'bundle.js'); 88 | assert.is(map.sources.length, 1); 89 | assert.is(map.sources[0], '../src/main.js'); 90 | assert.is(map.sourcesContent, null); 91 | }); 92 | 93 | test('squelches "unused CSS" warnings if `emitCss: false`', () => { 94 | const p = plugin({ 95 | emitCss: false 96 | }); 97 | 98 | p.transform.call({ 99 | warn: warning => { 100 | throw new Error(warning.message); 101 | } 102 | }, ` 103 |
104 | 109 | `, 'test.svelte'); 110 | }); 111 | 112 | test('preprocesses components', async () => { 113 | const p = plugin({ 114 | preprocess: { 115 | markup: ({ content, filename }) => { 116 | return { 117 | code: content 118 | .replace('__REPLACEME__', 'replaced') 119 | .replace('__FILENAME__', filename), 120 | dependencies: ['foo'], 121 | }; 122 | }, 123 | style: () => null, 124 | } 125 | }); 126 | 127 | const { code, dependencies } = await p.transform(` 128 |i am a widget
-------------------------------------------------------------------------------- /test/node_modules/widgets/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rixo/rollup-plugin-svelte-hot/7250e214c158e0e884dd9ca013f324ce9911f47d/test/node_modules/widgets/index.js -------------------------------------------------------------------------------- /test/node_modules/widgets/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "./index.js", 3 | "svelte.root": "src" 4 | } -------------------------------------------------------------------------------- /test/node_modules/widgets/src/Foo.html: -------------------------------------------------------------------------------- 1 |i am a widget
-------------------------------------------------------------------------------- /test/sourcemap-test/index.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /test/sourcemap-test/src/Bar.svelte: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | -------------------------------------------------------------------------------- /test/sourcemap-test/src/Foo.svelte: -------------------------------------------------------------------------------- 1 |red
2 |