diff --git a/README.md b/README.md index df7dc565..be9452b2 100644 --- a/README.md +++ b/README.md @@ -196,8 +196,29 @@ Or, on a global basis by adding `{noPreserveState: true}` to `hotOptions`. For e **Please Note:** If you are using `svelte/store`, `noPreserveState` has no effect on `store` properties. Neither locally, nor globally. +#### External Dependencies +If you rely on any external dependencies (files required in a preprocessor for example) you might want to watch these files for changes and re-run svelte compile. +Webpack allows [loader dependencies](https://webpack.js.org/contribute/writing-a-loader/#loader-dependencies) to trigger a recompile. svelte-loader exposes this API via `options.externalDependencies`. + For example: + +```js +... +const variables = path.resolve('./variables.js'); +... +{ + test: /\.(html|svelte)$/, + use: [ + { + loader: 'svelte-loader', + options: { + externalDependencies: [variables] + } + } + ] + } +``` ## License diff --git a/index.js b/index.js index 3cac4d73..8ab13cce 100644 --- a/index.js +++ b/index.js @@ -99,6 +99,7 @@ module.exports = function(source, map) { if (!('name' in options)) options.name = capitalize(sanitize(options.filename)); if (!('onwarn' in options)) options.onwarn = warning => this.emitWarning(new Error(warning)); if (options.emitCss) options.css = false; + if (options.externalDependencies) options.externalDependencies.forEach(dep => this.addDependency(dep)); deprecatePreprocessOptions(options); options.preprocess.filename = options.filename;