Skip to content

Commit cecdb42

Browse files
committed
Move compiler options under compilerOptions
1 parent 69b1b94 commit cecdb42

File tree

4 files changed

+15
-29
lines changed

4 files changed

+15
-29
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* Breaking: dropped Svelte 2 support ([#150](https://github.com/sveltejs/svelte-loader/pull/150))
66
* Breaking: dropped Node 8 support ([#157](https://github.com/sveltejs/svelte-loader/pull/157))
7+
* Breaking: compiler options must now be specified under `compilerOptions` ([#158](https://github.com/sveltejs/svelte-loader/pull/158))
78
* Add Webpack 5 support ([#151](https://github.com/sveltejs/svelte-loader/pull/151))
89
* Replace broken Svelte 2 HMR with the implementation from `rixo/svelte-loader-hot` ([#156](https://github.com/sveltejs/svelte-loader/pull/156))
910
* 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))

README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,12 @@ module.exports = {
161161
use: {
162162
loader: 'svelte-loader',
163163
options: {
164-
// NOTE Svelte's dev mode MUST be enabled for HMR to work
165-
// -- in a real config, you'd probably set it to false for prod build,
166-
// based on a env variable or so
167-
dev: true,
164+
compilerOptions: {
165+
// NOTE Svelte's dev mode MUST be enabled for HMR to work
166+
// -- in a real config, you'd probably set it to false for prod build,
167+
// based on a env variable or so
168+
dev: true,
169+
},
168170

169171
// NOTE emitCss: true is currently not supported with HMR
170172
// Enable it for production to output separate css file

index.js

+4-21
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,6 @@ const { getOptions } = require('loader-utils');
33
const { makeHot } = require('./lib/make-hot.js');
44
const { compile, preprocess } = require('svelte/compiler');
55

6-
const pluginOptions = {
7-
hotReload: true,
8-
hotOptions: true,
9-
preprocess: true,
10-
emitCss: true,
11-
12-
// legacy
13-
onwarn: true,
14-
style: true,
15-
script: true,
16-
markup: true
17-
};
18-
196
function posixify(file) {
207
return file.replace(/[/\\]/g, '/');
218
}
@@ -66,22 +53,18 @@ module.exports = function(source, map) {
6653
return;
6754
}
6855

69-
const isServer = this.target === 'node' || (options.generate && options.generate == 'ssr');
56+
const isServer = this.target === 'node' || (options.compilerOptions && options.compilerOptions.generate == 'ssr');
7057
const isProduction = this.minimize || process.env.NODE_ENV === 'production';
7158

7259
const compileOptions = {
7360
filename: this.resourcePath,
74-
format: options.format || 'esm'
61+
css: !options.emitCss,
62+
...options.compilerOptions,
63+
format: (options.compilerOptions && options.compilerOptions.format) || 'esm'
7564
};
7665

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

79-
for (const option in options) {
80-
if (!pluginOptions[option]) compileOptions[option] = options[option];
81-
}
82-
83-
if (options.emitCss) compileOptions.css = false;
84-
8568
deprecatePreprocessOptions(options);
8669
options.preprocess.filename = compileOptions.filename;
8770

test/loader.spec.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ describe('loader', () => {
148148
expect(err).not.to.exist;
149149
expect(code).not.to.contain('function add_css()');
150150
},
151-
{ css: false }
151+
{ compilerOptions: { css: false } }
152152
)
153153
);
154154
});
@@ -164,7 +164,7 @@ describe('loader', () => {
164164
expect(code).to.contain('import {');
165165
expect(code).to.contain('custom-svelte/internal');
166166
},
167-
{ sveltePath: 'custom-svelte' }
167+
{ compilerOptions: { sveltePath: 'custom-svelte' } }
168168
)
169169
);
170170
});
@@ -190,7 +190,7 @@ describe('loader', () => {
190190

191191
expect(code).to.contain('create_ssr_component');
192192
},
193-
{ generate: 'ssr' }
193+
{ compilerOptions: { generate: 'ssr' } }
194194
)
195195
);
196196
});
@@ -357,7 +357,7 @@ describe('loader', () => {
357357
},
358358
{
359359
hotReload: true,
360-
generate: 'ssr'
360+
compilerOptions: { generate: 'ssr' }
361361
}
362362
)
363363
);

0 commit comments

Comments
 (0)