Skip to content

Commit

Permalink
Add support for HMR with elm-hot (#2388)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktosiek authored and devongovett committed Dec 11, 2018
1 parent 3d58ac0 commit 697b234
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/core/parcel-bundler/package.json
Expand Up @@ -90,6 +90,7 @@
"coffeescript": "^2.0.3",
"cross-env": "^5.1.1",
"elm": "^0.19.0",
"elm-hot": "^1.0.1",
"eslint": "^4.13.0",
"glslify-bundle": "^5.0.0",
"glslify-deps": "^1.3.0",
Expand Down
5 changes: 4 additions & 1 deletion packages/core/parcel-bundler/src/assets/ElmAsset.js
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 @@ -47,6 +46,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 packages/core/parcel-bundler/test/elm.js
Expand Up @@ -22,6 +22,20 @@ describe('elm', function() {
assert(js.includes('elm$browser$Debugger'));
});

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 remove debugger in production', async function() {
let b = await bundle(__dirname + '/integration/elm/index.js', {
production: true
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Expand Up @@ -3413,6 +3413,11 @@ elliptic@^6.0.0:
minimalistic-assert "^1.0.0"
minimalistic-crypto-utils "^1.0.0"

elm-hot@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/elm-hot/-/elm-hot-1.0.1.tgz#12751fc41ecf1ddc58b5492114d6f77395d3a440"
integrity sha512-C6VEX3TqVJv+OhUKMMb2mcaSuRArqvCFNItqxue81/mlfX4PWwvovE5vqocgO3AnrStyHElCRm0KNknfDttEBw==

elm@^0.19.0:
version "0.19.0"
resolved "https://registry.yarnpkg.com/elm/-/elm-0.19.0.tgz#c6ad86afea9e971424ebe75e36c9d03412a787fa"
Expand Down

0 comments on commit 697b234

Please sign in to comment.