Skip to content
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

PostCSS fonts #1190

Closed
Tracked by #1135
jho406 opened this issue Apr 18, 2024 · 3 comments
Closed
Tracked by #1135

PostCSS fonts #1190

jho406 opened this issue Apr 18, 2024 · 3 comments

Comments

@jho406
Copy link

jho406 commented Apr 18, 2024

When including styles from node_modules, sometimes the font faces refer to the packages font files. When PostCSS process that, it doesn't copy the font files over.
For example with primereact installed at node_modules/primereact/resources/themes/lara-dark-amber/theme.css

@font-face {
  font-family: "Inter var";
  font-weight: 100 900;
  font-display: swap;
  font-style: normal;
  font-named-instance: "Regular";
  src: url("./fonts/Inter-roman.var.woff2?v=3.19") format("woff2");
}

Suspenders didn't add additional postcss modules, but this is what I had to do to get that working:

module.exports = {
  plugins: [
    require('postcss-import'),
    require('postcss-nesting'),
    require('autoprefixer'),
    require('postcss-url')({
      url: 'copy',
      assetsPath: 'static'
    })
  ],
}
@stevepolitodesign
Copy link
Contributor

Thank you for opening this.

When including styles from node_modules, sometimes the font faces refer to the packages font files

Can you provide an example of how you included these styles? I want to get a better understanding of the use case.

@jho406
Copy link
Author

jho406 commented Apr 19, 2024

First

npm install primereact

In your application.postcss.css, add the following

@import "primereact/resources/themes/lara-light-cyan/theme.css";

Build the css and go to the root path of your rails app. Notice the console it says its missing a font.

Then add

    require('postcss-url')({
      url: 'copy',
      assetsPath: 'static'
    })

to your postcss.config.js. Rebuild the css, notice the new files located in assets/static. Go to the root path, now the error is gone.

@stevepolitodesign stevepolitodesign added this to the 3.0.0 milestone Apr 19, 2024
@stevepolitodesign stevepolitodesign mentioned this issue Apr 19, 2024
17 tasks
stevepolitodesign added a commit that referenced this issue Apr 19, 2024
Closes #1190

When including styles from `node_modules` via `@import`, we discovered
that static assets referenced in those style sheets are not loaded,
resulting in an error.

Since [cssbundling-rails][] ships with [postcss-import][], we are
already encouraging the use of importing styles from `node_modules`.

This commit aims to solve this problem by installing and configuring
[postcss-url][].

One thing to note is that we override the `postcss.config.js` generated
by the cssbundling-rails installation script, which assumes that the
following plugins have been installed.

- `postcss-import`
- `postcss-nesting`
- `autoprefixer`

Should that change, this file would be invalid, and those packages would
need to be installed.

[cssbundling-rails]: https://github.com/rails/cssbundling-rails
[postcss-import]: https://github.com/postcss/postcss-import
[postcss-url]: https://github.com/postcss/postcss-url
stevepolitodesign added a commit that referenced this issue Apr 19, 2024
Closes #1190

When including styles from `node_modules` via `@import`, we discovered
that static assets referenced in those style sheets are not loaded,
resulting in an error.

Since [cssbundling-rails][] ships with [postcss-import][], we are
already encouraging the use of importing styles from `node_modules`.

This commit aims to solve this problem by installing and configuring
[postcss-url][]. Because `postcss-url` needs a directory to copy assets
to, we create `app/assets/static` as part of the generator.

One thing to note is that we override the `postcss.config.js` generated
by the cssbundling-rails installation script, which assumes that the
following plugins have been installed.

- `postcss-import`
- `postcss-nesting`
- `autoprefixer`

Should that change, this file would be invalid, and those packages would
need to be installed.

[cssbundling-rails]: https://github.com/rails/cssbundling-rails
[postcss-import]: https://github.com/postcss/postcss-import
[postcss-url]: https://github.com/postcss/postcss-url
stevepolitodesign added a commit that referenced this issue Apr 19, 2024
Closes #1190

