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

Cache isn't invalidated if transform options are changed

Open jameslnewell opened this issue 9 years ago • 6 comments

I'm using the envify transform and uglify to remove dead code.

.transform('envify', {
    global: true,
    NODE_ENV: process.argv.indexOf('--production') !== -1 ? 'production' : 'development'
  })

When the NODE_ENV property is changed between runs, browserify-incremental still uses its cached version of files which produces a different output to what is expected.


Is this fixable in browserify-incremental? Otherwise, before I run browserify-incremental I need to delete the cache file when NODE_ENV changes between runs and that means storing state somewhere. :disappointed:

jameslnewell avatar Nov 07 '15 20:11 jameslnewell

To fix this, environment and configuration need to become part of the cache key (which we should have always been doing 😬). This is not yet implemented, but it's my first priority.

jsdf avatar Nov 08 '15 20:11 jsdf

Awesome! Can you clarify what parts of the environment and configuration would become part of the cache key?

I've got around the issue for now by not using browserify-incremental for "prod" builds at all.

jameslnewell avatar Nov 08 '15 22:11 jameslnewell

Basically when items are stored in the cache, currently they are keyed by file name only. If that key also included a digest of things like the node env and browserify opts, then when those things change, that cache entry wouldn't be used.

jsdf avatar Nov 08 '15 22:11 jsdf

Would it work to mark the NODE_ENV in the browserify incremental cache? Like cacheFile: './browserify-cache-' + NODE_ENV + '.json' roughly?

aquach avatar Jan 07 '16 01:01 aquach

Won't help with changes to transformation or plugin settings in package.json or the browserify command line, @aquach. @jsdf' approach of invalidating if the config changes makes sense.

garthk avatar Apr 29 '16 02:04 garthk

maybe it could make a json of the options, make a base64 sha1 hash out of that string and append that to the cache file name? that way the cache file would match the same (and only the same) options.

The cli could do the same technique with it is command line argument string.

xaviergonz avatar Jun 03 '17 12:06 xaviergonz