You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PostHTML plugins that require css-modules don't work. #395
Choose one: is this a 🐛 bug report or 🙋 feature request?
🐛
Trying to use posthtml plugins that require the json containing the css classes causes the index.html to become <div></div>. regardless of what it was.
@devongovett Hello, there are no error messages it just outputs <div></div>. That example is not the same as what I've shown above all that integration test is if a single posthtml plugin works not posthtml with postcss.
changed the title [-]PostHTML plugins with non object arguments don't work.[/-][+]PostHTML plugins that require css-modules don't work.[/+]on Dec 26, 2017
@brandon93s Hello, I have provided the needed files to reproduce the bug in the original post. I've also done some debugging into the issue and have traced it to the posthtml line where the res.tree returned is a function named parse rather than an AST.
Since options there, for this particular use case, is a boolean, parcel never calls plugin().
Also you need to specify a file, dir with files or object that will be used for replacing class names with generated class names e.g. posthtml([require('posthtml-css-modules')('./cssClasses.json')]).
parcel is ignoring all none object options meaning even if you specify a file with classes something like: "posthtml-css-modules": "./cssClasses.json" it won't work.
But you still can specify options as an object e.g. "posthtml-css-modules": { "title": "_title_116zl_1 _heading_9dkf" } – which works fine...
It might be out of scope for this single issue, but I was wondering about how closely using css-modules in parcel should be with posthtml since they are already generated and special cased in parcel and they are not stored in a way that is visible for the user of parcel to use. I was thinking that there are two solutions to the problem.
Provide an option in .postcssrc to allow outputting css-modules to a file.
Have HTMLAsset store the generated class names of it's child CSSAssets and use posthtml-css-modules if it is enabled in a similar way to "modules": true in .postcssrc.
I got posthtml-include to work by ensuring that I had set the "root" property in my .posthtmlrc. If the include tag src attribute isn't correct with respect to root, <include src ... simply gets emitted as <include src ... in the parcel build output. IMHO, this should emit an error instead. Thanks, @devongovett for the link to the integration test!
yarn run v1.2.1
$ parcel build ./src/index.html
🚨 /Users/patrick.nausha/code/PersonalWebsite/src/index.html: tree.forEach is not a function
at Object.collapseWhitespace [as default] (/Users/patrick.nausha/code/PersonalWebsite/node_modules/htmlnano/lib/modules/collapseWhitespace.js:18:10)
at /Users/patrick.nausha/code/PersonalWebsite/node_modules/htmlnano/lib/htmlnano.js:58:42
at <anonymous>
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
The reference to tree seems related to
I've also done some debugging into the issue and have traced it to the posthtml line where the res.tree returned is a function named parse rather than an AST.
Run parcel ./src/index.html and watch it succeed happily.
Activity
devongovett commentedon Dec 24, 2017
There is an example in the tests that works. Can you give any more details about what doesn't work for you? Are there error messages?
https://github.com/parcel-bundler/parcel/tree/master/test/integration/posthtml
XAMPPRocky commentedon Dec 24, 2017
@devongovett Hello, there are no error messages it just outputs
<div></div>. That example is not the same as what I've shown above all that integration test is if a single posthtml plugin works not posthtml with postcss.[-]PostHTML plugins don't work.[/-][+]PostHTML plugins with non object arguments don't work.[/+][-]PostHTML plugins with non object arguments don't work.[/-][+]PostHTML plugins that require css-modules don't work.[/+]bndnsmth commentedon Dec 28, 2017
@Aaronepower a reproducible test repo or gist would be hugely helpful in debugging!
XAMPPRocky commentedon Dec 29, 2017
@brandon93s Hello, I have provided the needed files to reproduce the bug in the original post. I've also done some debugging into the issue and have traced it to the posthtml line where the
res.treereturned is a function namedparserather than an AST.d4rkr00t commentedon Jan 1, 2018
I've investigated a little bit, and some of the things i've found:
parcel/src/utils/loadPlugins.js
Lines 29 to 31 in b9004fc
plugin().posthtml([require('posthtml-css-modules')('./cssClasses.json')]).parcel/src/utils/loadPlugins.js
Lines 25 to 27 in b9004fc
"posthtml-css-modules": "./cssClasses.json"it won't work."posthtml-css-modules": { "title": "_title_116zl_1 _heading_9dkf" }– which works fine...@devongovett is there any particular reason for:
parcel/src/utils/loadPlugins.js
Lines 25 to 27 in b9004fc
Is it fine if i change it to something like
if (typeof options !== 'object' && typeof options !== 'string') {?XAMPPRocky commentedon Jan 1, 2018
It might be out of scope for this single issue, but I was wondering about how closely using css-modules in parcel should be with posthtml since they are already generated and special cased in parcel and they are not stored in a way that is visible for the user of parcel to use. I was thinking that there are two solutions to the problem.
.postcssrcto allow outputting css-modules to a file."modules": truein.postcssrc.wryk commentedon Jan 12, 2018
Because of issue renaming I don't know if it's still belongs here :
Running any posthtml plugin with empty options (
{}) generate<div></div>.With this .posthtmlrc configuration parcel works fine but meeeh :
{ "plugins": { "posthtml-include": { "useless-option": true }, "posthtml-md": { "useless-option": true } } }sandrina-p commentedon Jan 13, 2018
I have the same problem and @wryk solution didn't work for me... I just can't use
posthtml-include...@brandon93s I added a repo so you guys can debug it
PatrickNausha commentedon Jan 14, 2018
A finding that may be helpful to @sandrina-p:
I got
posthtml-includeto work by ensuring that I had set the"root"property in my.posthtmlrc. If theincludetagsrcattribute isn't correct with respect toroot,<include src ...simply gets emitted as<include src ...in the parcel build output. IMHO, this should emit an error instead. Thanks, @devongovett for the link to the integration test!See full code at https://github.com/PatrickNausha/PersonalWebsite/tree/parcel
A finding related to
parcelvsparcel buildthat perhaps warrants a new issue:.posthtmlrcin my code to the below (or pull down https://github.com/PatrickNausha/PersonalWebsite/tree/parcel-broken-posthtmlrc andyarn install):parcel build ./src/index.htmlto seeThe reference to
treeseems related toparcel ./src/index.htmland watch it succeed happily.<div></div>Here's what I expect to be different:
parcelandparcel buildshould probably fail..posthtmlrcor other PostHTML validation.I hope this helps!
XAMPPRocky commentedon May 20, 2020
Hey, I wish you wouldn't close bug reports just because they're stale, it kind of defeats the point of making the bug report in the first place.