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
This question comes up a lot. A guide listing the options would be helpful, and I don't think that would break scope as long at it's mostly links and summaries.
The steps to include CSS in a webpack project are also not intuitive for beginners. Instructions should be documented somewhere. Posting here in the meantime.
A failed attempt (click to expand)
For example, this was my initial flawed interpretation of one suggestion:
I think you’d need to import the css in your js files. Like in an FFI module.
This compiles, but the js contents do not get incorporated into the final bundle. I seems to be skipped when the compiler determines it's an unnecessary FFI module.
So then if I add this line:
exports.dummy=5;
I get a FFI parsing error on import. Is this related to the ES modules todo?
The actual solutions are to either:
1.
Delete src/Main.js and create ./dev/tailwind.js with this content:
"use strict";import'./tailwind.css';
Then add this file as an entry point in webpack.config.js:
Also your initial attempt can be fixed by importing the stylesheet with the CommonJS require function instead of an ES import, exporting it from the foreign module and then importing it in PureScript (beware, the path is relative to the output directory):
This is quite useful for CSS modules, because then you can type the stylesheet with forall classes. Record classes and refer to the generated class names by record field lookup with the classes you wrote on the stylesheet.
Activity
milesfrain commentedon Jul 21, 2020
The steps to include CSS in a webpack project are also not intuitive for beginners. Instructions should be documented somewhere. Posting here in the meantime.
A failed attempt (click to expand)
For example, this was my initial flawed interpretation of one suggestion:
So, if I have a directory structure like this:
Do I put this in
Main.js:This compiles, but the js contents do not get incorporated into the final bundle. I seems to be skipped when the compiler determines it's an unnecessary FFI module.
So then if I add this line:
I get a FFI parsing error on
import. Is this related to the ES modules todo?The actual solutions are to either:
1.
Delete
src/Main.jsand create./dev/tailwind.jswith this content:Then add this file as an entry point in
webpack.config.js:Edit: Improved technique described in next post.
2.
Use an html
templatewithHtmlWebpackPlugin, and link to the css file from within this templateindex.html.webpack.config.js:dev/index.html:kl0tl commentedon Jul 21, 2020
Your first solution can be simplified a bit by dropping the JavaScript file and referring to ./dev/tailwind.css directly in the entry:
Also your initial attempt can be fixed by importing the stylesheet with the CommonJS
requirefunction instead of an ES import, exporting it from the foreign module and then importing it in PureScript (beware, the path is relative to the output directory):+foreign import stylesheet :: UnitThis is quite useful for CSS modules, because then you can type the stylesheet with
forall classes. Record classesand refer to the generated class names by record field lookup with the classes you wrote on the stylesheet.milesfrain commentedon Jul 21, 2020
Great tips!
Working example with your suggestion applied here:
https://github.com/milesfrain/tps-save-gist/tree/simple-webpack-fixed