1

I am new in using vue to build web app. By default, use npm run build, it will build the following structure:

enter image description here

But I hope to build as follow:

enter image description here

Then, how can I write the vue.config.js as output like what I want?

9
  • Where are the images in your sources? If they're in your public directory, just create a register directory in there for them. As for your CSS and JS files, why is it important? Commented Sep 6, 2018 at 4:25
  • This is built in dist folder. It is because of the server structure, it should be output like that. Commented Sep 6, 2018 at 4:29
  • Yes, I know that is your dist folder but I asked you where are the images in your sources? Commented Sep 6, 2018 at 4:29
  • Also, "It is because of the server structure" doesn't make much sense. Can you elaborate? Commented Sep 6, 2018 at 4:46
  • 'css' change to 'css/register', 'img' change to 'images/register' and 'js' change to 'js/register'. It is because of we are using old apache server with php framework. Commented Sep 6, 2018 at 4:53

1 Answer 1

5

Using this GitHub issue as an example, you should be able to achieve this by adding something like this to your configuration...

// vue.config.js
module.exports = {
  chainWebpack: config => {
    config.module.rule('images').use('url-loader')
      .loader('file-loader') // replaces the url-loader
      .tap(options => Object.assign(options, {
        name: 'images/register/[name].[hash:8].[ext]'
      }))
    config.module.rule('svg').use('file-loader')
      .tap(options => Object.assign(options, {
        name: 'images/register/[name].[hash:8].[ext]'
      }))
  },
  css: {
    extract: {
      filename: 'css/register/[name].[hash:8].css',
      chunkFilename: 'css/register/[name].[hash:8].css'
    }
  },
  configureWebpack: {
    output: {
      filename: 'js/register/[name].[hash:8].js',
      chunkFilename: 'js/register/[name].[hash:8].js'
    }
  }
}

See https://cli.vuejs.org/config/#vue-config-js for more information and examples.

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.