grunt-browserify icon indicating copy to clipboard operation
grunt-browserify copied to clipboard

Support of persistent cache

Open ovcharik opened this issue 8 years ago • 4 comments

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

ovcharik avatar Apr 04 '16 10:04 ovcharik

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.

TheSavior avatar Apr 23 '16 03:04 TheSavior

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.

TheSavior avatar Apr 23 '16 03:04 TheSavior

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.

ovcharik avatar Apr 23 '16 14:04 ovcharik

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?

TheSavior avatar Apr 23 '16 21:04 TheSavior