When including styles from `node_modules` via `@import`, we discovered
that static assets referenced in those style sheets are not loaded,
resulting in an error.

Since [cssbundling-rails][] ships with [postcss-import][], we are
already encouraging the use of importing styles from `node_modules`.

This commit aims to solve this problem by installing and configuring
[postcss-url][]. Because `postcss-url` needs a directory to copy assets
to, we create `app/assets/static` as part of the generator.

One thing to note is that we override the `postcss.config.js` generated
by the cssbundling-rails installation script, which assumes that the
following plugins have been installed.

- `postcss-import`
- `postcss-nesting`
- `autoprefixer`

Should that change, this file would be invalid, and those packages would
need to be installed.

[cssbundling-rails]: https://github.com/rails/cssbundling-rails
[postcss-import]: https://github.com/postcss/postcss-import
[postcss-url]: https://github.com/postcss/postcss-url
stevepolitodesign added a commit that referenced this issue Apr 19, 2024
Closes #1190

When including styles from `node_modules` via `@import`, we discovered
that static assets referenced in those style sheets are not loaded,
resulting in console errors.

Since [cssbundling-rails][] ships with [postcss-import][], we are
already encouraging the use of importing styles from `node_modules`.

This commit aims to solve this problem by installing and configuring
[postcss-url][]. Because `postcss-url` needs a directory to copy assets
to, we create `app/assets/static` as part of the generator.

One thing to note is that we override the `postcss.config.js` generated
by the cssbundling-rails installation script, which assumes that the
following plugins have been installed.

- `postcss-import`
- `postcss-nesting`
- `autoprefixer`

Should that change, this file would be invalid, and those packages would
need to be installed.

[cssbundling-rails]: https://github.com/rails/cssbundling-rails
[postcss-import]: https://github.com/postcss/postcss-import
[postcss-url]: https://github.com/postcss/postcss-url
stevepolitodesign added a commit that referenced this issue Apr 19, 2024
Closes #1190

When including styles from `node_modules` via `@import`, we discovered
that static assets referenced in those style sheets are not loaded,
resulting in console errors.

Since [cssbundling-rails][] ships with [postcss-import][], we are
already encouraging the use of importing styles from `node_modules`.

This commit aims to solve this problem by installing and configuring
[postcss-url][]. Because `postcss-url` needs a directory to copy assets
to, we create `app/assets/static` as part of the generator.

One thing to note is that we override the `postcss.config.js` generated
by the cssbundling-rails installation script, which assumes that the
following plugins have been installed.

- `postcss-import`
- `postcss-nesting`
- `autoprefixer`

Should that change, this file would be invalid, and those packages would
need to be installed.

[cssbundling-rails]: https://github.com/rails/cssbundling-rails
[postcss-import]: https://github.com/postcss/postcss-import
[postcss-url]: https://github.com/postcss/postcss-url
@stevepolitodesign
Copy link
Contributor

Fixed in #1191

stevepolitodesign added a commit that referenced this issue May 10, 2024
Closes #1190

When including styles from `node_modules` via `@import`, we discovered
that static assets referenced in those style sheets are not loaded,
resulting in console errors.

Since [cssbundling-rails][] ships with [postcss-import][], we are
already encouraging the use of importing styles from `node_modules`.

This commit aims to solve this problem by installing and configuring
[postcss-url][]. Because `postcss-url` needs a directory to copy assets
to, we create `app/assets/static` as part of the generator.

One thing to note is that we override the `postcss.config.js` generated
by the cssbundling-rails installation script, which assumes that the
following plugins have been installed.

- `postcss-import`
- `postcss-nesting`
- `autoprefixer`

Should that change, this file would be invalid, and those packages would
need to be installed.

[cssbundling-rails]: https://github.com/rails/cssbundling-rails
[postcss-import]: https://github.com/postcss/postcss-import
[postcss-url]: https://github.com/postcss/postcss-url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants