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

"Unexpected token found" on @import directives #191

Open
DMW007 opened this issue Oct 6, 2016 · 16 comments
Open

"Unexpected token found" on @import directives #191

DMW007 opened this issue Oct 6, 2016 · 16 comments
Milestone

Comments

@DMW007
Copy link

DMW007 commented Oct 6, 2016

Installed product versions

  • Visual Studio: 2015 Community
  • This extension: 2.1.279

Description

When a css-file contains @import statements, the minifying-process would fail with the error-message

(Bundler & Minifier) Unexpected token, found '@import'

Steps to recreate

  1. Create a css file with a @import directive like @import url("../style.css");
  2. Add the file to BundlerMinifier and try to minify

Expected behavior

The tool should at least leave the import-directive. But the best way would be fetching the referenced file and replace their content with the import-line, this would result in best performance.

@DMW007
Copy link
Author

DMW007 commented Oct 9, 2016

Workaround for Wordpress

I had this issue because I'm including the style.css of a self-created child-theme, with itself is build on a paid wordpress-theme. So the style.css of the parent-theme was included in the style.css of the child-theme. To avoid this, I found out that this can be done using the style-hooks in the function.php file like explained here.

Because there is no css @import anymore, we've a workaround to bypass these bug. And its also better for the performance of the wordpress-theme, since @import will block rendering. Using the way above, the css file is inserted in a normal tag. Most browsers are able to download these css-files parellel.

In the ASP.NET Core application, we must only add both of the stylesheets from parent and child-theme in the bundleconfig.json like this:

{
    "outputFileName": "wwwroot/clientscript/bundle.min.css",
    "inputFiles": [
      "wwwroot/clientscript/wp/parent-theme/style.css",
      "wwwroot/clientscript/wp/child-theme/style.css"
    ]
}

Important is, that the parent-theme should be included before the child-theme. WordPress will do the same using the functions.php described above and it make sense: So you're able to override things from the parent-theme, which you want to customize. So it could have unwanted side-effects, if you don't care about those order.

@RouR
Copy link

RouR commented May 2, 2017

Same issue with @import url("https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700");

and with .spinner .rect5{-webkit-animation-delay:-0.8s;animation-delay:-0.8s}@-webkit-keyframes sk-stretchdelay{0%,40%,100%{-webkit-transform:scaleY(0.4)}20%{-webkit-transform:scaleY(1)}}@keyframes sk-stretchdelay{0%,40%,100%{transform:scaleY(0.4);-webkit-transform:scaleY(0.4)}20%{transform:scaleY(1);-webkit-transform:scaleY(1)}}

@mitja-p
Copy link

mitja-p commented May 31, 2017

I have the same issue as above. Any fix coming?

@nrgjack
Copy link

nrgjack commented Jun 16, 2017

Visual studio 2017 + Bundle & minifier 2.4.340

i have no issue

@OskarKlintrot
Copy link

Isn't 2.4.337 the latest..?

@los93sol
Copy link

I'm on VS17 with Bundle & minifier 2.5.357, still having the issue with it blowing up on @imports and @Keyframes

@alvipeo
Copy link

alvipeo commented Feb 5, 2018

guys, are you going to fix this???

@garfbradaz
Copy link

Was this ever fixed?

@omuleanu
Copy link

omuleanu commented May 8, 2018

@import statements need to be placed in the first css file (from the bundle) on the top
(this tool is not moving them for you, at least the current version)
or if you can avoid using them, you might use another link tag instead

@rockstardev rockstardev modified the milestones: back, backlog May 8, 2018
@cpwaters
Copy link

As above, put your new css file above the site.css in the array. Works fine on VS17 with Bundle & minifier 2.8.391.

@douglasalonso
Copy link

douglasalonso commented Feb 21, 2020

I had this problem when I was building the project in the Azure Devops pipeline, and with this tip of creating the css file and placing the import in it and then adding the file inside the bundleconfig.json it worked. Thanks

@Takerman
Copy link

Takerman commented May 5, 2020

@import statements need to be placed in the first css file (from the bundle) on the top
(this tool is not moving them for you, at least the current version)
or if you can avoid using them, you might use another link tag instead

IT WORKED FOR ME! Great answer

@WalissonPires
Copy link

Was this ever fixed?

@bilalsaeed
Copy link

There are so many limitations in this tools. Is there any better alternative available?

@programatix
Copy link

I'm having issue with files containing @media, such as,

@media only screen and (max-width: 600px) {
  body {
    background-color: lightblue;
  }
}

I get, (Bundler & Minifier) Unexpected token, found '@'

@DMW007
Copy link
Author

DMW007 commented Oct 13, 2023

There are so many limitations in this tools. Is there any better alternative available?

I used Gulp in the past, for new projects I'd have a look at Webpack.

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