zoukankan      html  css  js  c++  java
  • 在webpack中使用 html-withimg-loader 打包html文件中的图片

    在安装并配置file-loader插件后,在js文件中引入图片使用import导入图片才能被打包,在css或者sass中的背景图片,需要@import css或sass到js文件中才能被打包

    对于html中的img的src引入的图片无法正常打包,这时候需要引入一个webpack的插件 html-withimg-loader

    插件地址https://www.npmjs.com/package/html-withimg-loader

    安装 npm install html-withimg-loader -S
    
    使用 webpack.config.js
    const HtmlWithimgLoader = require("html-withimg-loader ");  
    module: {
      rules: [
        {
          test: /.(htm|html)$/,
          loader: 'html-withimg-loader'
        },
        // 在file-loader 的options中必须配置esModule: false
        {
          test: /.(png|jpg|gif)$/,
          use: [
            {
              loader: 'file-loader',
              options: {
                name: '[name].[ext]',
                outputPath: 'img/',
                publichPath: 'img/',
                esModule: false 
              }
            }
          ]
        }
      ]
    }

      

  • 相关阅读:
    一、docker安装CentOS7
    c#使用资源文件完成国际化
    .netcore 读取ansi编码
    省市区数据库
    .netcore2.0发送邮件
    使用py,根据日志记录自动生成周报
    mysql监控每一条执行的sql语句
    根据json生成c#实体类
    使用.net core efcore根据数据库结构自动生成实体类
    winform,同个程序只允许启动一次
  • 原文地址:https://www.cnblogs.com/aidixie/p/12770690.html
Copyright © 2011-2022 走看看