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

Angular build time optimization #4118

Merged
merged 20 commits into from
Sep 20, 2018

Conversation

kroeder
Copy link
Member

@kroeder kroeder commented Sep 4, 2018

Issue: #3968

What I did

Note: This is work-in-progress

  • Renamed loadTsConfig to getTsLoaderOptions because that is what it actually does (5801057#diff-aaa47dcc2ee48513f45210bb35a92d4cR1)
  • Set transpileOnly: true as default option for ts-loader
  • Added fork-ts-checker-webpack-plugin as a dependency in app/angular
  • Use ForkTsChecker and set option tsconfig to the same that is used for ts-loader (using getTsLoaderOptions)

Checklist

  • Set transpileOnly: true as default ts-loader option
  • Add ForkTsChecker to the list of plugins
  • Verify it works
  • Check, why ForkTsChecker does check jest (ERROR in D:/04_Development/ng-projects/storybook/node_modules/@types/jest/index.d.ts(1103,9): and many more in this file)
  • Update documentation
  • Update test-case ts_config.test.js

How to test

Is this testable with Jest or Chromatic screenshots? yes
Does this need a new example in the kitchen sink apps? no
Does this need an update to the documentation? yes

If your answer is yes to any of these, please make sure to include it in your PR.

Manual test:
Start yarn storybook in examples/angular-cli/

Using ForkTsChecker adds the folloing message when starting storybook

Starting type checking service...
Using 1 worker with 2048MB memory limit

For maintainers only: Please tag your pull request with at least one of the following:
["cleanup", "BREAKING CHANGE", "feature request", "bug", "documentation", "maintenance", "dependencies", "other"]

@kroeder
Copy link
Member Author

kroeder commented Sep 4, 2018

Please note: I had yarn test --core errors right from the beginning when forking master. Is this a known thing?

@ndelangen
Copy link
Member

@igor-dv please verify if this is compatible with your preset PR

@igor-dv
Copy link
Member

igor-dv commented Sep 6, 2018

I will review it soon (or when I will be bored of doing nothing in a vacation)

app/angular/src/server/ts_config.js Show resolved Hide resolved
@@ -1,45 +1,55 @@
import path from 'path';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please solve merge conflicts here, it moved to framework-preset-angular

path.resolve(__dirname, '..')
),
new ForkTsCheckerWebpackPlugin({
tsconfig: tsLoaderOptions.configFile,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what will happen if there is not a configFile ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, if tslint is always located in root, we can also add it here (just check if it exists).

@kroeder
Copy link
Member Author

kroeder commented Sep 10, 2018

Thanks for your comments! Do you think I should revert + change my approach to fit in into the new template feature?

@igor-dv
Copy link
Member

igor-dv commented Sep 10, 2018

I don't think you need to revert. The preset has a similar structure, just move your changes there

@igor-dv
Copy link
Member

igor-dv commented Sep 16, 2018

@kroeder, do you need help to finish this?

@kroeder
Copy link
Member Author

kroeder commented Sep 16, 2018

Normally I would say "no" but I spent hours trouble shooting why my project does not build, start, tests on master fail.. Even on a fresh checkout :( btw. I am the one asking lots of questions in slack. I'll try to continue today

# Conflicts:
#	app/angular/src/server/wrapInitialConfig.js

Created a function for ForkTsCheckerWebpackPlugin
Added tests for ForkTsCheckerWebpackPlugin
@kroeder
Copy link
Member Author

kroeder commented Sep 16, 2018

I created a seperate file for creating an instance of ForkTsChecker and added tests for it.

@@ -9,7 +9,7 @@
"e2e": "ng e2e",
"ng": "ng",
"start": "ng serve",
"storybook": "npm run storybook:prebuild && start-storybook -p 9008 -s src/assets",
"storybook": "start-storybook -p 9008 -s src/assets",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've fixed this, please merge from master and revert this

@kroeder
Copy link
Member Author

kroeder commented Sep 18, 2018

Checks are fine now, finally! I just need to integrate the cli stuff as well as the updated documentation for this PR. Anything else you want to add/change?

@codecov
Copy link

codecov bot commented Sep 19, 2018

Codecov Report

Merging #4118 into master will increase coverage by 0.03%.
The diff coverage is 75%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4118      +/-   ##
==========================================
+ Coverage   40.75%   40.78%   +0.03%     
==========================================
  Files         492      493       +1     
  Lines        5845     5852       +7     
  Branches      781      782       +1     
==========================================
+ Hits         2382     2387       +5     
- Misses       3087     3089       +2     
  Partials      376      376
Impacted Files Coverage Δ
app/angular/src/server/framework-preset-angular.js 0% <0%> (ø) ⬆️
app/angular/src/server/ts_config.js 100% <100%> (ø) ⬆️
...ngular/src/server/create-fork-ts-checker-plugin.js 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a6697e4...6070cb8. Read the comment docs.

@kroeder
Copy link
Member Author

kroeder commented Sep 19, 2018

I added tsconfig.json to the angular-cli getstorybook template and updated the documentation.

How can I verify, that getstorybook works for angular-cli projects?

Copy link
Member

@igor-dv igor-dv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor comments

We are almost there =)

require('fs').__setMockFiles(files);
};

describe('framework-preset-ts-fork-checker-plugin', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create-fork-ts-checker-plugin.test

@@ -73,6 +73,27 @@ That'll load stories in `../src/stories/index.ts`.

Just like that, you can load stories from wherever you want to.

## Storybook TypeScript configuration

**Note:** You need this only if you are using Storybook `>= 4.0.0-alpha.22`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can mention that this file is created with a Storybok cli (storybook init that was getstorybook before)
Also, maybe you can mention that there is a use of ForkTsCheckerWebpackPlugin to boost the performance.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can mention that but the whole guide is more or less a complete "manual installation" guide, isn't it?

https://storybook.js.org/basics/guide-angular/

If you want to set up Storybook manually, this is the guide for you.

Regarding ForkTsCheckerWebpackPlugin I'll add that.

@igor-dv
Copy link
Member

igor-dv commented Sep 20, 2018

How can I verify, that getstorybook works for angular-cli projects?

getstorybook is now called storybook init from the @storybook/cli

@Keraito, how are you testing CLI?

@Keraito
Copy link
Contributor

Keraito commented Sep 20, 2018

@igor-dv As said on discord, atm manually on dummy projects. Still trying to come up with something else that doesn't have the same issues as the removed CLI snapshots.

@kroeder what are you exactly trying to verify with the CLI?

@kroeder
Copy link
Member Author

kroeder commented Sep 20, 2018

@Keraito I want to check if a custom tsconfig.json is created on storybook init (only for angular cli projects) and that a fresh project with storybook init still works out of the box.

@Keraito
Copy link
Contributor

Keraito commented Sep 20, 2018

I want to check if a custom tsconfig.json is created on storybook init (only for angular cli projects)

The easiest for now is to probably check this manually for now. Tagging #1108 so I don't forget this.

that a fresh project with storybook init still works out of the box.

You can use a smoke test for this. https://github.com/storybooks/storybook/tree/master/lib/cli/test/fixtures Add a example project here without Storybook installed. Running yarn test --cli will trigger the storybook init command, install deps and then start Storybook in it. It will give an error if the Storybook doesn't start successfully (make sure you merged the changes from #4194 through master already)

@kroeder
Copy link
Member Author

kroeder commented Sep 20, 2018

I npm linked lib/cli and created a fresh angular project. storybook init now creates a tsconfig.json inside .storybook. I also linked my changes from @storybook/angular. Everything seems to work but I get the following error

Module build failed (from ./node_modules/postcss-loader/lib/index.js):
Syntax Error 

(2:1) Unknown word

  1 | 
> 2 | var content = require("!!../node_modules/css-loader/index.js??ref--17-1!../node_modules/@storybook/core/node_modules/postcss-loader/src/index.js??postcss!./styles.css");
    | ^
  3 | 
  4 | if(typeof content === 'string') content = [[module.id, content, '']];

 @ ./src/styles.css 2:14-325 21:1-42:3 22:19-330
 @ multi ./node_modules/@storybook/core/dist/server/config/polyfills.js ./node_modules/@storybook/core/dist/server/config/globals.js ./.storybook/config.js ./node_modules/webpack-hot-middleware/client.js?reload=true ./src/styles.css
i 「wdm」: Failed to compile.

I don't know if it's related to my PR - anyone knows something about this error?

If this is not related to my PR I'm done, so far. 👍

@igor-dv
Copy link
Member

igor-dv commented Sep 20, 2018

I think it's not related 👍

@igor-dv igor-dv closed this Sep 20, 2018
@igor-dv igor-dv reopened this Sep 20, 2018
@igor-dv igor-dv merged commit 71fb0da into storybookjs:master Sep 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants