-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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 Elm assets #1968
Conversation
The two pass thing is due to a known unfixed regression in This |
Thanks @kzc, I wasn't aware of that. I've updated it so it's just a single operation now. |
src/assets/ElmAsset.js
Outdated
unsafe: true, | ||
unsafe_comps: true | ||
}, | ||
mangle: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the unlikely event that the Terser maintainer reintroduces the rename
pass, please explicitly disable the option:
rename: false,
src/assets/ElmAsset.js
Outdated
}; | ||
|
||
const {code} = minify(source, options); | ||
return code; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The minify
return error
property should be examined. Terser will not throw upon minify
error. Consult its API docs.
src/assets/ElmAsset.js
Outdated
}; | ||
|
||
const {code} = minify(source, options); | ||
return code; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The minify
return error
property should be examined. Terser will not throw upon minify
error. Consult its API docs.
I noticed in the original docs for https://github.com/rtfeldman/elm-spa-example#step-2 that it specified the |
@kzc I believe all the feedback should be accounted for now. I also set |
Cool. I've never used Elm before - looks interesting. I should check it out. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks for this, looks pretty much good to go.
Added some comments for minor improvements (the biggest one being config for cache invalidation)
src/Asset.js
Outdated
@@ -25,6 +25,7 @@ class Asset { | |||
this.options = options; | |||
this.encoding = 'utf8'; | |||
this.type = path.extname(this.name).slice(1); | |||
this.forceReload = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this should be called forceReload, at first I thought this meant a parcel reload or something.
Perhaps hmrPageReload
or something?
package.json
Outdated
@@ -82,7 +82,9 @@ | |||
"codecov": "^3.0.0", | |||
"coffeescript": "^2.0.3", | |||
"cross-env": "^5.1.1", | |||
"elm": "^0.19.0-bugfix2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps change this to ^0.19.0
not sure why they're appending -bugfix
instead of just bumping the patch version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm not sure why they decided to tag it like that. Makes sense to keep it as ^0.19.0
.
src/assets/ElmAsset.js
Outdated
this.name | ||
); | ||
const dependencies = await findAllDependencies(this.name); | ||
const packageFile = await findPackageFile(path.dirname(this.name)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this to:
await this.getConfig(['elm.json'], {load: false});
This automatically recursively searches for the file and adds it to the deps, without reading it.
This way you can remove your helper function, cleans it up a little
src/assets/ElmAsset.js
Outdated
|
||
async collectDependencies() { | ||
const {findAllDependencies} = await localRequire( | ||
'find-elm-dependencies', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can avoid installing this package directly if we use elm.findAllDependencies
from the node-elm-compiler
package, which already depends on find-elm-dependencies
. This way only one package will end up getting installed in a user's app.
@@ -82,7 +82,9 @@ | |||
"codecov": "^3.0.0", | |||
"coffeescript": "^2.0.3", | |||
"cross-env": "^5.1.1", | |||
"elm": "^0.19.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this dependency used for? I don't see it used anywhere in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This provides the actual elm
binaries that node-elm-compiler
uses to compile the source files. The package isn't a dependency of node-elm-compiler
, so unfortunately we have to pull it in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see. So since this is a dev dependency in parcel, so we might need to install it in a user's project as well, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, updated to auto install elm
when the command isn't available globally.
Updated to auto install |
This PR adds support for assets written with Elm 0.19. Some notes are as follows.
forceReload
flag to theAsset
class so that any asset that requires a reload can be indicated as such. Aside from Elm assets, HTML assets also have this flag turned on.two-passconfiguration as recommended by the official Elm docs (http://elm-lang.org/0.19.0/optimize)