[英]webpack: How to inject the JS chunks in the a YAML file
I'm using webpack to modernize a legacy MVC application (symfony 1.4)我正在使用 webpack 对遗留 MVC 应用程序进行现代化改造(symfony 1.4)
I would like to inject the JS chunks and the CSS file in a YAML file that contains several other settings.我想在包含其他几个设置的 YAML 文件中注入 JS 块和 CSS 文件。
Here is an example:下面是一个例子:
default:
foo: bar
.
.
stylesheets: [ style.db80006f5e14f38456ef.css ]
javascripts: [ runtime.d8969ec83f67a36c8877.js, npm.material.db07856eff6817abe7f2.js, main.db80006f5e14f38456ef.js ]
.
.
The html-webpack-plugin
supports plugin as well. html-webpack-plugin
支持插件。 I was wondering if it would be possible with my own plugin for the html-webpack-plugin
to inject the CSS files and JS files in a YAML file instead of an HTML template.我想知道是否可以使用我自己的
html-webpack-plugin
将 CSS 文件和 JS 文件注入 YAML 文件而不是 HTML 模板。 I'm not sure if the html-webpack-plugin
is the way to go since I don't want to manipulate an HTML file.我不确定
html-webpack-plugin
是否html-webpack-plugin
,因为我不想操作 HTML 文件。
Maybe there is another possibility to get the names and the order of the JS chunks, plus the CSS file.也许还有另一种可能来获取 JS 块的名称和顺序,以及 CSS 文件。
Thanks a lot in advance!非常感谢!
html-webpack-plugin
is the way to go, you can provide your "base" yaml file as a template, and provide a templateContent
function that will generate your yaml content. html-webpack-plugin
是要走的路,你可以提供你的“基础”yaml 文件作为模板,并提供一个templateContent
函数来生成你的 yaml 内容。
Something like this:像这样的东西:
new HtmlWebpackPlugin({
templateContent: function(params) {
return `
default:
stylesheets: [ ${params.htmlWebpackPlugin.files.css.join(',')} ]
javascripts: [ ${params.htmlWebpackPlugin.files.js.join(',')} ]
`;
},
filename: 'path-to/where/to/save/your.yaml',
inject: false, // prevents from the plugin to auto-inject html tags
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.