-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Mount common JS config files into /assets/_jsconfig and add these filenames to the JS environment #7656
Comments
Fixes gohugoio#7644 Fixes gohugoio#7656
Fixes gohugoio#7644 Fixes gohugoio#7656
Fixes gohugoio#7644 Fixes gohugoio#7656
Question: is this using ESBuild or the normal JS pipeline. Some of this seems to work in ESBuild which is why I am asking. |
@richtera Not relevant for ESBuild. Main issue I want to solve here is PostCSS/Tailwind living in a Hugo Module. What I would have loved to solve on the ESBuild side is to allow some custom "import resolver", so Hugo could have a way to say ESBuild have some internal abstractions that would enable this, it's just a matter of convincing the author that it's a fantastic idea, and seeing how busy he has been, I have not wanted to push that idea, yet ... |
I think I was able to actually get this to work. I am using two theme modules layered and I was able to put a jsconfig.json on each layer to optional search for js files in the other theme layer. Although it's a bit tricky to setup. {
"compilerOptions": {
"paths": {
"react/*": ["/some/path/react/*"],
"react": ["/some/path/react/main"]
}
}
} This should work although it was not quite obvious where to put the jsconfig.json file. I put it parallel to the file I used as source for the resource.Get path. I did find that if I had the file in theme/*/assets/js and there was a assets/js folder it would no longer find the file even though there was no assets/js/index.js file. So the ESBuild will assume an index.js file exists as long as it finds the folder. But that was a minor issue for me. |
Fixes gohugoio#7644 Fixes gohugoio#7656
Map @assets to search through root and theme layer assets. Map @js to search through root and theme layer assets for a js folder with the file. Read original ts/js config and amend settings to temporary tsconfig file. Ref gohugoio#7656
Although the js.Build PR solves the resolution of js files within the js.Build transform in the pipeline, it would need to dynamically render the js from assets in order to inject the dependency into the postcss pipeline, so it's related. I am not sure how easy it would be to launch the postcss transform from the output of a js.Build pipeline. |
Fixes gohugoio#7644 Fixes gohugoio#7656
This commit also introduces a convention where these common JS config files, including `package.hugo.json`, gets mounted into: ``` assets/_jsconfig ´`` These files mapped to their real filename will be added to the environment when running PostCSS, Babel etc., so you can do `process.env.HUGO_FILE_TAILWIND_CONFIG_JS` to resolve the real filename. But do note that `assets` is a composite/union filesystem, so if your config file is not meant to be overridden, name them something specific. Fixes gohugoio#7644 Fixes gohugoio#7656
@richtera I have modified the description of this issue somewhat, and I don't think this and ESBuild overlaps. This is about running an external program (PostCSS) and how that program resolves its configuration, there is no "Javascript building" involved. |
Ok, true. I was just thinking in theory if we were to "build" the tailwinds config using js.Build and then execute the output file from postcss it would resolve the correct paths. |
This commit also introduces a convention where these common JS config files, including `package.hugo.json`, gets mounted into: ``` assets/_jsconfig ´`` These files mapped to their real filename will be added to the environment when running PostCSS, Babel etc., so you can do `process.env.HUGO_FILE_TAILWIND_CONFIG_JS` to resolve the real filename. But do note that `assets` is a composite/union filesystem, so if your config file is not meant to be overridden, name them something specific. Fixes gohugoio#7644 Fixes gohugoio#7656
OK, so my initial testing of this seems to have been flawed, so I got to get back to the drawing board. These JS/Node path issues are fairly frustrating. |
OK, I think I figured it out ... And that was about to ruin my Saturday evening ... Now, a glass of wine. |
@richtera oh, and your PR/research around jsconfig vs ESBuild looks very promising, I will look into it in a couple of days. |
Cool, thanks. I have been using it locally and if I find anything I'll amend the PR. Have a great night! |
I just thought of a crazy idea. why not setup NODE_PATH and PATH environment variable inside postcss.go to be something like. PATH=./node_modules/.bin:./themes/THEMEMOD1/node_modules/.bin:./themes/THEMEMOD2/node_modules/.bin:$PATH
NODE_PATH=./node_modules:./themes/THEMEMOD1/node_modules:./themes/THEMEMOD2/node_modules Sounds crazy, but in theory, it should do what is required for postcss to find the main modules. You'd then only need to resolve the config file by looking up the same paths. Hmmm. |
|
... also, the NODE_PATH does not solve the primary problem in this issue: That Tailwind resolves its config file relatively to where it lives. |
I like the hugo mod idea to install modules, but if those modules are pulled automatically then I think npm install should be run automatically if there is a package.json within them. It should use yarn is there is a yarn.lock or npm if there is a package-lock.json. It's a bit tricky for sure and this would cause things to be a little fragile. There would be a lot of moving parts and if there was babel going on as well, then this is a lot of things. Hmmm. |
This commit also introduces a convention where these common JS config files, including `package.hugo.json`, gets mounted into: ``` assets/_jsconfig ´`` These files mapped to their real filename will be added to the environment when running PostCSS, Babel etc., so you can do `process.env.HUGO_FILE_TAILWIND_CONFIG_JS` to resolve the real filename. But do note that `assets` is a composite/union filesystem, so if your config file is not meant to be overridden, name them something specific. Fixes gohugoio#7644 Fixes gohugoio#7656
This commit also introduces a convention where these common JS config files, including `package.hugo.json`, gets mounted into: ``` assets/_jsconfig ´`` These files mapped to their real filename will be added to the environment when running PostCSS, Babel etc., so you can do `process.env.HUGO_FILE_TAILWIND_CONFIG_JS` to resolve the real filename. But do note that `assets` is a composite/union filesystem, so if your config file is not meant to be overridden, name them something specific. This commit also adds adds `workDir/node_modules` to NODE_PATH if it exists and `HUGO_WORKDIR` to the env when running the JS tools above. Fixes gohugoio#7644 Fixes gohugoio#7656 Fixes gohugoio#7675
This commit also introduces a convention where these common JS config files, including `package.hugo.json`, gets mounted into: ``` assets/_jsconfig ´`` These files mapped to their real filename will be added to the environment when running PostCSS, Babel etc., so you can do `process.env.HUGO_FILE_TAILWIND_CONFIG_JS` to resolve the real filename. But do note that `assets` is a composite/union filesystem, so if your config file is not meant to be overridden, name them something specific. This commit also adds adds `workDir/node_modules` to `NODE_PATH` and `HUGO_WORKDIR` to the env when running the JS tools above. Fixes gohugoio#7644 Fixes gohugoio#7656 Fixes gohugoio#7675
This commit also introduces a convention where these common JS config files, including `package.hugo.json`, gets mounted into: ``` assets/_jsconfig ´`` These files mapped to their real filename will be added to the environment when running PostCSS, Babel etc., so you can do `process.env.HUGO_FILE_TAILWIND_CONFIG_JS` to resolve the real filename. But do note that `assets` is a composite/union filesystem, so if your config file is not meant to be overridden, name them something specific. This commit also adds adds `workDir/node_modules` to `NODE_PATH` and `HUGO_WORKDIR` to the env when running the JS tools above. Fixes gohugoio#7644 Fixes gohugoio#7656 Fixes gohugoio#7675
This commit also introduces a convention where these common JS config files, including `package.hugo.json`, gets mounted into: ``` assets/_jsconfig ´`` These files mapped to their real filename will be added to the environment when running PostCSS, Babel etc., so you can do `process.env.HUGO_FILE_TAILWIND_CONFIG_JS` to resolve the real filename. But do note that `assets` is a composite/union filesystem, so if your config file is not meant to be overridden, name them something specific. This commit also adds adds `workDir/node_modules` to `NODE_PATH` and `HUGO_WORKDIR` to the env when running the JS tools above. Fixes gohugoio#7644 Fixes gohugoio#7656 Fixes gohugoio#7675
This commit also introduces a convention where these common JS config files, including `package.hugo.json`, gets mounted into: ``` assets/_jsconfig ´`` These files mapped to their real filename will be added to the environment when running PostCSS, Babel etc., so you can do `process.env.HUGO_FILE_TAILWIND_CONFIG_JS` to resolve the real filename. But do note that `assets` is a composite/union filesystem, so if your config file is not meant to be overridden, name them something specific. This commit also adds adds `workDir/node_modules` to `NODE_PATH` and `HUGO_WORKDIR` to the env when running the JS tools above. Fixes gohugoio#7644 Fixes gohugoio#7656 Fixes gohugoio#7675
So, I'm complicating this further at this moment. What I add now works seamlessly with Netlify and other build tools. In your local setup you will currently still have to do a |
This commit also introduces a convention where these common JS config files, including `package.hugo.json`, gets mounted into: ``` assets/_jsconfig ´`` These files mapped to their real filename will be added to the environment when running PostCSS, Babel etc., so you can do `process.env.HUGO_FILE_TAILWIND_CONFIG_JS` to resolve the real filename. But do note that `assets` is a composite/union filesystem, so if your config file is not meant to be overridden, name them something specific. This commit also adds adds `workDir/node_modules` to `NODE_PATH` and `HUGO_WORKDIR` to the env when running the JS tools above. Fixes gohugoio#7644 Fixes gohugoio#7656 Fixes gohugoio#7675
This commit also introduces a convention where these common JS config files, including `package.hugo.json`, gets mounted into: ``` assets/_jsconfig ´`` These files mapped to their real filename will be added to the environment when running PostCSS, Babel etc., so you can do `process.env.HUGO_FILE_TAILWIND_CONFIG_JS` to resolve the real filename. But do note that `assets` is a composite/union filesystem, so if your config file is not meant to be overridden, name them something specific. This commit also adds adds `workDir/node_modules` to `NODE_PATH` and `HUGO_WORKDIR` to the env when running the JS tools above. Fixes gohugoio#7644 Fixes gohugoio#7656 Fixes gohugoio#7675
This commit also introduces a convention where these common JS config files, including `package.hugo.json`, gets mounted into: ``` assets/_jsconfig ´`` These files mapped to their real filename will be added to the environment when running PostCSS, Babel etc., so you can do `process.env.HUGO_FILE_TAILWIND_CONFIG_JS` to resolve the real filename. But do note that `assets` is a composite/union filesystem, so if your config file is not meant to be overridden, name them something specific. This commit also adds adds `workDir/node_modules` to `NODE_PATH` and `HUGO_WORKDIR` to the env when running the JS tools above. Fixes #7644 Fixes #7656 Fixes #7675
Map @assets to search through root and theme layer assets. Map @js to search through root and theme layer assets for a js folder with the file. Read original ts/js config and amend settings to temporary tsconfig file. Ref gohugoio#7656
Map @assets to search through root and theme layer assets. Map @js to search through root and theme layer assets for a js folder with the file. Read original ts/js config and amend settings to temporary tsconfig file. Ref gohugoio#7656
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This issue talks about using PostCSS with the TailwindCSS plugin in different situations in Hugo, from the main project, from the theme in
/themes
, from modules, from vendored modules ... But this is also a general issue which is mostly relevant to these JS tools living outside of Hugo.I created this local "test project" to illustrate the problem for myself:
So, when running
postcss
fromproject
with the configuration living inmod
, I can do:postcss --config ../mod/postcss.config.js -o out.css styles.css;
This is in essence what Hugo does today, and it breaks in, at least, the Tailwind setup above. There are some other "gotchas" to the current situation (one being vendored modules), but I'm not going into details about those.
The main problem with the above is that it fails to find the TailwindCSS configuration. So I could do:
Which works, but how do I, running in Hugo, know where to find that file?
I have thought long and hard about this, and jumping to my conclusion, I thought we could do something ala this:
tailwind.config.js
=>HUGO_FILE_TAILWIND_CONFIG_JS
. In the example above, we could be even more specific doing:Thoughts? Any better ideas?
/cc @regisphilibert @onedrawingperday @digitalcraftsman @jmooring @coliff and gang.
Also see #7635 and some others ....
The text was updated successfully, but these errors were encountered: