admin管理员组文章数量:1022743
We had been using HtmlWebpackInlineSourcePlugin
without issue but it's no longer supported so we moved to InlineChunkHtmlPlugin
which works great for JS, but refuses to capture the output style.css
file and inline it, leaving us with no styles.
Is there some way to inline CSS without building a crude custom solution?
There's many questions similar to mine, but all answers I've found rely on the now unmaintained HtmlWebpackInlineSourcePlugin
plugin.
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin');
const InlineChunkHtmlPlugin = require('react-dev-utils/InlineChunkHtmlPlugin');
module.exports = {
// ... our other configuration options, loaders, etc
plugins: [
new CleanWebpackPlugin(pathsToClean),
new MiniCssExtractPlugin({
filename: 'style.css',
}),
new HtmlWebpackPlugin({
template: './template.html',
// inject: 'body',
inject: true,
filename: './output.html',
inlineSource: '.(js|css)$',
chunks: ['chunk'],
}),
// new HtmlWebpackInlineSourcePlugin(); // Used to work for loading JS & CSS
new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/.*/]); // Only loads JS, no CSS --
],
}
We had been using HtmlWebpackInlineSourcePlugin
without issue but it's no longer supported so we moved to InlineChunkHtmlPlugin
which works great for JS, but refuses to capture the output style.css
file and inline it, leaving us with no styles.
Is there some way to inline CSS without building a crude custom solution?
There's many questions similar to mine, but all answers I've found rely on the now unmaintained HtmlWebpackInlineSourcePlugin
plugin.
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin');
const InlineChunkHtmlPlugin = require('react-dev-utils/InlineChunkHtmlPlugin');
module.exports = {
// ... our other configuration options, loaders, etc
plugins: [
new CleanWebpackPlugin(pathsToClean),
new MiniCssExtractPlugin({
filename: 'style.css',
}),
new HtmlWebpackPlugin({
template: './template.html',
// inject: 'body',
inject: true,
filename: './output.html',
inlineSource: '.(js|css)$',
chunks: ['chunk'],
}),
// new HtmlWebpackInlineSourcePlugin(); // Used to work for loading JS & CSS
new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/.*/]); // Only loads JS, no CSS -- https://openbase.io/js/react-dev-utils
],
}
Share
Improve this question
asked Apr 28, 2020 at 21:54
SlboxSlbox
13.2k18 gold badges65 silver badges135 bronze badges
1 Answer
Reset to default 4yarn add
html-inline-css-webpack-plugin
--dev
const HTMLInlineCSSWebpackPlugin = require('html-inline-css-webpack-plugin').default; // Require the plugin
// ...
// ...
new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/.*/]); // Your existing InlineChunkHtmlPlugin
new HTMLInlineCSSWebpackPlugin(); // Add this new line after InlineChunkHtmlPlugin
All of your code should be otherwise the same. Hope this helps someone.
We had been using HtmlWebpackInlineSourcePlugin
without issue but it's no longer supported so we moved to InlineChunkHtmlPlugin
which works great for JS, but refuses to capture the output style.css
file and inline it, leaving us with no styles.
Is there some way to inline CSS without building a crude custom solution?
There's many questions similar to mine, but all answers I've found rely on the now unmaintained HtmlWebpackInlineSourcePlugin
plugin.
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin');
const InlineChunkHtmlPlugin = require('react-dev-utils/InlineChunkHtmlPlugin');
module.exports = {
// ... our other configuration options, loaders, etc
plugins: [
new CleanWebpackPlugin(pathsToClean),
new MiniCssExtractPlugin({
filename: 'style.css',
}),
new HtmlWebpackPlugin({
template: './template.html',
// inject: 'body',
inject: true,
filename: './output.html',
inlineSource: '.(js|css)$',
chunks: ['chunk'],
}),
// new HtmlWebpackInlineSourcePlugin(); // Used to work for loading JS & CSS
new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/.*/]); // Only loads JS, no CSS --
],
}
We had been using HtmlWebpackInlineSourcePlugin
without issue but it's no longer supported so we moved to InlineChunkHtmlPlugin
which works great for JS, but refuses to capture the output style.css
file and inline it, leaving us with no styles.
Is there some way to inline CSS without building a crude custom solution?
There's many questions similar to mine, but all answers I've found rely on the now unmaintained HtmlWebpackInlineSourcePlugin
plugin.
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin');
const InlineChunkHtmlPlugin = require('react-dev-utils/InlineChunkHtmlPlugin');
module.exports = {
// ... our other configuration options, loaders, etc
plugins: [
new CleanWebpackPlugin(pathsToClean),
new MiniCssExtractPlugin({
filename: 'style.css',
}),
new HtmlWebpackPlugin({
template: './template.html',
// inject: 'body',
inject: true,
filename: './output.html',
inlineSource: '.(js|css)$',
chunks: ['chunk'],
}),
// new HtmlWebpackInlineSourcePlugin(); // Used to work for loading JS & CSS
new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/.*/]); // Only loads JS, no CSS -- https://openbase.io/js/react-dev-utils
],
}
Share
Improve this question
asked Apr 28, 2020 at 21:54
SlboxSlbox
13.2k18 gold badges65 silver badges135 bronze badges
1 Answer
Reset to default 4yarn add
html-inline-css-webpack-plugin
--dev
const HTMLInlineCSSWebpackPlugin = require('html-inline-css-webpack-plugin').default; // Require the plugin
// ...
// ...
new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/.*/]); // Your existing InlineChunkHtmlPlugin
new HTMLInlineCSSWebpackPlugin(); // Add this new line after InlineChunkHtmlPlugin
All of your code should be otherwise the same. Hope this helps someone.
本文标签: javascriptInline CSS with Webpackwithout HtmlWebpackInlineSourcePluginStack Overflow
版权声明:本文标题:javascript - Inline CSS with Webpack, without HtmlWebpackInlineSourcePlugin? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745554628a2155798.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论