svelte-loader
Advanced tools
Comparing version 3.1.9 to 3.2.0
44
index.js
@@ -5,3 +5,3 @@ const path = require('path'); | ||
const { buildMakeHot } = require('./lib/make-hot.js'); | ||
const { compile, preprocess, VERSION } = require('svelte/compiler'); | ||
const svelte = require('svelte/compiler'); | ||
@@ -59,2 +59,6 @@ function posixify(file) { | ||
function getMajor() { | ||
return Number(svelte.VERSION.split('.')[0]) | ||
} | ||
module.exports = function(source, map) { | ||
@@ -75,9 +79,33 @@ this.cacheable(); | ||
const isProduction = this.minimize || process.env.NODE_ENV === 'production'; | ||
const compileOptions = { | ||
filename: this.resourcePath, | ||
css: VERSION[0] === '3' ? !options.emitCss : (options.emitCss ? 'external' : 'injected'), | ||
css: getMajor() === 3 ? !options.emitCss : (options.emitCss ? 'external' : 'injected'), | ||
...options.compilerOptions | ||
}; | ||
if (VERSION[0] === '3') { | ||
const handleWarning = warning => this.emitWarning(new Error(warning)); | ||
if (getMajor() >= 5 && (this.resourcePath.endsWith('.svelte.js') || this.resourcePath.endsWith('.svelte.ts'))) { | ||
try { | ||
const { js, warnings } = svelte.compileModule( | ||
source, | ||
{ filename: this.resourcePath, dev: compileOptions.dev, generate: compileOptions.generate } | ||
); | ||
warnings.forEach( | ||
options.onwarn | ||
? warning => options.onwarn(warning, handleWarning) | ||
: handleWarning | ||
); | ||
callback(null, js.code, js.map); | ||
} catch (err) { | ||
// wrap error to provide correct | ||
// context when logging to console | ||
callback(new Error(`${err.name}: ${err.toString()}`)); | ||
} | ||
return; | ||
} | ||
if (getMajor() === 3) { | ||
compileOptions.format = (options.compilerOptions && options.compilerOptions.format) || 'esm'; | ||
@@ -92,8 +120,6 @@ } else { | ||
const handleWarning = warning => this.emitWarning(new Error(warning)); | ||
options.preprocess = options.preprocess || {}; | ||
options.preprocess.filename = compileOptions.filename; | ||
preprocess(source, options.preprocess).then(processed => { | ||
svelte.preprocess(source, options.preprocess).then(processed => { | ||
if (processed.dependencies && this.addDependency) { | ||
@@ -107,3 +133,3 @@ for (let dependency of processed.dependencies) { | ||
const compiled = compile(processed.toString(), compileOptions); | ||
const compiled = svelte.compile(processed.toString(), compileOptions); | ||
let { js, css, warnings } = compiled; | ||
@@ -129,3 +155,3 @@ | ||
if (options.emitCss && css.code) { | ||
if (options.emitCss && css && css.code) { | ||
const resource = posixify(compileOptions.filename); | ||
@@ -132,0 +158,0 @@ const cssPath = `${resource}.${index++}.css`; |
{ | ||
"name": "svelte-loader", | ||
"version": "3.1.9", | ||
"version": "3.2.0", | ||
"author": "Nico Rehwaldt <git_nikku@nixis.de>", | ||
@@ -32,3 +32,3 @@ "description": "A webpack loader for svelte", | ||
"peerDependencies": { | ||
"svelte": "^3.0.0 || ^4.0.0-next.0" | ||
"svelte": "^3.0.0 || ^4.0.0-next.0 || ^5.0.0-next.1" | ||
}, | ||
@@ -35,0 +35,0 @@ "repository": { |
@@ -25,5 +25,5 @@ > Undecided yet what bundler to use? We suggest using [SvelteKit](https://kit.svelte.dev), or Vite with [vite-plugin-svelte](https://github.com/sveltejs/vite-plugin-svelte/). | ||
// see below for an explanation | ||
// alias: { | ||
// svelte: path.resolve('node_modules', 'svelte/src/runtime') // Svelte 3: path.resolve('node_modules', 'svelte') | ||
// }, | ||
alias: { | ||
svelte: path.resolve('node_modules', 'svelte/src/runtime') // Svelte 3: path.resolve('node_modules', 'svelte') | ||
}, | ||
extensions: ['.mjs', '.js', '.svelte'], | ||
@@ -57,3 +57,3 @@ mainFields: ['svelte', 'browser', 'module', 'main'], | ||
The [`resolve.alias`](https://webpack.js.org/configuration/resolve/#resolvealias) option is used to make sure that only one copy of the Svelte runtime is bundled in the app, even if you are `npm link`ing in dependencies with their own copy of the `svelte` package. Having multiple copies of the internal scheduler in an app, besides being inefficient, can also cause various problems. It's commented out because you rarely should need this and it's brittle since it relies on the internal structure of the Svelte package, which can change. | ||
The [`resolve.alias`](https://webpack.js.org/configuration/resolve/#resolvealias) option is used to make sure that only one copy of the Svelte runtime is bundled in the app, even if you are `npm link`ing in dependencies with their own copy of the `svelte` package. Having multiple copies of the internal scheduler in an app, besides being inefficient, can also cause various problems. | ||
@@ -60,0 +60,0 @@ ### resolve.mainFields |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22298
238