zoukankan      html  css  js  c++  java
  • 打包其他资源(除html/css/js 资源以外的资源)

    src / index.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>webpack</title>
    </head>
    <body>
        <span class="iconfont icon-icon-test"></span>
        <span class="iconfont icon-icon-test2"></span>
        <span class="iconfont icon-icon-test3"></span>
        <span class="iconfont icon-icon-test1"></span>
    </body>
    </html>
    

    src / index.js

    // 引入 iconfont 样式文件
    import './font/iconfont.css'
    

    webpack.config.js

    const {resolve} = require('path')
    const HtmlWebpackPlugin = require('html-webpack-plugin')
    
    module.exports={
        entry:'./src/index.js',
        output:{
            filename:'bundle.js',
            path:resolve(__dirname,'build')
        },
        module:{
            rules:[
                {
                    test:/.css$/,
                    use:['style-loader','css-loader']
                },
                //打包其他资源(如字体图标)
                {
                    exclude:/.(css|js|html|less)$/,
                    loader:'file-loader',
                    options:{
                        name:'[hash:10].[ext]'
                    }
                }
            ]
        },
        plugins:[
            new HtmlWebpackPlugin({
                template:'./src/index.html'
            })
        ],
        mode:'development'
    }
    

    npx webpack 执行后:

  • 相关阅读:
    wait
    iOS UITableviewCell优化
    iOS本地版本和服务器对比
    iOS 二维码生成 改变颜色 添加中心图
    iOS坑点解析
    iOS View快照,View截屏
    双缓冲读感感悟
    查找附近点--Geohash方案讨论
    各种报告word模板
    跳转到设置里面各个页面iOS8
  • 原文地址:https://www.cnblogs.com/shanlu0000/p/13046689.html
Copyright © 2011-2022 走看看