-
Notifications
You must be signed in to change notification settings - Fork 49
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 "templateParameters" when prerender-loader used #50
Comments
EDIT: for the updated the loader what I did was to copy the file, but remove the lines: const allLoadersButThisOne = this.loaders.filter(function (loader) {
// Loader API changed from `loader.module` to `loader.normal` in Webpack 2.
return (loader.module || loader.normal) !== module.exports;
});
// This loader shouldn't kick in if there is any other loader
if (allLoadersButThisOne.length > 0) {
return source;
} so the workaround is: add /* eslint-disable */
'use strict';
const _ = require('lodash');
const loaderUtils = require('loader-utils');
// temporary loader to ensure templateParams are used.
// see https://github.com/GoogleChromeLabs/prerender-loader/issues/50
module.exports = function (source) {
if (this.cacheable) {
this.cacheable();
}
// Skip .js files
if (/\.js$/.test(this.resourcePath)) {
return source;
}
// The following part renders the tempalte with lodash as aminimalistic loader
//
// Get templating options
const options = this.query !== '' ? loaderUtils.parseQuery(this.query) : {};
const template = _.template(source, _.defaults(options, { variable: 'data' }));
// Require !!lodash - using !! will disable all loaders (e.g. babel)
return 'var _ = require(' + loaderUtils.stringifyRequest(this, '!!' + require.resolve('lodash')) + ');' +
'module.exports = function (templateParams) { with(templateParams) {' +
// Execute the lodash template
'return (' + template.source + ')();' +
'}}';
}; then in in rules: {
test: selfPath('src/index.html'),
use: [
{
loader: './temporary-template-params-loader',
},
{
loader: 'prerender-loader',
options: {
entry: './src/index.js',
// notice prerender-loader is used without "string: true"
},
},
],
}, plugin: new HtmlWebpackPlugin({
filename: 'index.html',
template: './src/index.html',
templateParameters: (compilation, params) => {
Object.assign(params, {myParam});
return params;
},
inject: false,
}), |
Actually, since jantimon/html-webpack-plugin#972 html-webpack-plugin loader has |
right! so in in rules: {
test: selfPath('src/index.html'),
use: [
{
loader: 'html-webpack-plugin/lib/loader',
options: {
force: true,
},
},
{
loader: 'prerender-loader',
options: {
entry: './src/index.js',
// notice prerender-loader is used without "string: true"
},
},
],
}, plugin: new HtmlWebpackPlugin({
filename: 'index.html',
template: './src/index.html',
templateParameters: (compilation, params) => {
Object.assign(params, {myParam});
return params;
},
inject: false,
}), |
Hi!
Properties from "templateParameters" do not appear in html when using "prerender-loader".
Minimal code to reproduce:
webpack.config.js
index.html
html output
The text was updated successfully, but these errors were encountered: