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

minimizerOptions fails when not serializable (using import/require) #83

Closed
slorber opened this issue Apr 18, 2021 · 3 comments · Fixed by #84
Closed

minimizerOptions fails when not serializable (using import/require) #83

slorber opened this issue Apr 18, 2021 · 3 comments · Fixed by #84

Comments

@slorber
Copy link

slorber commented Apr 18, 2021

  • Operating System: macos
  • Node Version: 14.16
  • NPM Version: 6
  • webpack Version: 5.28.0
  • css-minimizer-webpack-plugin Version: 2.0.0

Expected Behavior

Using cssnano preset with a require call instead of a string preset + options object:

      new CssMinimizerPlugin({
        minimizerOptions: [
          // CssNano options
          {
            preset: require('cssnano-preset-advanced'), 
          },
        ],
        minify: [
          CssMinimizerPlugin.cssnanoMinify,
        ],
      })

Actual Behavior

ReferenceError: defaultOpts is not defined

image

Also tried with preset: require('cssnano-preset-advanced')(opts) (looks like the correct way to me) and got another similar error:

image

ReferenceError: _commentRemover is not defined

Code

cf above

How Do We Reproduce?

cf above


For context, Docusaurus is migrating to Webpack 5 (@alexander-akait helped review a bit our PR facebook/docusaurus#4089)

We have a custom CSSNano preset with some custom config + an additional postcss plugin: https://github.com/facebook/docusaurus/tree/master/packages/docusaurus-cssnano-preset

It's not 100% clear to me how I am supposed to provide our custom Cssnano preset to the CssMinimizer, as it seems there's some evaluation of options that prevent imports/requires in our preset. Do you have an example to share?

I believe that it is a similar issue that @RDIL already reported here: #58

@slorber
Copy link
Author

slorber commented Apr 18, 2021

Actually, this seems to work:

{
  preset: require.resolve('@docusaurus/cssnano-preset'),
}

Still think that what I tried should work.
But maybe just documenting this better or throwing a user-friendly error could be good enough?

@alexander-akait
Copy link
Member

But maybe just documenting this better or throwing a user-friendly error could be good enough?

Yep, here problems with multi threading, we need serialize options and require is broken in this case, so we should use string here (i.e. require.resolve)

@cap-Bernardito cap-Bernardito mentioned this issue Apr 19, 2021
6 tasks
@alexander-akait
Copy link
Member

@slorber Can you look at #84?

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 a pull request may close this issue.

2 participants