-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Serve styles and assets using .angular-cli webpack configuration #2735
Serve styles and assets using .angular-cli webpack configuration #2735
Conversation
cc @amcdnl :D |
} | ||
const appConfig = cliConfig.apps[appIndex]; | ||
|
||
// FIXME dummy value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which of these are dummy values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's outputPath: 'outPutpath'
. I'll amend comment 🙇
app/angular/src/server/config.js
Outdated
import { | ||
getAngularCliWebpackConfigOptions, | ||
applyAngularCliWebpackConfig, | ||
} from './angular-cli_config'; | ||
|
||
// avoid ESLint errors | ||
const logger = console; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use @storybook/node-logger
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Quramy, I think this is the last comment to take care of
// We should not require('@angular/cli') at the top script level because user project might not have `@angular/cli`. | ||
// eslint-disable-next-line global-require, import/no-extraneous-dependencies | ||
ngcliConfigFactory = require('@angular/cli/models/webpack-configs'); | ||
} catch (e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to see this changed a bit.
I'd like to extract a function that detects the installment of @angular/cli
.
If it's not installed, we just merge the base, we might log that.
If it's installed we try to get their webpack config.
This might fail, since it's a deep file in a npm module.
We should log in either case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great!
Codecov Report
@@ Coverage Diff @@
## master #2735 +/- ##
==========================================
- Coverage 35.75% 35.51% -0.25%
==========================================
Files 433 434 +1
Lines 9441 9501 +60
Branches 995 1010 +15
==========================================
- Hits 3376 3374 -2
- Misses 5414 5455 +41
- Partials 651 672 +21
Continue to review full report at Codecov.
|
@@ -76,10 +76,6 @@ export default function(configDir) { | |||
loader: 'raw-loader', | |||
exclude: /\.async\.css$/, | |||
}, | |||
{ | |||
test: /\.scss$/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we want to configure scss in case there is no angular-cli ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should do this:
angular-cli
present -> use whatever's in their config- not present? Just fallback to good ol' css.
Technically, if they're not using the cli we aren't officially supporting it. So they should config everything manually. This feels consistent.
@amcdnl what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the vast majority of people will be using the cli so its pretty safe bet. There is the 1% case when they eject from the CLI we might need to think about ( https://github.com/angular/angular-cli/wiki/eject ) but that just nets the 'guts' of the CLI in a basic webpack config file as if you configured it manually yourself.
Personally, I'd fall under the thought process of try to handle as much as you can w/o config (seems to be a trend now i.e. parcel) so leaving the scss wouldn't hurt. Just my 2 cents tho.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so leaving the scss wouldn't hurt
Thanks your feedback, I'll revet this change 😄
…/Quramy/storybook into merge-angular-cli-webpack-config
|
||
const logger = console; | ||
|
||
export function isAngularCliInstalled() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why exporting it?
|
||
const mod = { | ||
...baseConfig.module, | ||
rules: [...cliStyleConfig.module.rules, ...styleRules], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we actually need these styleRules
if they should be filtered out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, the variable name styleRules
is so bad 🙇
This array includes rules for .jsx
, .ts
, ..., so we need it.
I'll change the variable's name.
@Quramy , you need to update snapshots to fix tests =) |
@igor-dv storyshots for Angular 🎉 ! |
@Quramy , As I understand, after this fix we can't already import global css into Having this config: import { configure } from '@storybook/angular';
import addCssWarning from '../src/cssWarning';
import '../src/assets/common.css' // <--- this
addCssWarning();
function loadStories() {
// put welcome screen at the top of the list so it's the first one displayed
require('../src/stories');
// automatically import all story ts files that end with *.stories.ts
const req = require.context('../src/stories', true, /\.stories\.ts$/)
req.keys().forEach((filename) => req(filename))
}
configure(loadStories, module); If it's ok I'll just put the css from |
Importing global CSS file manually( For instance, in "apps": [
{
:
"styles": [
"styles.css"
],
:
}
}
], So it's imported automatically as So, I think we can remove the following lines from example's config: import '../src/assets/common.css' // <--- this And move the following selector to .css-rules-warning {
display: none;
} |
Good job mate. Does it support angular 6? |
Issue: See #2645, #2688
What I did
Add ability to configure webpack using
@angular/cli
and user's.angular-cli.json
.So
@storybook/anguar
serves according to the .angular-cli.json:And if user don't have .angular-cli.json, the minimum configuration is provided as before.
How to test
See example/angular-cli manually 🙏 . I added new component and story under
examples/angular-cli/src/stories/component-with-style
. Open this story, you can see the following styled DOM:And open
localhost:9008/assets/common.css
, you can confirm that static files listed .angular-cli.json are served.