shanlu0000

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 执行后:

 

分类:

技术点:

相关文章:

  • 2021-07-26
  • 2022-02-14
  • 2021-10-23
  • 2021-12-12
  • 2021-04-22
  • 2022-12-23
  • 2021-08-29
猜你喜欢
  • 2022-12-23
  • 2021-05-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-16
相关资源
相似解决方案