vuetify webpack simple - npm run build - 图像未被复制到/ dist /

时间:2017-10-20 15:26:11

标签: vuetify.js

我有一个使用vuetify webpack-simple的vuetify项目。在项目中,我使用v-parallax标签,每个图像的src绑定到标签和数据对象中的图像路径。图像在src>中。资产>图片。当项目在开发服务器上运行时,图像会显示,但是当我构建项目时,图像不会被复制到dist文件夹。我想我必须配置文件加载器以适应我的项目?值得注意的是,我有两个图像被复制到dist文件夹。那些图像不在v-parallax标签中。如果可以的话请帮忙。

谢谢

{{1}}

1 个答案:

答案 0 :(得分:0)

我用文件加载器替换了url-loader。在构建项目时,它应该指向正确的路径。您还可以使用outputPath选项更改文件的最终位置,outputPath: '/assets/images/'会将您的图片输出到dist/assets/images/

 {
    test: /\.(jpe?g|png|gif|svg)$/i,
    use: [
      {
        loader: 'file-loader',
        options: {
          name: '[name].[ext]',
          outputPath: '/assets/images/'
        }
      }
    ]
  },

完整背景

var path = require('path')
var webpack = require('webpack')

module.exports = {
  entry: './src/main.js',
  output: {
    path: path.resolve(__dirname, './dist'),
    publicPath: '/dist/',
    filename: 'build.js'
  },
  resolve: {
    alias: {
      'public': path.resolve(__dirname, './public')
    }
  },
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          // vue-loader options go here
        }
      },
      {
        test: /\.(jpe?g|png|gif|svg)$/i,
        use: [
          {
            loader: 'file-loader',
            options: {
              name: '[name].[ext]',
              outputPath: '/assets/images/'
            }
          }
        ]
      },
      {
        test: /\.js$/,
        loader: 'buble-loader',
        exclude: /node_modules/,
        options: {
          objectAssign: 'Object.assign'
        }
      },
      {
        test: /\.styl$/,
        loader: ['style-loader', 'css-loader', 'stylus-loader']
      }
    ]
  },
  devServer: {
    historyApiFallback: true,
    noInfo: true
  },
  devtool: '#eval-source-map',
  performance: false
}

if (process.env.NODE_ENV === 'production') {
  module.exports.devtool = '#source-map'
  // http://vue-loader.vuejs.org/en/workflow/production.html
  module.exports.plugins = (module.exports.plugins || []).concat([
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: '"production"'
      }
    }),
    new webpack.optimize.UglifyJsPlugin({
      compress: {
        warnings: false
      }
    }),
    new webpack.LoaderOptionsPlugin({
      minimize: true
    })
  ])
}