Open beckend opened 7 years ago
Can you simplify your earlier demo project to showcase this issue? It's easier to see where it fails then.
I am on it, note that purification does not really fail, it just strips away too much.
I am on it, note that purification does not really fail, it just strips away too much.
Yeah, sounds like it's missing some classes. It's either missing files or failing to process certain type of code. But we'll know better once you narrow it down. 👍
Finally, here it is, I managed to repro.
https://github.com/beckend/webpack-debug-1
Ignore the build error, it's just react-toolbox
which has faulty typings - it's harmless.
Try the yarn dev
command after install and open browser to see how it looks.
Then build the production build and open build/index.html
to see purified result.
The repo is always using extract text plugin regardless of dev or prod.
Thanks. Can you point out a specific class that's missing from the build result?
Sure, the only class that I defined in the whole project which becomes index-default-local_AppBar_2lK
after the css-loader through local css transformation is not there.
Css loaded from example flexboxgrid
package, which is also local css scoped is missing - one example is class flexboxgrid_col-xs-12_3qH
.
Css loaded from react-toolbox
, which is also local scoped are missing - one example is theme_appBar_3Wm
.
Basically a lot of local scoped ones are missing(if not all actually), the globally loaded one seems fine.
I'm guessing the plugin only manage to get the css classes before the local scope transformation occurs.
I think I understand a little better now what's going on. The relationship between the code and flexboxgrid is implicit through const { Grid, Row, Col } = require('react-flexbox-grid');
. It's that react-flexbox-grid
that uses the classes.
I could add better hooks for including specific node modules for Purify to parse. I think in this case we could set moduleExtensions: ['.js']
and excludeModules: ['react']
to get around React induced breakage. Maybe module bits should go below their own namespace even so we get modules.<something>
. I think doing this would help in this particular problem and allow the setup to pick the classes.
Well react-flexbox-grid
imports flexboxgrid
css, https://github.com/roylee0704/react-flexbox-grid/blob/master/src/components/Col.js#L3
It's setup in webpack config to local css load.
Yup, but given the import is on package side, the current setup doesn't pick it up I think. That said, perhaps setting moduleExtensions: ['.css']
would be worth a go.
I think I'll rethink the module side anyway as it's not flexible enough right now. I guess the simplest way out would be to expose a filtering hook over multiple fields now that I think of it.
Well, the project is built with this config currently: https://github.com/beckend/webpack-debug-1/blob/master/webpack.config.ts#L251-L281
Alright, so moduleExtensions
is like that already. I know where to look now. In the meantime, you can try enabling the verbose
mode to see what it exactly matches.
I guess one way to hack it would be to import flexboxgrid
from the app side, although that would bring all the related classes to the project then.
I guess some kind of prop to match some regexes to make that import hack?
Yeah. I think I'll just expose the filtering mechanism better. More control then.
You know it's basically all the styleExtensions if you think about it, but yea users might have some weird extensions, doesn't hurt to let them decide.
@beckend @bebraw
I, too, have a similar use-case / need for this filtering!
My project is stripping too much CSS away (as mentioned by @beckend ).
Note: using react-toolbox
in conjunction with other vendor libraries.
Ok, I'm a bit busy now (till Friday at least), but if someone wants to give it a stab, feel free. I think I would start from expanding the current examples, adding something that fails there, and figuring out how to solve that (might need new API and so on).
@beckend Did you ever discover anything?
@jmahc sorry for the late response, I have not been working on this actively. Just been really busy.
Hello there ! Any news from this issue ? I'm using Blueprint, and I have the same issue. I have only some of the CSS classes, not all of them, it's quite weird.
To debug I simply included all my relevant files into the
paths
:The css is then purified, but it looks like it's missing styles when I launch it in the browser.