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

Support of persistent cache #380

Open
ovcharik opened this issue Apr 4, 2016 · 4 comments
Open

Support of persistent cache #380

ovcharik opened this issue Apr 4, 2016 · 4 comments

Comments

@ovcharik
Copy link

ovcharik commented Apr 4, 2016

Hi!

I just wanted to share idea. Maybe it will be useful: https://gist.github.com/ovcharik/4b230e103b584c864ddb038ec6c2b7ea

Simple benchmark:
screenshot at 15-47-28

Lager project:
screenshot at 16-00-02

@elicwhite
Copy link

This seems similar to https://github.com/jsdf/browserify-incremental and we've been needing something like this at work. We currently spend about a minute and a half creating our bundles in some instances. I'm curious if I can get @ovcharik's snippit to work in our codebase.

@elicwhite
Copy link

The code in the snippit seems to leave me with a cache file that looks like this:

{"path_to_file.js":{"cache":{},"packageCache":{}}}

I'm sure there is some small bug, I'll keep looking into it.

@ovcharik
Copy link
Author

The code in the snippit seems to leave me with a cache file that looks like this:

{"path_to_file.js":{"cache":{},"packageCache":{}}}

This is because grunt-browserify creates browserify instance for each output file. Therefore it is necessary to create an entry in the cache file for each output file. Format of cache file can be found here. Also I've updated the snippet: added comments and improved algorithm save cache file.

@elicwhite
Copy link

elicwhite commented Apr 23, 2016

It seems like the cache data for each file is a package.json contents, not the actual file contents:

For example:

"/myProject/node_modules/grunt-browserify/node_modules/browserify/node_modules/buffer/index.js": {
        "data": {
          "name": "buffer",
          "description": "Node.js Buffer API, for the browser",
          "version": "4.5.1",
          "author": {
            "name": "Feross Aboukhadijeh",
            "email": "[email protected]",
            "url": "http://feross.org"
          },
          "bugs": {
            "url": "https://github.com/feross/buffer/issues"
          },
          "contributors": [
            {
              "name": "Romain Beauxis",
              "email": "[email protected]"
            },
            {
              "name": "James Halliday",
              "email": "[email protected]"
            }
          ],
          "dependencies": {
            "base64-js": "^1.0.2",
            "ieee754": "^1.1.4",
            "isarray": "^1.0.0"
          },
          "devDependencies": {
            "benchmark": "^2.0.0",
            "browserify": "^13.0.0",
            "concat-stream": "^1.4.7",
            "hyperquest": "^1.0.1",
            "is-buffer": "^1.1.1",
            "is-nan": "^1.0.1",
            "split": "^1.0.0",
            "standard": "^6.0.5",
            "tape": "^4.0.0",
            "through2": "^2.0.0",
            "zuul": "^3.0.0"
          },
          "homepage": "https://github.com/feross/buffer",
          "keywords": [
            "buffer",
            "browserify",
            "compatible",
            "browser",
            "arraybuffer",
            "uint8array",
            "dataview"
          ],
          "license": "MIT",
          "main": "index.js",
          "repository": {
            "type": "git",
            "url": "git://github.com/feross/buffer.git"
          },
          "scripts": {
            "test": "standard && node ./bin/test.js",
            "test-browser": "zuul -- test/*.js test/node/*.js",
            "test-browser-local": "zuul --local -- test/*.js test/node/*.js",
            "test-node": "tape test/*.js test/node/*.js test/node-es6/*.js && OBJECT_IMPL=true tape test/*.js test/node/*.js",
            "perf": "browserify --debug perf/bracket-notation.js > perf/bundle.js && open perf/index.html",
            "perf-node": "node perf/bracket-notation.js && node perf/concat.js && node perf/copy-big.js && node perf/copy.js && node perf/new-big.js && node perf/new.js && node perf/readDoubleBE.js && node perf/readFloatBE.js && node perf/readUInt32LE.js && node perf/slice.js && node perf/writeFloatBE.js",
            "size": "browserify -r ./ | uglifyjs -c -m | gzip | wc -c"
          },
          "standard": {
            "ignore": [
              "test/node/*.js",
              "test/node-es6/*.js",
              "test/_polyfill.js",
              "perf/*.js"
            ]
          },
          "jspm": {
            "map": {
              "./index.js": {
                "node": "@node/buffer"
              }
            }
          },
          "readme": "blah blah readme data",
          "readmeFilename": "README.md",
          "_id": "[email protected]",
          "_shasum": "237b5bdef693c4c332385c1ded4ef4646e232d73",
          "_resolved": "https://npmjs.org/buffer/-/buffer-4.5.1.tgz",
          "_from": "https://npmjs.org/buffer/-/buffer-4.5.1.tgz",
          "__dirname": "/myProject/node_modules/grunt-browserify/node_modules/browserify/node_modules/buffer"
        },
        "size": 40180,
        "mtime": 1458788103000
      },

Also, to use this you also need to specify cache and packageCache as browserifyOptions in grunt-browserify.

@ovcharik: Do you think this functionality makes more sense as a browserify plugin than as a part of grunt-browserify?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants