question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ember-cli-postcss filters not running under embroider

See original GitHub issue

Cross posting this embroider compatibility issue from the ember-cli-postcss repo: https://github.com/jeffjewiss/ember-cli-postcss/issues/714

tl;dr: the addon uses the postprocessTree hook to run a postcss “filter” operation, this hook seems to no longer work under embroider.

From https://jeffjewiss.github.io/ember-cli-postcss/docs:

if you would like to run Postcss after another processor or on all of your styles, including files added by addons or through vendor, then use filter.

Is there a recommended path forward for addons like this which want to do work at a particular stage of the build pipeline?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
ef4commented, Mar 10, 2022

I will add one warning about using sass directly with webpack.

Sass is a bundler in its own right, and not just a transpiler. Some obvious things you might decide to do, like having each of your component javascript files import a corresponding sass file, give disastrously bad output (like, megabytes and megabytes of duplicated styles).

Sass has a solution for this, which is “sass modules” (which means using @use instead of @import), so if you and your sass-providing dependencies have switched to that, you can do fine-grained inclusion of sass. But most codebases I’ve seen still use the older style.

Using that style, you should limit yourself to having a single place in the app do an import of a single top-level sass file:

// app/app.js
import "./styles/app.scss";

and the app.scss should internally @import or @use everything else that’s needed.

0reactions
22acommented, Apr 11, 2022

We’ve had some success getting the postcss “filter” operation to run as part of the existing broccoli pipeline in our embroider app, short-circuiting the non-existent postprocessTree hook.

Removing our existing ember-cli-postcss config:

    postcssOptions: {
      compile: {
        enabled: false,
      },
      filter: {
        enabled: true,
        map: isProduction,
        include: ['assets/embercom.css', 'assets/vendor.css'],
        exclude: ['**/*.css.map'],
        plugins: [
          require('tailwindcss')('./config/tailwind.config.js'),
          ...(isProduction ? [require('postcss-clean')] : []),
        ],
      },
    },

and replacing it with a direct invocation of broccoli-postcss:

const PostcssFilter = require('broccoli-postcss');

// ...

  let postcssFilterOptions = {
    enabled: true,
    map: isProduction,
    include: ['assets/embercom.css', 'assets/vendor.css'],
    exclude: ['**/*.css.map'],
    plugins: [
      require('tailwindcss')('./config/tailwind.config.js'),
      ...(isProduction ? [require('postcss-clean')] : []),
    ],
    overrideBrowserslist: ['Edge >= 80', 'Chrome >= 66', 'Firefox >= 58', 'Safari >= 13'],
    processTrees: ['css'],
  };

  let treeWithPostcssTransformedStyles = new PostcssFilter(
    new MergeTrees(trees),
    postcssFilterOptions,
  );

  trees = trees.concat([treeWithPostcssTransformedStyles]);

Extra context

In this app I’m testing, we only use PostCSS for replacing @tailwind at-rules and minification (with ember-cli-sass handling the rest of our app styles) so this may be a simplified use case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ember-cli-postcss - Bountysource
I'm running into an issue where ember-cli-postcss filters aren't being run during app/addon builds. From playing around with repo config and ember-cli-postcss ......
Read more >
Postcss-import problem with TailwindCSS v1.0 - Ember.JS
I suspect this is a problem with postcss-import not being able to detect the base.css and the rest of the css files in...
Read more >
ember-cli-postcss | Yarn - Package Manager
Note: it's possible to use both compile and filter. ... Filter. This step will run at the end of the build process on...
Read more >
how to filter out files during when ember-cli is building my app ...
I am trying to reduce monaco-editor dependency size. generally, if you're using embroider, if you don't import it, it won't be a part...
Read more >
ember-css-modules - npm Package Health Analysis | Snyk
Further analysis of the maintenance status of ember-css-modules based on released npm versions cadence, the repository activity, and other data points ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found