As you may know, the release of vue-cli 3 is getting close (currently at RC3 status).

I really like the streamlined way of starting projects and having a good baseline for development (especially when trying to setup a good starting point in house, that has documentation and it’s actively developed).

However the default setup isn’t friendly with legacy projects because vue-cli implicitly adds a hash to the generated filenames. That’s great if you’re starting a new project/SPA because it’s like a built in cache buster but doesn’t help if you’re trying to integrate it with your favourite c#/php/python/ruby etc application.

In order to change this let’s quickly look over the following config

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
let assetsDir = "assets";

module.exports = {
  assetsDir: assetsDir,

  configureWebpack: {
    output: {
      filename: assetsDir + "/[name].js",
      chunkFilename: assetsDir + "/[name].js"
    }
  },

  chainWebpack: config => {
    if (config.plugins.has("extract-css")) {
      const extractCSSPlugin = config.plugin("extract-css");
      extractCSSPlugin &&
        extractCSSPlugin.tap(() => [
          {
            filename: assetsDir + "/[name].css",
            chunkFilename: assetsDir + "/[name].css"
          }
        ]);
    }

    config.plugins
      .delete("html")
      .delete("prefetch")
      .delete("preload");
  }
};

Since assetsDir isn’t applied to custom filenames, we do a small workaround defining a variable, and using that for our generated filenames.

We’re then setting the javascript and the css filenames using their respective options and deleting the html plugin that generates the index.html file with it’s ‘dependencies’ prefetch and preload.

Now you are free to use npm run build --modern and setup Modern Mode

An update:

The official docs reference this setup now in a cleaner way