Skip to content

Commit f7e5eec

Browse files
authored
Add code comments (#130)
1 parent f570b49 commit f7e5eec

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default {
5656
// your components to custom elements (aka web elements)
5757
customElement: false,
5858

59-
// Extract CSS into a separate file (recommended).
59+
// Extract CSS into a single bundled file (recommended).
6060
// See note below
6161
css: function (css) {
6262
console.log(css.code); // the concatenated CSS

index.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ module.exports = function svelte(options = {}) {
141141
? options.css
142142
: null;
143143

144+
// A map from css filename to css contents
145+
// If css: true we output all contents
146+
// If emitCss: true we virtually resolve these imports
144147
const cssLookup = new Map();
145148

146149
if (css || options.emitCss) {
@@ -150,11 +153,17 @@ module.exports = function svelte(options = {}) {
150153
return {
151154
name: 'svelte',
152155

156+
/**
157+
* Returns CSS contents for an id
158+
*/
153159
load(id) {
154160
if (!cssLookup.has(id)) return null;
155161
return cssLookup.get(id);
156162
},
157163

164+
/**
165+
* Returns id for import
166+
*/
158167
resolveId(importee, importer) {
159168
if (cssLookup.has(importee)) { return importee; }
160169
if (!importer || importee[0] === '.' || importee[0] === '\0' || path.isAbsolute(importee))
@@ -189,6 +198,10 @@ module.exports = function svelte(options = {}) {
189198
}
190199
},
191200

201+
/**
202+
* Transforms a .svelte file into a .js file
203+
* Adds a static import for virtual css file when emitCss: true
204+
*/
192205
transform(code, id) {
193206
if (!filter(id)) return null;
194207

@@ -283,10 +296,12 @@ module.exports = function svelte(options = {}) {
283296
return compiled.js;
284297
});
285298
},
299+
/**
300+
* If css: true then outputs a single file with all CSS bundled together
301+
*/
286302
generateBundle(options, bundle) {
287303
if (css) {
288-
// write out CSS file. TODO would be nice if there was a
289-
// a more idiomatic way to do this in Rollup
304+
// TODO would be nice if there was a more idiomatic way to do this in Rollup
290305
let result = '';
291306

292307
const mappings = [];

0 commit comments

Comments
 (0)