Closed sahilmob closed 4 months ago
Hallo @sahilmob,
Thanks for the issue report. I'll try to fix it over the weekend.
@sahilmob
I cannot reproduce the issue. I have created the manual test watch-imported-css-inline with nested components. After change any file all imported CSS will be inlined into HTML.
npm start
, open in your browser the url : http://localhost:8080src/home.html
=> oksrc/style.css
=> oksrc/main.js
=> oksrc/component-a/style.css
=> oksrc/component-a/index.js
=> oksrc/component-b/style.css
=> oksrc/component-b/index.js
=> okPlease:
src/path/to/style.css
) are you changing, after which occurs issue@sahilmob Is the issue reproducible if you don't use your custom "inline-template-plugin"?
@webdiscus
Yes its is! what is interesting though is that style-loader
seems to be the root cause of the problem, I noticed that style-loader
doesn't work very well with this plugin.
Initially my workaround was to create a local .css
file and @import "~some-package/dist/index.css";
inside it, and then import the local css file into Layout.tsx
, but when I went back to reproduce this issue without my custom plugin (and import some-package/dist/index.css
in Layout.tsx
component), I noticed that I cannot compile the app with the following error
ERROR in [entry] [initial] Spread syntax requires ...iterable[Symbol.iterator] to be a function
I then disabled style-loader
and enabled my custom plugin, it worked fine!
Please note that I've added style-loader
very recently, after reporting this bug, and after doing the aforementioned workaround so that's why it was compiling successfully.
Why you use the bundler plugin
with style-loader
?
The bundler plugin
is designed to replace the style-loader
and is absolutely incompatible for together work.
The bundler plugin
can extract CSS and inline into HTML.
The style-loader
do the same. Only one different: style-loader
can HMR without site reloading after changes, the bundler plugin
requires the site reloading.
I don't understand what doing your inline-template-plugin
. It's look like a wrapper over generated HTML with a templating things: <#import "template.ftl" as layout>...
. Why you don't write this wrapper directly in HTML template file?
Yes you are right l, I use style loader for HMR.
Also you are right about the custom plugin. I convert the html into Freemarket template (ftl)and the reason why I don't write it inside the html is that I want to inline js and css, and the ftl syntax breaks html parsing.
@sahilmob
WARNING
Without your repo, I can't help you, sorry.
Sure. Thanks
here is the test case for .ftl
template.
You can use you .ftl
template as an entry. Just disable the preprocessor: false
option.
Your source tempalte:
<#import "template.ftl" as layout>
<@layout.registrationLayout displayMessage=true displayInfo=realm.password && realm.registrationAllowed && !registrationDisabled??; section>
<#if section = "styles">
<link rel="stylesheet" href="./scss/styles.scss" />
</#if>
<#if section = "scripts">
<script typo="module" src="./js/main.js"></script>
</#if>
<img src="./images/picture.png" />
</@layout.registrationLayout>
the HtmlBundlerPlugin config:
new HtmlBundlerPlugin({
filename: '[name].ftl', // <= output filename of template
test: /\.ftl$/, // <= add it to detect *.ftl files
entry: {
index: 'src/index.ftl',
},
// OR entry: 'src/',
js: {
inline: true,
},
css: {
inline: true,
},
preprocessor: false, // <= disable it for processing *.ftl template w/o compilation
}),
The generated output template file:
<#import "template.ftl" as layout>
<@layout.registrationLayout displayMessage=true displayInfo=realm.password && realm.registrationAllowed && !registrationDisabled??; section>
<#if section = "styles">
<style>...inlined CSS...</style>
</#if>
<#if section = "scripts">
<script>... inlined JS code ...</script>
</#if>
<img src="img/picture.7b396424.png" />
</@layout.registrationLayout>
So you don't need additional inline-template-plugin
.
@sahilmob
for info: I'm working on the HMR supporting for styles. So, after changes in a SCSS/CSS file, the generated CSS will be updated in the browser without reloading, similar it works in style-loader
. This it takes a lot of time, because it is very very complex. But this works already for styles imported in JS very well. Now I work on HMR supporting for styles defined directly in HTML.
P.S. what is with your test repo for using .ftl
templates? Is it yet actual?
Thanks for your efforts. My repos is private unfortunately.
Thanks for your efforts. My repos is private unfortunately.
you can create a public demo repo with fake data to reproduce your issue. Without the reproducible issue I can't help you, you should understand it ;-)
@sahilmob is the issue still actual?
Current behaviour
I have and
index.html
that importsindex.jsx
which has aLayout
Component, and theLayout
Component imports a stylesheet from a package innode_modules
, and theLayout
component renders a child component, when I runwebpack --watch --progress --mode development
for the first time I get all the js and css injected in the html however, if I change the child component file and save, the generated html won't have the inline css, furthermore, if I go to theLayout
component and save it to trigger rebuild, I get the css in the generated html.Expected behaviour
The css should be included in the generated html in watch mode every time
Reproduction Example
./index.html
./index.js
./Layout.jsx
./SomeComponent.jsx
webpack.config.js
Environment
Additional context
I noticed that the
beforeEmit
hook isn't being called after savingSomeComponent
while its being called forLayout
component