Yusup's avatar
Level 5

Lazy loaded files versioning.

Hi.I'm useing Laravel 5.3 with Vuejs2.In vue router I require components lazy

path: '/archive',
        name: 'archive',
        component: resolve => {
            require.ensure(['./Table/Archive/Archive.vue'], () => {
                resolve(require('./Table/Archive/Archive.vue'))
            })
        }

I need to version all my files include lazyloaded via webpack files .I mean I have now app.js, 1.app.js, 2.app.js etc.I'm making

<script src="{{ elixir('js/app.js', '/') }}"></script>

How can I version all that lazy loaded files? My gulpfile

mix.sass('app.scss')
       .webpack('app.js').version('js/app.js', 'public');
0 likes
3 replies
docmattman's avatar

I'm looking to do this same thing. Did you ever figure out how to version the chunks? When I run the elixir version, it adds a single .js file into the public/build/js folder. There are no versioned chunks in there with it. Webpack seems to be putting them in public/js with all the proper chunks, but not versioned.

Yusup's avatar
Level 5

If you make

if(process.env.NODE_ENV == 'production')
    mix.version();

and run npm run prod then it will make all files including chunks versioned

rhand's avatar

We use Webpack code splitting / Dynamic Imports for lazy loading components and have

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 */
mix.webpackConfig({
    output: {
        publicPath: '/',
        chunkFilename: 'js/components/[name].[hash].js',
    }
});

now in webpack.mix.js and that works with loading components using:

Vue.component('app-editor', () => import(/* webpackChunkName:"editor/app-editor"*/ './components/editor/Editor.vue'));

I only wonder how we could update version only when an update is made. Now that these are constantly generated on npm run prod we seem to generate new versions on every build.

2 likes

Please or to participate in this conversation.