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

Styles Generator: Install postcss-url #1191

Merged
merged 1 commit into from
Apr 19, 2024

Conversation

stevepolitodesign
Copy link
Contributor

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.

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
end

def configures_postcss
File.delete(postcss_config) if File.exist?(postcss_config)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, copy_file does not override existing files. So, we need to delete it first.

@stevepolitodesign stevepolitodesign merged commit 5b133e7 into suspenders-3-0-0 Apr 19, 2024
2 checks passed
@stevepolitodesign stevepolitodesign deleted the suspenders-3-0-0-postcss-url branch April 19, 2024 20:04
@stevepolitodesign stevepolitodesign mentioned this pull request Apr 19, 2024
stevepolitodesign added a commit that referenced this pull request 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

Successfully merging this pull request may close these issues.

1 participant