scss-bundle icon indicating copy to clipboard operation
scss-bundle copied to clipboard

ignoreImports option does not seem to work with ~@angular/material/theming imports.

Open MalumAtire832 opened this issue 5 years ago • 12 comments

Describe the bug ignoreImports option does not seem to work with ~@angular/material/theming imports.

To Reproduce toolbar.component-theme.scss

@import "~@angular/material/theming";

@mixin htg-toolbar-theme($theme) {

  $primary: map-get($theme, primary);

  .htg-toolbar {
    background-color: mat-color($primary);
  }
}

components.scss

@import "../htg-navigation/components/toolbar/toolbar.component-theme";

@mixin component-themes($theme, $company-logo) {
  @include htg-toolbar-theme($theme);
}

index.scss

@import "components";

scss-bundle.config.json

{
  "bundlerOptions": {
    "entryFile": "./src/lib/scss/index.scss",
    "rootDir": "./src/lib/",
    "outFile": "dist/shared-components/bundled.scss",
    "ignoreImports": ["~@angular/.*"],
    "logLevel": "debug"
  }
}

Expected behavior The ~@angular/material/theming imports should be ignored and the files should be bundled.

Package version: v3.0.2 Node version: v12.13.0 OS: Windows 10 - 1903

MalumAtire832 avatar Dec 09 '19 14:12 MalumAtire832

It appears that the ignoreImports option has been renamed to ignoredImports (notice the d)

I included the following property and value in my scss-bundle.config.json and the outFile did not contain any material scss code:

"ignoredImports": ["~@angular/.*"],

@jefferywroblewski-accesso Might this be for a newer version? My version does not seem to know the ignoredImports option when used in the CLI, it specificly says so.

As for the issue at hand, i seem to have fixed it. I was running scss-bundle from the projects/myproject directory, with the rootdir also set to this directory. This meant it could not find my node_modules 2 directories up. While messing around i got the hint 'found tilde import but no node_modules found.'

The solution for me was to move the scss-bundle.config.json to the root of my workspace and change some values:

{
  "bundlerOptions": {
    "entryFile": "projects/shared-components/src/_theme.scss",
    "outFile": "dist/shared-components/bundled.scss",
    "rootDir": "",
    "ignoreImports": ["~@angular/.*"],
    "logLevel": "debug"
  }
}

Everything is now working like it should now that scss-bundle can find my node_modules. Maybe someone else can verify this issue, because the error message is very misleading if this is the case. I'll leave this issue open for any possible feedback for the time beeing.

MalumAtire832 avatar Dec 15 '19 13:12 MalumAtire832

Same problem occurs here.

having a projects/my-project/scss-bundle.config.json and running: "build:theming:scss": "scss-bundle --project='./projects/my-project'", does not work.

Moving the scss-bundle.config.json to the root fixes it. But I would love to have the config in de project root instead of the workspace root. (we have multiple projects)


--project: Project location where scss-bundle.config.json and node_modules are located.

Would be nice if this was separated: node_modules default from root or something? (or a separate option)

the-ult avatar Dec 16 '19 09:12 the-ult

@MalumAtire832 , My mistake. The ignoredImports was only available in previous versions (I was using 2.5.1). I installed the latest version (which is 3.0.2 at the time of this post) and discovered the configuration scheme was refactored between the two versions. The old ignoredImports property was removed and replaced with the bundlerOptions.ignoreImports property.

I was able to get this working where it is only ignoring the @angular imports using the same approach that you used. Thanks for the comment which reminded me to look for an updated version. 👍

Hey @the-ult and @MalumAtire832. If I understood correctly, you having issues with configuration file location and where exactly node_modules are.

I have published a new canary version. It has CLI flag --config and project property in bundlerOptions.

$ npm install [email protected] -D

I think another issue is somewhat related #74.

MartynasZilinskas avatar Dec 18 '19 13:12 MartynasZilinskas

Thanks @MartynasZilinskas will give it a try tomorrow

the-ult avatar Dec 18 '19 14:12 the-ult

@MartynasZilinskas The combination of the --config and project options seems to work for me:

{
  "bundlerOptions": {
    "entryFile": "./projects/shared-components/src/_theme.scss",
    "rootDir": "./projects/shared-components/src",
    "project": "../../",
    "outFile": "./dist/shared-components/theme.scss",
    "ignoreImports": ["~@angular/.*"],
    "logLevel": "debug"
  }
}

Thank you for this!

I only noticed one thing:

The project option seems to expect a path relative from the specified rootDir; am i correct in this? Because the entryFile seems to require a path relative from the directory where scss-bundle was called.

For example;

  • Setting project equal to ./ does not work; same import error.
  • Setting entryFile equal to _theme.scss does not work, file not found error.

Is this the expected behavior? Because it strikes me as a bit odd.

MalumAtire832 avatar Dec 18 '19 20:12 MalumAtire832

@MalumAtire832 I think I know where is the problem. Could you test with new canary version ([email protected])?

MartynasZilinskas avatar Dec 19 '19 06:12 MartynasZilinskas

@jefferywroblewski-accesso ignoreImports is not working for ~@material/.*


  {
    entryFile: 'libs/theme/src/lib/safire-theme.scss',
    outFile: 'libs/theme/dist/theme.scss'
  },

  {
    entryFile: 'libs/theme/src/lib/utilities.scss',
    outFile: 'libs/theme/dist/utilities.scss'
  },

  {
    ignoreImports: ['~@material/.*'],
    entryFile: 'libs/components/button/src/scss/button.scss',
    outFile: 'libs/components/button/src/dist/button-theming.scss'
  }

];
Am using "scss-bundle": "^3.0.2",

chimiwangchuk avatar Dec 30 '19 18:12 chimiwangchuk

Thanks @MartynasZilinskas! I'm using [email protected] with --config flag and project property and it's working fine for me. This is my .config.json:

{
  "bundlerOptions": {
    "entryFile": "./src/components/src/components.theme.scss",
    "rootDir": "",
    "project": "../../",
    "outFile": "./dist/components/theming.scss",
    "ignoreImports": [
      "~@angular/.*"
    ],
    "logLevel": "debug"
  }
}

mvmjacobs avatar Jan 08 '20 18:01 mvmjacobs

I am using the same config with [email protected] and it's not working:

There is an error in your styles:
Can't find stylesheet to import.
  ?
1 ¦ @import '~@angular/material/theming';
  ¦         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ?
  stdin 1:9  root stylesheet on line (1, 9)

Why is it even trying to resolve the file if it's specifically ignored?

PapaNappa avatar Jan 16 '20 08:01 PapaNappa

This still seems to be an issue in 3.1.1 even when following the guidance above.

Calling from workspace root (where node_modules) is and setting project config to "./" or leaving blank does not solve the problem.

dankellett avatar Jul 08 '20 05:07 dankellett