所以这是我的 webpack 配置:
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 文件,所以我想包含它们......
我尝试了很多方法,包括另一个模板,但都没有奏效......
有人可以给我任何关于如何使这项工作的想法吗?