《基于 Vue 组件库 的 Webpack5 配置》6.将字体库和图片等静态资料,编译后打包至指定文件夹

  • 参考 Rule.generator.filename
  • package.json 的配置如下
module.exports = {
    module: {
            {
                test: /\.(png|svg|jpg|jpeg|gif)$/i,
                type: 'asset/resource',
                generator: {
                    // publicPath: 'assets/imgs/', // 
                    filename: 'imgs/[hash][ext]',
                }
            },
            {
                test: /\.(woff|woff2|eot|ttf|otf)$/i,
                type: 'asset/resource',
                generator: {
                    filename: 'fonts/[hash][ext]',
                }
            },
        ]
    },
}

你可能感兴趣的:(Webpack,vue.js,前端,javascript,webpack)