Wrap library with UMD and add npm release task #587
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Builds on #454 which adds a package.json field.
This PR adds the following features:
rake release:npm
that can be run to publish this library to NPM. The task will ensure that the NPM release version matches the info inVERSION
.cocoon.js
in Universal Module Definition (UMD). This is an immediately-invoked function expression (IIFE) that is compatible with browser and Node.js environments, i.e., applications that use Sprockets and applications that use Webpacker to bundle JavaScript.I've also added to the description in
package.json
to clarify for end-users that this package is designed solely for use with the cocoon gem.A note about the UMD expression: I used
rollup
locally to generate this wrapper, which is the only modification to thecocoon.js
file. It might make more sense, typically, to add this wrapper as a build step and use a tool (like rollup or any module bundler) to develop locally against the "unwrapped" code, but I didn't want to dictate that change to the owner.Generally, I believe this is these changes represent the path forward for "asset gems" to best accommodate both Sprockets and module-bundlers, like
webpack
for Rails applications. I hope you find this useful.