Vue Cli 3 为不同类型的文件构建自定义目录

Sam*_*son 1 npm webpack vue.js vue-cli-3

我是使用 vue 构建网络应用程序的新手。默认情况下,使用npm run build,它将构建以下结构:

在此输入图像描述

但我希望构建如下:

在此输入图像描述

那么,我怎样才能写出vue.config.js我想要的那样的输出呢?

Phi*_*hil 5

使用此 GitHub 问题作为示例,您应该能够通过在配置中添加类似的内容来实现此目的...

// 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'
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

请参阅https://cli.vuejs.org/config/#vue-config-js了解更多信息和示例。