rollup-plugin-svelte
Advanced tools
Comparing version 5.2.3 to 6.0.0
# rollup-plugin-svelte changelog | ||
## 6.0.0 | ||
* Breaking changes: | ||
* Rollup 1.19.2+ is now required | ||
* The path passed to `css.write()` is now relative to the destination directory. | ||
* Other changes: | ||
* 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)) | ||
* Use Rollup's `emitFile` API ([#72](https://github.com/sveltejs/rollup-plugin-svelte/pull/72)) | ||
* Warn when `package.json` does not expose itself via `exports` ([#119](https://github.com/sveltejs/rollup-plugin-svelte/pull/119)) | ||
## 5.2.3 | ||
@@ -4,0 +14,0 @@ |
import { Plugin, RollupWarning } from 'rollup'; | ||
import { PreprocessorGroup } from 'svelte/types/compiler/preprocess'; | ||
interface PreprocessOptions extends Record<string, (...args: any[]) => void> {} | ||
interface Css { | ||
@@ -10,4 +9,5 @@ code: any; | ||
class CssWriter { | ||
declare class CssWriter { | ||
code: string; | ||
filename: string; | ||
map: { | ||
@@ -22,2 +22,3 @@ version: number; | ||
warn: RollupWarning; | ||
emit(fileName: string, source: string): void; | ||
write(dest: string, map: boolean): void; | ||
@@ -53,4 +54,3 @@ toString(): string; | ||
*/ | ||
// this isn't used yet in plugin | ||
// generate?: 'ssr'; | ||
generate?: 'dom' | 'ssr' | false; | ||
@@ -61,3 +61,3 @@ /** | ||
*/ | ||
preprocess?: PreprocessOptions; | ||
preprocess?: PreprocessorGroup | PreprocessorGroup[]; | ||
// { | ||
@@ -80,3 +80,10 @@ // style: ({ content }) => { | ||
/** | ||
* Compile Svelte components to custom elements (aka web components). | ||
* @default false | ||
*/ | ||
customElement?: boolean; | ||
/** | ||
* let Rollup handle all other warnings normally | ||
@@ -83,0 +90,0 @@ */ |
52
index.js
@@ -9,2 +9,3 @@ const fs = require('fs'); | ||
const major_version = +version[0]; | ||
const pkg_export_errors = new Set(); | ||
@@ -54,2 +55,6 @@ const { compile, preprocess } = major_version >= 3 | ||
if (err.code === 'MODULE_NOT_FOUND') return null; | ||
if (err.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED') { | ||
pkg_export_errors.add(pkg.replace(/\/package.json$/, '')); | ||
return null; | ||
} | ||
throw err; | ||
@@ -69,18 +74,8 @@ } | ||
function mkdirp(dir) { | ||
const parent = path.dirname(dir); | ||
if (parent === dir) return; | ||
mkdirp(parent); | ||
try { | ||
fs.mkdirSync(dir); | ||
} catch (err) { | ||
if (err.code !== 'EEXIST') throw err; | ||
} | ||
} | ||
class CssWriter { | ||
constructor (code, map, warn) { | ||
constructor(code, filename, map, warn, toAsset) { | ||
this.code = code; | ||
this.filename = filename; | ||
this.emit = toAsset; | ||
this.warn = warn; | ||
this.map = { | ||
@@ -94,14 +89,10 @@ version: 3, | ||
}; | ||
this.warn = warn; | ||
} | ||
write(dest, map) { | ||
dest = path.resolve(dest); | ||
mkdirp(path.dirname(dest)); | ||
write(dest = this.filename, map) { | ||
const basename = path.basename(dest); | ||
if (map !== false) { | ||
fs.writeFileSync(dest, `${this.code}\n/*# sourceMappingURL=${basename}.map */`); | ||
fs.writeFileSync(`${dest}.map`, JSON.stringify({ | ||
this.emit(dest, `${this.code}\n/*# sourceMappingURL=${basename}.map */`); | ||
this.emit(`${dest}.map`, JSON.stringify({ | ||
version: 3, | ||
@@ -113,5 +104,5 @@ file: basename, | ||
mappings: this.map.mappings | ||
}, null, ' ')); | ||
}, null, 2)); | ||
} else { | ||
fs.writeFileSync(dest, this.code); | ||
this.emit(dest, this.code); | ||
} | ||
@@ -300,3 +291,3 @@ } | ||
}, | ||
generateBundle() { | ||
generateBundle(options, bundle) { | ||
if (css) { | ||
@@ -336,12 +327,21 @@ // write out CSS file. TODO would be nice if there was a | ||
const writer = new CssWriter(result, { | ||
const filename = Object.keys(bundle)[0].split('.').shift() + '.css'; | ||
const writer = new CssWriter(result, filename, { | ||
sources, | ||
sourcesContent, | ||
mappings: encode(mappings) | ||
}, this.warn); | ||
}, this.warn, (fileName, source) => { | ||
this.emitFile({ type: 'asset', fileName, source }); | ||
}); | ||
css(writer); | ||
} | ||
if (pkg_export_errors.size < 1) return; | ||
console.warn('\nrollup-plugin-svelte: The following packages did not export their `package.json` file so we could not check the `svelte` field. If you had difficulties importing svelte components from a package, then please contact the author and ask them to export the package.json file.\n'); | ||
console.warn(Array.from(pkg_export_errors).map(s => `- ${s}`).join('\n') + '\n'); | ||
} | ||
}; | ||
}; |
{ | ||
"name": "rollup-plugin-svelte", | ||
"version": "5.2.3", | ||
"version": "6.0.0", | ||
"description": "Compile Svelte components with Rollup", | ||
@@ -14,4 +14,4 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "mocha", | ||
"lint": "eslint index.js", | ||
"test": "node test/index.js", | ||
"prepublishOnly": "npm run lint && npm test" | ||
@@ -33,7 +33,7 @@ }, | ||
"locate-character": "^2.0.5", | ||
"mocha": "^7.1.1", | ||
"rollup": "^0.67.4", | ||
"rollup": "^1.32.1", | ||
"sander": "^0.6.0", | ||
"source-map": "^0.7.3", | ||
"svelte": "^3.0.0-beta.5" | ||
"svelte": "^3.24.0", | ||
"uvu": "^0.3.1" | ||
}, | ||
@@ -47,4 +47,4 @@ "dependencies": { | ||
"svelte": "*", | ||
"rollup": ">=0.60.0" | ||
"rollup": ">=1.19.2" | ||
} | ||
} |
@@ -19,3 +19,2 @@ # rollup-plugin-svelte | ||
// rollup.config.js | ||
import * as fs from 'fs'; | ||
import svelte from 'rollup-plugin-svelte'; | ||
@@ -57,2 +56,6 @@ | ||
// You can optionally set 'customElement' to 'true' to compile | ||
// your components to custom elements (aka web elements) | ||
customElement: false, | ||
// Extract CSS into a separate file (recommended). | ||
@@ -64,5 +67,6 @@ // See note below | ||
// creates `main.css` and `main.css.map` — pass `false` | ||
// as the second argument if you don't want the sourcemap | ||
css.write('public/main.css'); | ||
// creates `main.css` and `main.css.map` | ||
// using a falsy name will default to the bundle name | ||
// — pass `false` as the second argument if you don't want the sourcemap | ||
css.write('main.css'); | ||
}, | ||
@@ -69,0 +73,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22622
362
133