Skip to content

Commit

Permalink
Update to latest Svelte-HMR (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
halfnelson authored May 15, 2021
1 parent 97abbbd commit bc49318
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# svelte-loader changelog

## Unreleased

* Update to latest `svelte-hmr` package fixing Webpack 4 support

## 3.1.1

* Fix empty sourcesContent ([#177](https://github.com/sveltejs/svelte-loader/pull/177))
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { relative } = require('path');
const { getOptions } = require('loader-utils');
const { makeHot } = require('./lib/make-hot.js');
const { buildMakeHot } = require('./lib/make-hot.js');
const { compile, preprocess } = require('svelte/compiler');

function posixify(file) {
Expand Down Expand Up @@ -60,6 +60,7 @@ module.exports = function(source, map) {

if (options.hotReload && !isProduction && !isServer) {
const hotOptions = { ...options.hotOptions };
const makeHot = buildMakeHot(hotOptions);
const id = JSON.stringify(relative(process.cwd(), compileOptions.filename));
js.code = makeHot(id, js.code, hotOptions, compiled, source, compileOptions);
}
Expand Down
5 changes: 3 additions & 2 deletions lib/make-hot.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ const { createMakeHot } = require('svelte-hmr');

const hotApi = require.resolve('./hot-api.js');

const makeHot = createMakeHot({
const buildMakeHot = (hotOptions) => createMakeHot({
walk,
meta: 'module',
hotApi,
hotOptions
});

module.exports.makeHot = makeHot;
module.exports.buildMakeHot = buildMakeHot;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dependencies": {
"loader-utils": "^2.0.0",
"svelte-dev-helper": "^1.1.9",
"svelte-hmr": "^0.12.3"
"svelte-hmr": "^0.14.2"
},
"devDependencies": {
"chai": "^4.2.0",
Expand Down
6 changes: 3 additions & 3 deletions test/loader.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ describe('loader', () => {
expect(err).not.to.exist;

expect(code).to.contain('module && module.hot');
expect(code).not.to.contain('"noPreserveState":true');
expect(code).not.to.contain('"preserveLocalState":true');
},
{ hotReload: true }
)
Expand All @@ -306,12 +306,12 @@ describe('loader', () => {
expect(err).not.to.exist;

expect(code).to.contain('module && module.hot');
expect(code).to.contain('"noPreserveState":true');
expect(code).to.contain('"preserveLocalState":true');
},
{
hotReload: true,
hotOptions: {
noPreserveState: true
preserveLocalState: true
}
}
)
Expand Down

0 comments on commit bc49318

Please sign in to comment.