Skip to content

Commit 9fc9f80

Browse files
authored
Merge pull request #66 from rob-balfre/master
added options.externalDependencies
2 parents 0f34526 + b154c36 commit 9fc9f80

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

README.md

+21
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,29 @@ Or, on a global basis by adding `{noPreserveState: true}` to `hotOptions`. For e
196196

197197
**Please Note:** If you are using `svelte/store`, `noPreserveState` has no effect on `store` properties. Neither locally, nor globally.
198198

199+
#### External Dependencies
199200

201+
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.
200202

203+
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`.
204+
For example:
205+
206+
```js
207+
...
208+
const variables = path.resolve('./variables.js');
209+
...
210+
{
211+
test: /\.(html|svelte)$/,
212+
use: [
213+
{
214+
loader: 'svelte-loader',
215+
options: {
216+
externalDependencies: [variables]
217+
}
218+
}
219+
]
220+
}
221+
```
201222

202223
## License
203224

index.js

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ module.exports = function(source, map) {
9999
if (!('name' in options)) options.name = capitalize(sanitize(options.filename));
100100
if (!('onwarn' in options)) options.onwarn = warning => this.emitWarning(new Error(warning));
101101
if (options.emitCss) options.css = false;
102+
if (options.externalDependencies) options.externalDependencies.forEach(dep => this.addDependency(dep));
102103

103104
deprecatePreprocessOptions(options);
104105
options.preprocess.filename = options.filename;

0 commit comments

Comments
 (0)