आप इस प्लगइन github.com/bazilio91/ejs-compiled-loader उपयोग कर सकते हैं:
{ test: /\.ejs$/, use: 'ejs-compiled-loader' }
.ejs
में अपने .html
फ़ाइलों को बदलें और अपने HtmlWebpackPlugin
सही .ejs
टेम्पलेट को इंगित करने के लिए:
new HtmlWebpackPlugin({
template: 'src/views/index.ejs',
filename: 'index.html',
title: 'Home',
chunks: ['index']
})
आप में आंशिक, चर, और संपत्ति आयात कर सकते हैं .ejs
फाइलें:
src/views/partials/head.ejs
:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
src/js/ejs_variables.js
:
const hello = 'Hello!';
const bye = 'Bye!';
export {hello, bye}
src/views/index.ejs
:
<% include src/views/partials/head.ejs %>
<body>
<h2><%= require("../js/ejs_variables.js").hello %></h2>
<img src=<%= require("../../assets/sample_image.jpg") %> />
<h2><%= require("../js/ejs_variables.js").bye %></h2>
</body>
एक नोट, जब आप एक आंशिक शामिल पथ अपनी परियोजना के रूट के सापेक्ष होना चाहिए।
मैंने उसी प्रश्न का उत्तर दिया stackoverflow.com/a/48750048/7448956।
मुझे एक ही समस्या है और जब मैं
की आवश्यकता नहीं है, मैं इसे काम नहीं कर सकता, क्या आप एक कामकाजी उदाहरण दे सकते हैं? – Ruby
उपरोक्त में से कोई भी काम –