-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Passing individual values" config output errors #11
Comments
Hello. Could you please create a sample project to reproduce the error? We might be able to figure out if the error is caused by |
Hi, What I want to do is :
I managed to get that filename but was obliged to modify your loader : I've added that line (after line 70 of node_modules/template-ejs-loader/lib/index.js ) My webpack.config.js is quite long but here is (at the message bottom) a brief view. I just resumed entries with 2 lines but this part is a loop on multiple files like the HTMLWebpackPlugin part. Your loader doesn't allow templateParameters as a function (but not sure it is the solution) A more simple HTMLWebpackPlugin version I test never give me the right filename but always the first one used on the loop (event if filename is the right one in the loop below)
So I tested this one to have singular parameter :
|
Hi, Thank you |
Hi, |
@florent-cdl And if you want to show your .js code, you can use |
Hi, |
You mean ... just like this? folder structure:
index.ejs: <%- include "./partials1/tempA.ejs" %>
<%- include "./partials2/tempB.ejs" %> |
I guess I know what you are meaning about. |
This is exactly the pb. |
I don't think there is an existing way(using this loader) for your problem. Even I get a solution, I still have to wait for the reviewing of my pull request. Actually I am thinking about creating a new ejs loder npm package on my own BTW :/ |
Great ! Thank you very much |
I think I got a temporary solution for you, but not with this loader. new HtmlWebpackPlugin({
filename: ...,
template: ...,
templateParameters:{
filename:// filename you get.
}
}) And in .ejs file: <!DOCTYPE html>
<html lang="en">
<head></head>
<body>
<div class="site">
<div class="site__header-wrapper">
</div>
<div class="site__body">
<!-- use temaplateParameter-->
<h1><%= htmlWebpackPlugin.options.filename %></h1>
</div>
<div class="site__footer-wrapper">
<!-- include other partial-->
<%= require('./src/template/footer.ejs')() %>
<!-- no using alias -->
<img src="./assets/images/xxx.png">
</div>
</div>
</body>
</html> PS.But if you decide to use {
test: /\.ejs$/,
use: [// no other loader except ejs-loader
{
loader: 'ejs-loader',
options: {
esModule:false
}
}
]
}, And ONCE you remove
Just feel free to ask if you have any problem about this solution :D. |
Hi |
It's not "my loader"... pal lol. If you do have some good idea about fixing this issue, I suggest you just make a pull request. But about the message you mentioned above, I don't think that's a good way to go, 'cause not everyone using this loader will need that |
@mizok |
Hi d-suke, |
Sorry for the late reply. I still do not understand the problem you are having. |
I just want to get the current filenmane as a variable inside the ejs. |
@dc7290 |
@florent-cdl If you still have any problem, just feel free to report a new issue. |
Very nice, you're the best :) |
Hi,
I'm trying to get the current filename inside my ejs template (which include an ejs with that name) but can't get that parameter either by HtmlWebpackPlugin options or template-ejs-loader.
This is a part of my webpack.config (plugins part, sorry some quotes don't render ,so have to change "`" to "'") :
...arrayOfEntry.map( (page) => new HtmlWebpackPlugin({ inject: true, template: '${projectPaths.projectEjsTemplatesPath}/webpack-base-standard.ejs', filename: '../${page}.html', chunks: [page, "common"], templateParameters: { env: process.env.NODE_ENV, jsPath: projectPaths.projectJsPath, cssPath: projectPaths.projectScssPath, ejsPath: projectPaths.projectEjsPath, filename: page }, }) ),
filename templateParameters always set to the first 'page' var opf the loop
I've tried (as specified in readme file)
template: '!${require.resolve('html-loader')}??ruleSet[1].rules[0].use[0]!${path.resolve( __dirname, '../lib/index.js' )}?${new URLSearchParams({ // Use the query as an option to pass to the loader root: projectPaths.projectEjsTemplatesPath, data: JSON.stringify({ foo: 'bar', }), })}!${projectPaths.projectEjsTemplatesPath}/webpack-base-standard.ejs',
but get the error
ERROR in Error: Child compilation failed: Module not found: Error: Can't resolve '/Volumes/TEST-WEBPACK/lib/index.js' in '/Volumes/TEST-WEBPACK'
Please if someone get the solution. What I'm trying to get inside the template ejs
<%- include('${htmlWebpackPlugin.options.ejsPath}/${htmlWebpackPlugin.options.filename}.ejs', {myvar : 'test'}) %>
Best regards
Florent
The text was updated successfully, but these errors were encountered: