Skip to content

Commit

Permalink
Move compiler options under compilerOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Jan 16, 2021
1 parent 69b1b94 commit cecdb42
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* Breaking: dropped Svelte 2 support ([#150](https://github.com/sveltejs/svelte-loader/pull/150))
* Breaking: dropped Node 8 support ([#157](https://github.com/sveltejs/svelte-loader/pull/157))
* Breaking: compiler options must now be specified under `compilerOptions` ([#158](https://github.com/sveltejs/svelte-loader/pull/158))
* Add Webpack 5 support ([#151](https://github.com/sveltejs/svelte-loader/pull/151))
* Replace broken Svelte 2 HMR with the implementation from `rixo/svelte-loader-hot` ([#156](https://github.com/sveltejs/svelte-loader/pull/156))
* Add Node 14 support and fix intermittent crashes when using `cache-loader` in front of `svelte-loader` ([#125](https://github.com/sveltejs/svelte-loader/pull/125))
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,12 @@ module.exports = {
use: {
loader: 'svelte-loader',
options: {
// NOTE Svelte's dev mode MUST be enabled for HMR to work
// -- in a real config, you'd probably set it to false for prod build,
// based on a env variable or so
dev: true,
compilerOptions: {
// NOTE Svelte's dev mode MUST be enabled for HMR to work
// -- in a real config, you'd probably set it to false for prod build,
// based on a env variable or so
dev: true,
},

// NOTE emitCss: true is currently not supported with HMR
// Enable it for production to output separate css file
Expand Down
25 changes: 4 additions & 21 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,6 @@ const { getOptions } = require('loader-utils');
const { makeHot } = require('./lib/make-hot.js');
const { compile, preprocess } = require('svelte/compiler');

const pluginOptions = {
hotReload: true,
hotOptions: true,
preprocess: true,
emitCss: true,

// legacy
onwarn: true,
style: true,
script: true,
markup: true
};

function posixify(file) {
return file.replace(/[/\\]/g, '/');
}
Expand Down Expand Up @@ -66,22 +53,18 @@ module.exports = function(source, map) {
return;
}

const isServer = this.target === 'node' || (options.generate && options.generate == 'ssr');
const isServer = this.target === 'node' || (options.compilerOptions && options.compilerOptions.generate == 'ssr');
const isProduction = this.minimize || process.env.NODE_ENV === 'production';

const compileOptions = {
filename: this.resourcePath,
format: options.format || 'esm'
css: !options.emitCss,
...options.compilerOptions,
format: (options.compilerOptions && options.compilerOptions.format) || 'esm'
};

const handleWarning = warning => this.emitWarning(new Error(warning));

for (const option in options) {
if (!pluginOptions[option]) compileOptions[option] = options[option];
}

if (options.emitCss) compileOptions.css = false;

deprecatePreprocessOptions(options);
options.preprocess.filename = compileOptions.filename;

Expand Down
8 changes: 4 additions & 4 deletions test/loader.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ describe('loader', () => {
expect(err).not.to.exist;
expect(code).not.to.contain('function add_css()');
},
{ css: false }
{ compilerOptions: { css: false } }
)
);
});
Expand All @@ -164,7 +164,7 @@ describe('loader', () => {
expect(code).to.contain('import {');
expect(code).to.contain('custom-svelte/internal');
},
{ sveltePath: 'custom-svelte' }
{ compilerOptions: { sveltePath: 'custom-svelte' } }
)
);
});
Expand All @@ -190,7 +190,7 @@ describe('loader', () => {

expect(code).to.contain('create_ssr_component');
},
{ generate: 'ssr' }
{ compilerOptions: { generate: 'ssr' } }
)
);
});
Expand Down Expand Up @@ -357,7 +357,7 @@ describe('loader', () => {
},
{
hotReload: true,
generate: 'ssr'
compilerOptions: { generate: 'ssr' }
}
)
);
Expand Down

0 comments on commit cecdb42

Please sign in to comment.