javascriptvue.jsvue-cli-4

With Vue-cli, when running build, how to organize files in css and js folders after the build?


By default, Vue-cli creates the files as follows:

- dist
-- demo.html
-- style.css
-- file.commom.js
-- file.commom.js.map
-- file.umd.js
-- file.umd.js.map
-- file.umd.min.js
-- file.umd.min.js.map

I want the files to be organized this way:

- dist
-- demo.html
-- css
--- style.css
-- js
--- file.commom.js
--- file.commom.js.map
--- file.umd.js
--- file.umd.js.map
--- file.umd.min.js
--- file.umd.min.js.map

Bonus question: Are these common and umd names really necessary? Because in the node_modules folder, I don't see any projects with these names.


Solution

  • You can achieve this by modifying your webpack config.

    Take a look at this issue here: https://github.com/vuejs/vue-cli/issues/1967

    module.exports = {
        chainWebpack: (config) => {
        config.module
          .rule('images')
          .use('url-loader')
          .tap(options => Object.assign({}, options, { name: '[name].[ext]' }));
      },
      css: {
        extract: {
          filename: '[name].css',
          chunkFilename: '[name].css',
        },
      },
      configureWebpack: {
        output: {
          filename: '[name].js',
          chunkFilename: '[name].js',
        }
      }
    };
    

    This is the example given, but you can change the chunkFilname and filename keys to include a folder as part of the path. For instance 'javascript/[name].js'