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

[Gridsome] ModuleBuildError: Module build failed #1

Closed
Tragio opened this issue Oct 6, 2020 · 4 comments
Closed

[Gridsome] ModuleBuildError: Module build failed #1

Tragio opened this issue Oct 6, 2020 · 4 comments

Comments

@Tragio
Copy link

Tragio commented Oct 6, 2020

Hello @unematiii 🙂

First of all, really thank you for this work and contribution to the community!

I've tried this package and some other methods but nothing seems to work. I spend some hours around this but I was not able to find a solution.

I was trying to reduce the CSS class names as Bulma has long names. I'm sure it will reduce heavily the CSS file size. I'm using Gridsome and Buefy.

Attached is a file with all the methods I've tried and the result and errors from them. You can also check it here http://pastie.org/p/1wpSI1AMvK3T6MZ23tXsLB.

I've sent this to another developer to see if it was working from his side but he faced the same problems.

Not sure if is Gridsome, Buefy, SASS fault or something else.

Really thank you and have a beautiful week 😄

debug.js.zip

@unematiii
Copy link
Owner

I did some research and apparently Gridsome CLI generated projects seem to pull in css-loader version 2.1.1 (latest is 4.3.0), and for this version options should be provided differently:

gridsome.config.js:

const { getLocalIdentName } = require("css-loader-shorter-classnames");

const isProduction = process.env.NODE_ENV === "production";

module.exports = {
  // ... other config options
  css: {
    loaderOptions: {
      css: {
        localIdentName: "[local]-[hash:base64:8]",
        ...(isProduction ? { getLocalIdent: getLocalIdentName() } : {}),
      },
    },
  },
};

Attaching sample project with working configuration.

@Tragio
Copy link
Author

Tragio commented Oct 7, 2020

Hello @unematiii!! You're amazing, really thank you for your quick reply.

I took your sample project, I added the Buefy and imported into the main.js. If you try to do gridsome build you notice that the output is the same. There's no effect happening. 🤔

Here is the updated sample project.

Really thank you for the help!

@unematiii
Copy link
Owner

unematiii commented Oct 7, 2020

Hey!

Actually everything in Vue SFC-s do get correct class names. I guess <style module></style> in *.vue components does the trick here. (Observe the first lines of the sample projects built css file). You can enable modules for all the the other css assets by setting additionally modules: true:

module.exports = {
  // ... other config options
  css: {
    loaderOptions: {
      css: {
        modules: true,
        localIdentName: "[local]-[hash:base64:8]",
        ...(isProduction ? { getLocalIdent: getLocalIdentName() } : {}),
      },
    },
  },
};

But beware, enabling modules for external libraries can cause some problems: if you yourself or the JS implementation of the library rely on static class names. Then you should use different configuration for the styles in you app and for those of external libraries.

@unematiii unematiii changed the title ModuleBuildError: Module build failed [Gridsome] ModuleBuildError: Module build failed Oct 7, 2020
@Tragio Tragio closed this as completed Oct 7, 2020
@Tragio
Copy link
Author

Tragio commented Oct 7, 2020

@unematiii it's now working 😄 really thank you for all the help!!!

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