-
-
Notifications
You must be signed in to change notification settings - Fork 205
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
[Feature] Add an extract option #385
Comments
Yes, but I think we can implement |
Even better ! |
Yes, let's change it |
Very interested to see this feature. I was trying to extract image, style and js, but keep getting error on those. |
Is there a way to make extraction work at present? |
up |
Is there currently any way or a work around to export to HTML files? The instructions in the readme don't seem to work, probably due to My use-case is pretty simple. I have a bunch of mjml files and I want to use |
What is the progress? |
Somebody can provide example how you use |
A simple example from Webpack 4: {
test: /\.ejs$/i,
exclude: /node_modules/,
use: [
{
loader: 'ejs-loader',
options: {
variable: 'data',
}
},
'extract-loader',
'html-loader',
]
}
// template.ejs
Hello, <%- data.name %>!
<% _.forEach(data.items, function (item) { %>
<div>Row - <%- item %></div>
<% }) %> // view.js
import helloTemplate from 'template.ejs';
let response = {name: 'John', items: ['foo', 'bar']};
$('.body').append(helloTemplate(response)); But most likely this is still unrealizable in the latest version of |
I have a <html>
<head>
<link href="main.css" type="text/css" rel="stylesheet">
</head>
<body>
<img src="hi.jpg">
</body>
</html> Solution, described in {
test: /\.html$/,
type: 'asset/resource',
use: [
'extract-loader',
{
loader: "html-loader",
options: {
esModules: false
}
}
]
}, Apparently, |
@pseusys Why don't use @StudioMaX Weird, I think |
@alexander-akait because image is referenced as |
@pseusys In this case you lose assets optimizations... |
@alexander-akait I thought it would be easier to process the assets by extracting them from HTML files with html-loader. |
I am think thinking you
Or you can even combine these approaches. Using |
Any progress on this Feature?
My source HTML is:
My entry index.js is:
|
You can try to use the new universal html-bundler-webpack-plugin. Note:
Profit Simple usage exampleFor example, there is ./src/views/home/index.html: <html>
<head>
<!-- load source styles here -->
<link href="./style.scss" rel="stylesheet">
<!-- load source scripts here and/or in body -->
<script src="./main.js" defer="defer"></script>
</head>
<body>
<h1>Hello World!</h1>
<img src="./logo.png">
</body>
</html> The generated HTML contains the output filenames of the processed source files, while the script and link tags remain in place: <html>
<head>
<link href="/assets/css/style.05e4dd86.css" rel="stylesheet">
<script src="/assets/js/main.f4b855d8.js" defer="defer"></script>
</head>
<body>
<h1>Hello World!</h1>
<img src="/assets/img/logo.58b43bd8.png">
</body>
</html> Add the HTML templates in the const HtmlBundlerPlugin = require('html-bundler-webpack-plugin');
module.exports = {
plugins: [
new HtmlBundlerPlugin({
entry: {
// define all your templates here, the syntax is the same as Webpack entry
index: 'src/views/index.html', // => dist/index.html
// 'pages/about': 'src/views/about/index.html', // => dist/pages/about.html
// ...
},
js: {
// output filename of extracted JS from source script loaded in HTML via `<script>` tag
filename: 'assets/js/[name].[contenthash:8].js',
},
css: {
// output filename of extracted CSS from source style loaded in HTML via `<link>` tag
filename: 'assets/css/[name].[contenthash:8].css',
},
}),
],
module: {
rules: [
// styles
{
test: /\.(css|sass|scss)$/,
use: ['css-loader', 'sass-loader'],
},
// images
{
test: /\.(ico|png|jp?g|svg)/,
type: 'asset/resource',
generator: {
filename: 'assets/img/[name].[hash:8][ext][query]',
},
},
],
},
}; |
That all sounds fantastic. |
A common use-case for this loader is to use it to generate an HTML file. Many users use this in tandem with the
extract-loader
. Sadly,extract-loader
is very outdated and seems unmaintained.Feature Proposal
html-loader
should support an option to output the HTML code it create into a new file.It could also output the CSS code, but this is maybe out of scope for this loader.
Feature Use Case
Users can use a
.html
as entry. This means that they'll need thehtml-loader
to handle the HTML code. Having an extract option would allow to output the HTML code into a new file in the destination folder, which is convenient for continuous deployment.The text was updated successfully, but these errors were encountered: