Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for HMR with elm-hot #2388

Merged
merged 1 commit into from Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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