Skip to content

Commit

Permalink
Add support for HMR with elm-hot
Browse files Browse the repository at this point in the history
  • Loading branch information
ktosiek committed Dec 8, 2018
1 parent d2dc7c9 commit 72f10f9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/assets/ElmAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class ElmAsset extends Asset {
constructor(name, options) {
super(name, options);
this.type = 'js';
this.hmrPageReload = true;
}

async parse() {
Expand Down Expand Up @@ -46,6 +45,10 @@ class ElmAsset extends Asset {

let compiled = await this.elm.compileToString(this.name, options);
this.contents = compiled.toString();
if (this.options.hmr) {
let {inject} = await localRequire('elm-hot', this.name);
this.contents = inject(this.contents);
}
}

async collectDependencies() {
Expand Down
14 changes: 14 additions & 0 deletions test/elm.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ describe('elm', function() {
assert.equal(typeof output().Elm.Main.init, 'function');
});

it('should apply elm-hot if HMR is enabled', async function() {
let b = await bundle(__dirname + '/integration/elm/index.js', {
hmr: true
});

await assertBundleTree(b, {
type: 'js',
assets: ['Main.elm', 'hmr-runtime.js', 'index.js']
});

let js = await fs.readFile(__dirname + '/dist/index.js', 'utf8');
assert(js.includes('[elm-hot]'));
});

it('should minify Elm in production mode', async function() {
let b = await bundle(__dirname + '/integration/elm/index.js', {
production: true
Expand Down

0 comments on commit 72f10f9

Please sign in to comment.