首页 > 解决方案 > Vue Cli 3 为不同类型的文件构建自定义目录

问题描述

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

在此处输入图像描述

但我希望构建如下:

在此处输入图像描述

那么,我怎样才能vue.config.js像我想要的那样编​​写 as 输出?

标签: vue.jsnpmwebpackvue-cli-3

解决方案


这个 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'
    }
  }
}

有关更多信息和示例,请参阅https://cli.vuejs.org/config/#vue-config-js


推荐阅读