Ai
1 Star 0 Fork 0

吴建勇/html-webpack-inline-plugin

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
index.js 1.47 KB
一键复制 编辑 原始数据 按行查看 历史
Leon 提交于 2018-08-14 09:42 +08:00 . fix error handler
var inline = require('inline-source')
function HtmlWebpackInlinePlugin(options) {
// Setup the plugin instance with options...
this.options = options
}
HtmlWebpackInlinePlugin.prototype.apply = function(compiler) {
let self = this
if (compiler.hooks) {
compiler.hooks.compilation.tap('HtmlWebpackInlinePlugin', compilation => {
if (!compilation.hooks.htmlWebpackPluginBeforeHtmlProcessing) {
throw new Error('The expected HtmlWebpackPlugin hook was not found! Ensure HtmlWebpackPlugin is installed and was initialized before this plugin.');
}
compilation.hooks.htmlWebpackPluginBeforeHtmlProcessing.tapAsync(
'HtmlWebpackInlinePlugin',
(htmlPluginData, callback) => {
var html = htmlPluginData.html
inline(html, self.options, function(err, html) {
if (err) {
return callback(err)
}
htmlPluginData.html = html
callback(null, htmlPluginData)
})
}
)
})
} else {
compiler.plugin('compilation', (compilation, options) => {
compilation.plugin('html-webpack-plugin-before-html-processing', (htmlPluginData, callback) => {
var html = htmlPluginData.html
inline(html, self.options, function(err, html) {
if (err) {
return callback(err)
}
htmlPluginData.html = html
callback(null, htmlPluginData)
})
})
})
}
};
module.exports = HtmlWebpackInlinePlugin
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wu_jianyong/html-webpack-inline-plugin.git
git@gitee.com:wu_jianyong/html-webpack-inline-plugin.git
wu_jianyong
html-webpack-inline-plugin
html-webpack-inline-plugin
master

搜索帮助