Skip to content

Commit a90bcb4

Browse files
authored
fix: handle disabled sourcemaps (#236)
1 parent c8a786f commit a90bcb4

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ module.exports = function(source, map) {
129129
const compiled = svelte.compile(processed.toString(), compileOptions);
130130
let { js, css, warnings } = compiled;
131131

132-
if (!js.map.sourcesContent) {
132+
if (js.map && !js.map.sourcesContent) {
133133
js.map.sourcesContent = [source];
134134
js.map.sources = [compileOptions.filename];
135135
}
@@ -150,7 +150,9 @@ module.exports = function(source, map) {
150150
if (options.emitCss && css && css.code) {
151151
const resource = posixify(compileOptions.filename);
152152
const cssPath = `${resource}.${index++}.css`;
153-
css.code += '\n/*# sourceMappingURL=' + css.map.toUrl() + '*/';
153+
if (css.map) {
154+
css.code += '\n/*# sourceMappingURL=' + css.map.toUrl() + '*/';
155+
}
154156
js.code += `\nimport '${cssPath}!=!svelte-loader?cssPath=${cssPath}!${resource}'\n;`;
155157
virtualModules.set(cssPath, css.code);
156158
}

test/loader.spec.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,34 @@ describe('loader', () => {
164164
{ compilerOptions: { css: false } }
165165
)
166166
);
167+
168+
it(
169+
'should configure css with dev sourcemaps',
170+
testLoader(
171+
'test/fixtures/css.html',
172+
function(err, code, map) {
173+
expect(err).not.to.exist;
174+
expect(code).to.contain('function add_css(target)');
175+
expect(code).to.contain('/*# sourceMappingURL=');
176+
expect(map).to.exist;
177+
},
178+
{ compilerOptions: { dev: true, enableSourcemap: true } }
179+
)
180+
);
181+
182+
it(
183+
'should configure css without dev sourcemaps',
184+
testLoader(
185+
'test/fixtures/css.html',
186+
function(err, code, map) {
187+
expect(err).not.to.exist;
188+
expect(code).to.contain('function add_css(target)');
189+
expect(code).not.to.contain('/*# sourceMappingURL=');
190+
expect(map).to.exist;
191+
},
192+
{ compilerOptions: { dev: true, enableSourcemap: { css: false, js: true } } }
193+
)
194+
);
167195
});
168196

169197
describe('sveltePath', () => {
@@ -234,6 +262,19 @@ describe('loader', () => {
234262
{ emitCss: true }
235263
)
236264
);
265+
266+
it(
267+
'should configure emitCss=true without css sourcemaps',
268+
testLoader(
269+
'test/fixtures/css.html',
270+
function(err, code, map) {
271+
expect(err).not.to.exist;
272+
273+
expect(code).to.match(/!=!svelte-loader\?cssPath=/);
274+
},
275+
{ emitCss: true, compilerOptions: { enableSourcemap: { css: false, js: true } } }
276+
)
277+
);
237278
});
238279

239280
describe('preprocess', () => {
@@ -354,6 +395,21 @@ describe('loader', () => {
354395
)
355396
);
356397
});
398+
399+
describe('compilerOptions', () => {
400+
it(
401+
'should configure enableSourcemap=false',
402+
testLoader(
403+
'test/fixtures/good.html',
404+
function(err, code, map) {
405+
expect(err).not.to.exist;
406+
expect(code).to.exist;
407+
expect(map).not.to.exist;
408+
},
409+
{ compilerOptions: { enableSourcemap: false } }
410+
),
411+
);
412+
});
357413
});
358414

359415
// needs Svelte 5

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy