-
Notifications
You must be signed in to change notification settings - Fork 34
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
not working with webpack very well. #39
Comments
@crashnick16 - do you have a sample of your webpack config and/or folder structure. Using webpack v4 with knockout-amd-helpers v1.0.0, a sample entry point looks like this:
|
Hi I am looking at the same errors, I've also copy and pasted + modified the code you have provided above. my project is as such
I have modified these to suit my structure is there something you can suggest to help me debug ? This is my first attempt to use webpack and I don't really understand how templating works in knockout inside out. |
Not sure if anyone is still listening on this thread, but I finally got this working with the most recent version of webpack (5.97.1). For posterity, here is what I did: Prerequisites (package.json:
Configuration (webpack.config.js) to configure the html-loader. rules: [
...
{
test: /\.html$/,
exclude: /node_modules/,
use: {
loader: 'html-loader',
},
},
...
] Override the default loader somewhere in code: var templateContext = require.context('../templates', true, /.html$/);
(ko.amdTemplateEngine as any).loader = function (templateName, done) {
var tname = `${ko.amdTemplateEngine.defaultPath}/${templateName}${ko.amdTemplateEngine.defaultSuffix}`;
var template = templateContext(tname);
done(template.default);
} What I found was that the templateContext (result of require.context) function returns a module, not the string contents of the template. There is a member "default" that has the contents, which is what you want. Another thing to consider is where your templates are located at runtime. If you don't get the pathing right, the functions will fail. |
@fiidim Nice! Thanks for adding this info to the thread. |
I am getting the below error every time I build with webpack:
Any ideas how this can be fixed?
The text was updated successfully, but these errors were encountered: