You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* break: remove `css` option
* windows
* Do not inline sourcemap
* Default emitCss to true
* chore: purge unused test files
* chore: add quotes in test name
* fix: define `emitCss` default on assignment
Co-authored-by: Ben McCann <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+4-21Lines changed: 4 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -49,25 +49,13 @@ export default {
49
49
}
50
50
},
51
51
52
-
// Emit CSS as "files" for other plugins to process
53
-
emitCss:true,
52
+
// Emit CSS as "files" for other plugins to process. default is true
53
+
emitCss:false,
54
54
55
55
// You can optionally set 'customElement' to 'true' to compile
56
56
// your components to custom elements (aka web elements)
57
57
customElement:false,
58
58
59
-
// Extract CSS into a single bundled file (recommended).
60
-
// See note below
61
-
css:function (css) {
62
-
console.log(css.code); // the concatenated CSS
63
-
console.log(css.map); // a sourcemap
64
-
65
-
// creates `main.css` and `main.css.map`
66
-
// using a falsy name will default to the bundle name
67
-
// — pass `false` as the second argument if you don't want the sourcemap
68
-
css.write('main.css');
69
-
},
70
-
71
59
// Warnings are normally passed straight to Rollup. You can
72
60
// optionally handle them here, for example to squelch
73
61
// warnings with a particular code
@@ -118,14 +106,9 @@ and so on. Then, in `package.json`, set the `svelte` property to point to this `
118
106
119
107
## Extracting CSS
120
108
121
-
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.
122
-
123
-
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.
124
-
125
-
If you have other plugins processing your CSS (e.g. rollup-plugin-scss), and want your styles passed through to them to be bundled together, you can use `emitCss: true`.
126
-
127
-
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`.
109
+
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`](https://www.npmjs.com/package/rollup-plugin-css-only), [`rollup-plugin-postcss`](https://www.npmjs.com/package/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.
128
110
111
+
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.
this.warn('[DEPRECATION] As of rollup-plugin-svelte@3, the argument to the `css` function is an object, not a string — use `css.write(file)`. Consult the documentation for more information: https://github.com/rollup/rollup-plugin-svelte');
* Write to CSS file if given `options.css` function.
207
-
* TODO: is there a better way to concat/append into Rollup asset?
129
+
* All resolutions done; display warnings wrt `package.json` access.
208
130
*/
209
-
generateBundle(config,bundle){
131
+
generateBundle(){
210
132
if(pkg_export_errors.size>0){
211
133
console.warn(`\n${PREFIX} 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`);
0 commit comments