Skip to content

Commit c0368ad

Browse files
committed
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.
1 parent f76c7e8 commit c0368ad

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

activestorage/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.byebug_history
22
node_modules
3+
src
34
test/dummy/db/*.sqlite3
45
test/dummy/db/*.sqlite3-journal
56
test/dummy/log/*.log

activestorage/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
* Add source code to published npm package
12

3+
This allows activestorage users to depend on the javascript source code
4+
rather than the compiled code, which can produce smaller javascript bundles.
5+
6+
*Richard Macklin*
27

38
Please check [5-2-stable](https://github.com/rails/rails/blob/5-2-stable/activestorage/CHANGELOG.md) for previous changes.

activestorage/package.json

+7-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "Attach cloud and local files in Rails applications",
55
"main": "app/assets/javascripts/activestorage.js",
66
"files": [
7-
"app/assets/javascripts/*.js"
7+
"app/assets/javascripts/*.js",
8+
"src/*.js"
89
],
910
"homepage": "http://rubyonrails.org/",
1011
"repository": {
@@ -16,18 +17,21 @@
1617
},
1718
"author": "Javan Makhmali <[email protected]>",
1819
"license": "MIT",
20+
"dependencies": {
21+
"spark-md5": "^3.0.0"
22+
},
1923
"devDependencies": {
2024
"babel-core": "^6.25.0",
2125
"babel-loader": "^7.1.1",
2226
"babel-preset-env": "^1.6.0",
2327
"eslint": "^4.3.0",
2428
"eslint-plugin-import": "^2.7.0",
25-
"spark-md5": "^3.0.0",
2629
"webpack": "^3.4.0"
2730
},
2831
"scripts": {
2932
"prebuild": "yarn lint",
3033
"build": "webpack -p",
31-
"lint": "eslint app/javascript"
34+
"lint": "eslint app/javascript",
35+
"prepublishOnly": "rm -rf src && cp -R app/javascript/activestorage src"
3236
}
3337
}

0 commit comments

Comments
 (0)