-
-
Notifications
You must be signed in to change notification settings - Fork 384
Compatibility with AngularCompilerPlugin #186
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
Comments
It seems that this issue occurs specifically when "skipCodeGeneration" is set to false and an Angular component has its "styleUrls" property set to an array of style sheet URLs. |
@sv-uml what version |
It's webpack 4.12.0. All packages are currently at the latest version. |
@sv-uml can you create minimum reproducible test repo? |
@evilebottnawi I am unable to create a repository right now, but I have put test code here: https://gist.github.com/sv-uml/dec79e2402e467e027abcceba9e675a6 |
@evilebottnawi Any luck with the issue? |
@sv-uml in todo list, feel free to investigate |
I'm not able to use mini-css-extract-plugin with AngularCompilerPlugin (i.e., I'm not able to set skipCodeGeneration to true). I have to skip AOT compilation by omitting AngularCompilerPlugin. |
…ct-plugin Note: This restores the demo watch feature; however, AOT is temporarily disabled because mini-css-extract-plugin has an issue with AngularCompilerPlugin See: webpack-contrib/mini-css-extract-plugin#186 (+1 squashed commit) Squashed commits: [ee51577] chore(package): update angular and webpack versions
…ct-plugin Note: This restores the demo watch feature; however, AOT is temporarily disabled because mini-css-extract-plugin has an issue with AngularCompilerPlugin See: webpack-contrib/mini-css-extract-plugin#186
…ct-plugin Note: This restores the demo watch feature; however, AOT is temporarily disabled because mini-css-extract-plugin has an issue with AngularCompilerPlugin See: webpack-contrib/mini-css-extract-plugin#186 (+1 squashed commit) Squashed commits: [ee51577] chore(package): update angular and webpack versions
As a workaround you can simply But of course it would be great if this issue got fixed so we could use this plugin with AngularCompilerPlugin the recommended way. |
Compatibility with AngularCompilerPlugin would be great! |
@pshurygin |
Prod build issue still exists: webpack-contrib/mini-css-extract-plugin#186
So there is no way to extract CSS when using Angular 6 + Webpack 4 (required) at this point? Not using styleUrls isn't going to be acceptable for any serious Angular project. |
@pshurygin your suggestion now conflict with "conflicting order" warnings (see issue #250). |
Well I have a pretty large project(100K LOC) using this approach and there are no warnings with mini-css-extract plugin 0.4.2. I guess it is a matter of your code organization and imports structure. |
@pshurygin Could you give a code example of this sentence of yours:
And an organization/structure example of this sentence:
|
We import css file on top of the component it belongs to and nowhere else. Also, we import components only once: either in shared module, or a feature module. So i guess with this pattern you cant get into that issue. |
@asidelnik Beforeimport { Component } from '@angular/core';
@Component({
selector: 'my-component',
templateUrl: './my.component.html',
styleUrls: ['./my.component.scss']
})
export class AppComponent { } Afterimport { Component, ViewEncapsulation } from '@angular/core';
import './app.component.scss';
@Component({
selector: 'my-component',
templateUrl: './my.component.html',
encapsulation: ViewEncapsulation.None
})
export class AppComponent { } |
I think I have this working. The way I look at it is, Angular's view encapsulation means that your component styles are part of the component definition, not part of the page style. This means that you don't want any Webpack plugins (other than AngularCompiler) to touch it. So, I did this:
My page styles all live in |
Thanks for sharing @thw0rted.
Yup. I understood My only concern around using Shadow DOM is what are the long term caching implications (no file, no caching), and what if the same Anyway, I would like to use |
I also don't have a super firm grip of how encapsulation works, but my understanding was that under the hood, component styles have an additional attribute attached to them, which uses a generated ID to uniquely identify component instances and limit application. That is, the rules come out looking like And I'm pretty sure the rule does exist in one place, for what it's worth. I have a "debug" Webpack build that generally tries to leave the Angular compiler's output as un-messed-with as possible, but otherwise pulls everything into a small number of files -- this makes it easy to deploy but also easy to read when the browser has problems with sourcemaps. I specify my "top level" CSS (everything outside
So, effectively the raw CSS (and apparently template HTML) strings are passed to the component decorator function and that component object is used to construct instances. This means that component CSS is not treated by webpack as CSS, but rather as a string literal -- which is exactly what I want! -- so it can't be minified, comment-stripped, etc. |
That's a great write up, thank you @thw0rted , and now that you mention it, I do recall this being the behavior with Angular ("linked" classes). I think this is sort of like how CSS Modules work? Definitely going to review your comment in depth, and hopefully see this supported in webpack and / or this plugin. 👍 |
@thw0rted Not sure if you could share an example of each, would be curious to try and solve this problem on my end. Starting to get CSS collisions now that all styles have moved into a "global" namespace (single file) and where our specificity is loose / weak. Not sure what options there are (CSS Modules, CSS-in-JS) is worth it as a stop gap measure to get component level CSS scoping too? (with or without extract I suppose, I would just prefer whatever makes CSS more modular / portable) |
I have the same issue if I do: ng build --prod --build-optimizer it fails with the same error as described in this issue, I tried also @thescientist13 solution but it still fails
|
@thescientist13 That's the idea, and I include |
I faced with the same problem. Any news? |
@zaikin-andrew it is open source, PR welcome |
I solved this by excluding {
test: /\.(scss|sass|css)$/,
issuer: {
exclude: /\.ts$/
},
use: [{
loader: MiniCssExtractPlugin.loader
}, {
loader: 'css-loader',
options: {importLoaders: 2, sourceMap: isDev}
}]
}, {
test: /\.(scss|sass|css)$/,
use: [{
loader: 'postcss-loader',
options: {
ident: 'postcss',
sourceMap: isDev,
plugins: () => [
postcssPresetEnv(),
...(!isDev
? [cssnano({preset: ['default', {discardComments: {removeAll: true}}]})]
: [])
]
}
}, {
loader: 'sass-loader',
options: {
sourceMap: isDev,
}
}]
}, |
@zaikin-andrew what is the helpers.root in this case, can you share the whole code snippet please |
Closed because not related to |
@ViieeS Doesn't work, I am getting the following error;
|
i have the same issue after installing https://github.com/swimlane/ngx-charts TypeError: Cannot read property 'replace' of undefined angular 8
all the other solutions above didn't work, it needs to be checked against the package causing it |
the same bug (in mini-css-extract-plugin) while running aot build. |
I have an Angular 6 project where I want to use the mini-css-extract-plugin. Here is the relevant part of the webpack configuration:
Running webpack will fail with the following message:
ERROR in Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
TypeError: Cannot read property 'replace' of undefined
at normalizeBackSlashDirection (C:\node_modules\webpack\lib\RequestShortener.js:16:16)
at new RequestShortener (C:\node_modules\webpack\lib\RequestShortener.js:26:15)
at Compiler (C:\node_modules\webpack\lib\Compiler.js:137:27)
at Compiler.createChildCompiler (C:\node_modules\webpack\lib\Compiler.js:378:25)
at Compilation.createChildCompiler (C:\node_modules\webpack\lib\Compilation.js:1892:24)
at Object.pitch (C:\node_modules\mini-css-extract-plugin\dist\loader.js:77:43)
However, if I change the "skipCodeGeneration" property to true, no error is thrown and everything works normally.
Is this a bug?
The text was updated successfully, but these errors were encountered: