webpack打包進內聯html


用到一個新插件: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)'


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM