用到一个新插件:html-webpack-inline-source-plugin(依赖于html-webpack-plugin)

1.安装

npm i -D html-webpack-inline-source-plugin html-webpack-plugin

2.编写webpack.config.js

const path = require('path');
const htmlWebpackPlugin = require('html-webpack-plugin');
var HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin');
module.exports = {
    entry: './main.js',
    output: {
        path: path.resolve('./dist'),
        filename: 'bundle.js'
    },
    plugins: [
        new htmlWebpackPlugin({
            template: './index.html',
            filename: 'index-[hash].html',
            inject: 'head',
            inlineSource: '.(js|css)'
        }),
        new HtmlWebpackInlineSourcePlugin()
    ]
}

需要在html-webpack-plugin里添加  inlineSource: '.(js|css)'

相关文章:

  • 2021-05-03
  • 2022-01-15
  • 2022-12-23
  • 2022-12-23
  • 2021-12-25
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-30
  • 2022-12-23
  • 2023-01-09
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案