1

I have a project in Vue that is going to be big, so we are splitting the code in chunks with Webpack configuration, but when I build the project with vue-cli-service, it generates an index.html that prefetches/preloads all the chunks. I don't want to use this index.html. I need a single entry file for Vue that will start the app and import the other files as requested.

I tried splitChunks: false in Webpack, but it didn't help:

configureWebpack: {
   optimization: {
     splitChunks: false
   }
}

Tried removing the other imports and keeping only the app.js, but that also didn't help.

We are using import(/* webpackChunkName: "login" */ './views/Login.vue'), but not in all components.

I previously had another Vue project that worked the way I want: only an app.js and a vendor.js that import other chunks as needed. Back then, I wasn't using vue-cli-service; rather just a simple Webpack config and System.import( /* webpackChunkName: "Login" */ '@/components/pages/login/Login.vue') in all components that import the route files:

<html>
...
    <body>
        <div id=app></div>
        <script type=text/javascript src=/static/js/vendor.2f58f4045cb046ff1dac.js>
        </script>
        <script type=text/javascript src=/static/js/app.877179012e83c1c97b77.js>
        </script>
    </body>
</html>

I would like to build my project and have a single JS file that I can import in another HTML file, and it will act as a starter file.

Do I just need the System.import in all imports? Any other configurations with vue-cli-service?

1 Answer 1

2

The preload and prefetch scripts that are inserted into index.html (by @vue/preload-webpack-plugin) can be disabled via chainWebpack, yielding only one JavaScript import of app.js in index.html:

// vue.config.js
module.exports = {
  chainWebpack: config => {
    config.optimization.delete('splitChunks') // no vendor chunks
    config.plugins.delete('prefetch')         // no prefetch chunks
    config.plugins.delete('preload')          // no preload chunks
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.