ocombe / ocLazyLoad

Lazy load modules & components in AngularJS
https://oclazyload.readme.io
MIT License
2.63k stars 510 forks source link

Lazyload webpack bundle js with hash in the name #363

Closed aaronte closed 8 years ago

aaronte commented 8 years ago

I am trying to lazy load a separate bundle that webpack generates like so:

resolve: {
    loadModule: ['$ocLazyLoad', ($ocLazyLoad) => {
        return $ocLazyLoad('./lazy.bundle.js');
    }]
}

My problem is when I deploy to production, I add a [hash] to my bundle names for cache busting. How am I able to rename my ocLazyLoaded file dynamically depending on how webpack generates the hash?

ocombe commented 8 years ago

Hello,

you will have to use a webpack plugin for that, either something that replaces the file names in your js code: https://github.com/zhongzhi107/replace-hash-webpack-plugin or something that emits the list of new hash names like that one: https://github.com/kossnocorp/assets-webpack-plugin

aaronte commented 8 years ago

@ocombe Thanks! https://github.com/zhongzhi107/replace-hash-webpack-plugin didn't work with weird errors. But https://github.com/kossnocorp/assets-webpack-plugin worked by referencing the json file that it emits. Was hoping that there would be a solution that dynamically changes the path in my js without the mapping but this works!