-
Notifications
You must be signed in to change notification settings - Fork 12k
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
feat(webpack): Support to add custom/third party css/sccs #1459
Comments
Possibly related #1457 |
@aciccarello #1457 is about importing files inside your sass file. This is about importing sass/css files in your typescript file. Which will enable webpack to load them in your page. |
@sirajc I understand what you are requesting, but disagree with the approach you desire. Importing css/sass/etc in a code file is a webpack feature, and thus nonstandard. If we were to move to another build system in the future your code would break. As far as the user application is concerned, the CLI is the build system - not webpack. The CLI encapsulates webpack and is providing an abstraction on top of it, and the user shouldn't assume there's webpack there. It's true that importing Your workaround essentially disables A2 style encapsulation to provide a global stylesheet, which is also not the ideal approach. The bigger problem to resolve here is importing arbitrary css outside of angular 2. This is needed for global styles and also to prevent the dreaded FOUC (flash of unstyled content). |
I agree with the black boxing of webpack, I am not a webpack expert either. Webpack version of CLI is much better, faster and feature rich than earlier and thanks you and the team for that. Coming to this case, We need to enable some configuration or mechanism to load the global stylesheet and third party stylesheet (Twitter Bootstrap would be mostly required by lots of projects). If not |
Also related to #1465 |
@TheLarkInn #1465 talks about creating a module for app like |
I've been talking with @TheLarkInn to see if we could come up with a overall solution script/link tags, and we came up with something that seems to cover the needed bases in an elegant enough way:
The key for me is using CSS imports - it's a part of standards and allows webpack to gobble it up on non sass/etc projects. That way all CSS entry points can be handled in the same consistent way. The CLI team is trying to reach a good solution as fast as possible as this issue is holding up a fair number of people, so please comment on this and other proposed solutions. |
I opened a PR for this issue: #1492 but I don't know if it is the right solution and it need to be discussed. My solution generates single Any suggestions and fixes are very welcome. |
Thanks @filipesilva this looks like a good start. Also it would be good if the scripts and compiled css (from sass/scss) also has the hash appended for bursting cache in the prod build. |
@sirajc browsers wouldn't need support for the native css imports, as webpack would bundle it. |
@filipesilva (in response to #1459 (comment) ) If you are writing:
Inside Of course assuming you have the right loader for CSS in the webpack config, which raises a different but possibly related question about having a place where the CLI user can override parts of the webpack config, but that's a different issue. |
@Meligy we don't want to use that pattern (importing .css in .ts) because it's webpack specific instead of a standard. |
@filipesilva I had a similar suggestion (albeit several hours after yours) regarding "global" style configuration (#1492 (comment)) Something to note is that currently css imports for css files are not being processed by web pack (scss files however do work). This concerns styles added to angular components as well. Changing the line to something like the following should work: |
No instead when we decide to tackle css styles we will probably take the approach of adding an additional loader targeting a specific pattern to tackle the global CSS. |
I would like to second the suggestion to keep @TheLarkInn Are you responding to my suggested loader change? If so, in either a global or component context, I would consider scss files supporting |
I was setting @import './shared/styles/variables';
@import '/node_modules/bootstrap-sass/assets/stylesheets/bootstrap'; var Angular2App = require('angular-cli/lib/broccoli/angular2-app');
var path = require('path');
module.exports = function(defaults) {
return new Angular2App(defaults, {
vendorNpmFiles: [
'systemjs/dist/system.src.js',
'zone.js/dist/**/*.+(js|js.map)',
'core-js/client/shim.min.+(js|js.map)',
'rxjs/**/*.+(js|js.map)',
'@angular/**/*.+(js|js.map)',
'ng2-bootstrap/**/*.js'
],
sassCompiler: {
cacheExclude: [/\/_[^\/]+$/],
includePaths: [
'src/app'
],
importer: function (url) {
if (url.search('/node_modules') !== -1) {
return {file: path.join(__dirname, url)};
}
},
sourceMap: true
}
});
}; |
#1633 addresses this issue. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This is CLI App. Have few css files/third party css that needs to be included in the app
Having above in
polyfill.ts
ormain.ts
has no effect, css are not included at allAs a workaround for now, I have included this in index.html
This works fine, but we loose webpack features in this.
Expectation: webpack starters support including css using import, It is expected that cli supports the same behaviour
Important:
I also have
app.scss
which is common styles for app, due this limitation I cannot include it, for now as a workaround, I have added this in app.component as belowThis way I have app.scss available for whole app, but this is clearly a hack
PS: No error in logs
The text was updated successfully, but these errors were encountered: