我有一个包含html
个文件的文件夹,该文件由myHtmlPlugin
进行编译。我希望webpack-dev-server
监视此文件夹中的更改并运行myHtmlPlugin
。基本上,我想添加没有自定义插件入口点的观察程序。这可能吗?
答案 0 :(得分:0)
html
文件都被编译为单个js
fs.readdir(directoryPath, (err, files) => {
fs.writeFileSync(
path.resolve(__dirname, 'public/htmltemplates.min.js'),
this.filecontent,
(err) => {
if(err) throw new Error(err);
}
)
});
module.exports = {
entry: {
htmlTemplates: 'htmltemplates.min.js',
},
apply
方法已设置为观察者:class myHtmlPlugin {
apply(compiler) {
fs.watch(
path.resolve(__dirname, 'templates/views/'),
'utf8',
(eventType, filename) => {
this.compileHtml();
});
}
}
在目录内更改文件时,nodejs
将所有html
个文件编译为一个文件,即webpack
服务器的entryPoint。