webpack html(ejs)包括其他模板 [英] webpack html (ejs) include other templates
本文介绍了webpack html(ejs)包括其他模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的webpack配置:
So this is my webpack config :
import path from 'path';
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: {
index: './dev/index.js'
},
output: {
path: path.join(__dirname, 'dist'),
// publicPath: 'http://localhost:3000/',
filename: 'bundle.js',
chunkFilename: '[id].bundle.js'
},
module: {
loaders: [
{
test: /\.js$/,
exclude: path.resolve(__dirname, "node_modules"),
loader: 'babel-loader'
}
]
},
plugins: [
new HtmlWebpackPlugin({
hash: true,
template: 'ejs!./dev/index.ejs',
inject: 'body'
})
]
};
我的 index.ejs
文件:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<%- include html/one/1.ejs %>
</body>
</html>
我的文件夹结构:
dev/
/assets
/html
/one
1.ejs
1.scss
1.js
/two
/three
index.js
index.ejs
我想将我的html文件模块化,所以我想包括它们...
I want to modularize my html file so I want to include them...
我尝试了很多方法,包括另一个模板,但没有一个工作...
I've tried a lot of methods including another template, but none of them worked...
有人可以给我关于如何进行此工作的任何想法吗?
Can someone give me any ideea of how can I make this work?
推荐答案
使用 ejs-render-loader
包。 查看程序包
plugins: [
new HtmlWebpackPlugin({
hash: true,
template: 'ejs-render!./dev/index.ejs',
inject: 'body'
})
]
我认为解决您的问题。
更新:使用webpack3,加载程序的语法已更改。 'ejs-render!./ dev / index.ejs'
现在应为:'ejs-render-loader!./ dev / index.ejs '
update: with webpack3 the syntax for loaders has changed. 'ejs-render!./dev/index.ejs'
should now be: 'ejs-render-loader!./dev/index.ejs'
这篇关于webpack html(ejs)包括其他模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文