diff --git a/index.js b/index.js index a2f3e1da..831bb07e 100644 --- a/index.js +++ b/index.js @@ -103,7 +103,7 @@ module.exports = function(source, map) { const compiled = compile(processed.toString(), compileOptions); let { js, css, warnings } = compiled; - if (!js.map.sourcesContent) { + if (js.map && !js.map.sourcesContent) { js.map.sourcesContent = [source]; js.map.sources = [compileOptions.filename]; } @@ -124,7 +124,9 @@ module.exports = function(source, map) { if (options.emitCss && css.code) { const resource = posixify(compileOptions.filename); const cssPath = `${resource}.${index++}.css`; - css.code += '\n/*# sourceMappingURL=' + css.map.toUrl() + '*/'; + if (css.map) { + css.code += '\n/*# sourceMappingURL=' + css.map.toUrl() + '*/'; + } js.code += `\nimport '${cssPath}!=!svelte-loader?cssPath=${cssPath}!${resource}'\n;`; virtualModules.set(cssPath, css.code); } diff --git a/test/loader.spec.js b/test/loader.spec.js index 4d8d2fbb..2acac63f 100644 --- a/test/loader.spec.js +++ b/test/loader.spec.js @@ -164,6 +164,34 @@ describe('loader', () => { { compilerOptions: { css: false } } ) ); + + it( + 'should configure css with dev sourcemaps', + testLoader( + 'test/fixtures/css.html', + function(err, code, map) { + expect(err).not.to.exist; + expect(code).to.contain('function add_css(target)'); + expect(code).to.contain('/*# sourceMappingURL='); + expect(map).to.exist; + }, + { compilerOptions: { dev: true, enableSourcemap: true } } + ) + ); + + it( + 'should configure css without dev sourcemaps', + testLoader( + 'test/fixtures/css.html', + function(err, code, map) { + expect(err).not.to.exist; + expect(code).to.contain('function add_css(target)'); + expect(code).not.to.contain('/*# sourceMappingURL='); + expect(map).to.exist; + }, + { compilerOptions: { dev: true, enableSourcemap: { css: false, js: true } } } + ) + ); }); describe('sveltePath', () => { @@ -234,6 +262,19 @@ describe('loader', () => { { emitCss: true } ) ); + + it( + 'should configure emitCss=true without css sourcemaps', + testLoader( + 'test/fixtures/css.html', + function(err, code, map) { + expect(err).not.to.exist; + + expect(code).to.match(/!=!svelte-loader\?cssPath=/); + }, + { emitCss: true, compilerOptions: { enableSourcemap: { css: false, js: true } } } + ) + ); }); describe('preprocess', () => { @@ -354,6 +395,21 @@ describe('loader', () => { ) ); }); + + describe('compilerOptions', () => { + it( + 'should configure enableSourcemap=false', + testLoader( + 'test/fixtures/good.html', + function(err, code, map) { + expect(err).not.to.exist; + expect(code).to.exist; + expect(map).not.to.exist; + }, + { compilerOptions: { enableSourcemap: false } } + ), + ); + }); }); });