Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move compiler options under compilerOptions #159

Merged
merged 2 commits into from
Jan 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"extends": "eslint:recommended",
"parserOptions": {
ecmaVersion: 9,
"sourceType": "module"
},
"plugins": [
Expand Down
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` ([#159](https://github.com/sveltejs/svelte-loader/pull/159))
* 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
Loading