1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Include source code in published activestorage npm package

This allows activestorage users to ship smaller javascript bundles to
visitors using modern browsers, as demonstrated in this repository:
https://github.com/rmacklin/activestorage-es2015-build-example

In that example, the bundle shrinks by 5K (24%).

In addition to allowing smaller bundles for those who ship untranspiled
code to modern browsers, including the source code in the published
package can be useful in other ways:

1. Users can import individual modules rather than the whole library
2. As a result of (1), users can also monkey patch parts of
   activestorage by importing the relevant module, modifying the
   exported object, and then importing the rest of activestorage (which
   would then use the patched object).

Note:
In order to allow the source code to be depended on rather than the
compiled code, we have to declare the external dependency on spark-md5
as a regular dependency, not a development dependency.

This means that even users who depend on the compiled code will have to
download this package. However, spark-md5 is a small package, so this
tradeoff seems worth it.
This commit is contained in:
Richard Macklin 2018-02-03 14:20:12 -08:00
parent f76c7e860e
commit c0368ad090
3 changed files with 13 additions and 3 deletions

View file

@ -1,5 +1,6 @@
.byebug_history
node_modules
src
test/dummy/db/*.sqlite3
test/dummy/db/*.sqlite3-journal
test/dummy/log/*.log

View file

@ -1,3 +1,8 @@
* Add source code to published npm package
This allows activestorage users to depend on the javascript source code
rather than the compiled code, which can produce smaller javascript bundles.
*Richard Macklin*
Please check [5-2-stable](https://github.com/rails/rails/blob/5-2-stable/activestorage/CHANGELOG.md) for previous changes.

View file

@ -4,7 +4,8 @@
"description": "Attach cloud and local files in Rails applications",
"main": "app/assets/javascripts/activestorage.js",
"files": [
"app/assets/javascripts/*.js"
"app/assets/javascripts/*.js",
"src/*.js"
],
"homepage": "http://rubyonrails.org/",
"repository": {
@ -16,18 +17,21 @@
},
"author": "Javan Makhmali <javan@javan.us>",
"license": "MIT",
"dependencies": {
"spark-md5": "^3.0.0"
},
"devDependencies": {
"babel-core": "^6.25.0",
"babel-loader": "^7.1.1",
"babel-preset-env": "^1.6.0",
"eslint": "^4.3.0",
"eslint-plugin-import": "^2.7.0",
"spark-md5": "^3.0.0",
"webpack": "^3.4.0"
},
"scripts": {
"prebuild": "yarn lint",
"build": "webpack -p",
"lint": "eslint app/javascript"
"lint": "eslint app/javascript",
"prepublishOnly": "rm -rf src && cp -R app/javascript/activestorage src"
}
}