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

feat(stark-build): implement integration with Angular CLI via @angular-builders #1148

Conversation

christophercr
Copy link
Collaborator

@christophercr christophercr commented Feb 22, 2019

ISSUES CLOSED: #883, #146, #114

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[X] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[X] Build related changes
[X] CI related changes
[X] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

Stark based apps are not compatible with Angular CLI due to the customizations done in Stark-Build.

Issue Number: #883, #146, #114 #1036

What is the new behavior?

Stark-Build now overrides and expands the default build configuration from Angular CLI to leverage the functionalities needed for the different Stark packages.

Does this PR introduce a breaking change?

[X] Yes
[ ] No

Other information

@christophercr christophercr force-pushed the feature/angular-cli-custom-builders branch 2 times, most recently from f24adbc to 3b5e1dc Compare February 22, 2019 15:07
@coveralls
Copy link

coveralls commented Feb 22, 2019

Coverage Status

Coverage decreased (-0.005%) to 93.473% when pulling 9a26c00 on christophercr:feature/angular-cli-custom-builders into 92496bc on NationalBankBelgium:master.

@christophercr christophercr added this to the 10.0.0-beta.5 milestone Feb 22, 2019
@christophercr christophercr force-pushed the feature/angular-cli-custom-builders branch 2 times, most recently from b26b40c to 7b9326e Compare February 22, 2019 17:22
@@ -88,7 +115,7 @@
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"builder": "@angular-builders/dev-server:generic",
"options": {
"browserTarget": "showcase:build"
Copy link
Member

Choose a reason for hiding this comment

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

With the previous implementation, the default port was 3000 and by default, the url was opened automatically in the default browser.

What do you think of keeping those 2 configurations ? 😊

We can add them back by adding those 2 options:

"options": {
  "browserTarget": "showcase:build",
  "port": 3000,
  "open": true
},

Copy link
Collaborator Author

@christophercr christophercr Feb 25, 2019

Choose a reason for hiding this comment

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

Mmm I was hesitating about that... and now that I think of it, I don't see why should use a different port from the default one that NG CLI uses, don't you think?

On the other hand, I do find it useful to open automatically the browser, so I'll that option

@@ -84,7 +111,7 @@
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"builder": "@angular-builders/dev-server:generic",
"options": {
"browserTarget": "starter:build"
Copy link
Member

Choose a reason for hiding this comment

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

Same as showcase/angular.json

@@ -1,4 +1,4 @@
{
"cspConnectSrc": "http://localhost:5000 http://localhost:5001 http://localhost:5002 http://localhost:4000 https://nationalbankbelgium.github.io",
"cspConnectSrc": "http://localhost:5000 http://localhost:5001 http://localhost:5002 http://localhost:4000 https://nationalbankbelgium.github.io ws://localhost:4200",
Copy link
Member

Choose a reason for hiding this comment

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

This is already managed in wepack-dev-server in webpack-partial.dev.js.
I think we can remove this change 😊

Copy link
Collaborator Author

@christophercr christophercr Feb 25, 2019

Choose a reason for hiding this comment

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

In fact, that was my bad... I think we should not modify the HOST and PORT via environment variables anymore because NG CLI already allows this via an option.

So I guess we need to change the CSP directive in webpack-partial.dev.js like this:
"connect-src 'self' ws://localhost:4200 " + webpackCustomConfig["cspConnectSrc"],

Copy link
Member

Choose a reason for hiding this comment

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

If we can get the default port and default host or the values defined in angular.json (if defined), I think it would be better to keep the previous scenario in cspDirectives in webpack-partial.dev.js --> "connect-src 'self' ws://" + METADATA.HOST + ":" + METADATA.PORT + " " " + webpackCustomConfig["cspConnectSrc"]

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

True, I'm fixing this

Copy link
Member

Choose a reason for hiding this comment

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

You forgot to remove your change here.
It should be "cspConnectSrc": "http://localhost:5000 http://localhost:5001 http://localhost:5002 http://localhost:4000 https://nationalbankbelgium.github.io",

"serve": {
"builder": "@angular-builders/dev-server:generic",
"options": {
"browserTarget": "your-app:build"
Copy link
Member

Choose a reason for hiding this comment

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

If you apply the asked modification about the port and the automatic opening, don't forget to apply it here 😊

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think it is necessary to add it in this doc, the host and port are just app specific so in Stark we don't really care about it

},
"configurations": {
"hmr": {
"browserTarget": "yourProjectName:build:hmr"
Copy link
Member

Choose a reason for hiding this comment

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

This should be "browserTarget": "your-app:build:hmr"

@@ -26,13 +26,15 @@
"npm": ">=5.6.0"
},
"scripts": {
"build:aot:prod": "npm run clean:dist && npm run clean:aot && cross-env BUILD_AOT=1 npm run webpack -- --config node_modules/@nationalbankbelgium/stark-build/config/webpack.prod.js --progress --profile --bail",
"build:aot:prod": "npm run clean:dist && npm run clean:aot && npm run ng -- build --aot=true --prod=true --buildOptimizer=true",
Copy link
Member

Choose a reason for hiding this comment

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

Same here about the arguments --aot and --buildOptimizer

<% for (let i = 0; i < htmlWebpackPlugin.options.dllFiles.css.length; ++i) { %>
<link href="<%= htmlWebpackPlugin.options.dllFiles.css[i] %>" rel="stylesheet" />
<% } %> <% } %>
<!--<% if (htmlWebpackPlugin.options.dllFiles) { %>-->
Copy link
Member

Choose a reason for hiding this comment

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

Do we plan to have support for dll files later ?

Copy link
Member

Choose a reason for hiding this comment

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

@christophercr What about this ? 😊

IS_DEV_SERVER: helpers.hasProcessFlag("serve"),
HMR: helpers.hasProcessFlag("hmr"),
AOT: helpers.hasProcessFlag("aot"),
E2E: helpers.hasProcessFlag("e2e"),
Copy link
Member

Choose a reason for hiding this comment

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

I don't see anywhere in our current package.json the flag --e2e. Can you confirm it is correct ? 😊

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed, the flag is not used... I kept it just in case... we should find a way to know whether the build is for e2e... but I think we can do that later

PORT: process.env.PORT || 4200,
ENV: isProd ? "production" : "development",
environment: helpers.hasProcessFlag("hmr") ? "hmr" : "dev",
WATCH: !helpers.hasProcessFlag("watch=false"),
Copy link
Member

Choose a reason for hiding this comment

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

Why keeping this logic in build-utils.js and repeating it here ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

True, I'll remove it from here

PORT: process.env.PORT || 4200,
ENV: isProd ? "production" : "development",
environment: helpers.hasProcessFlag("e2e") ? "e2e.prod" : "prod",
IS_DEV_SERVER: false
Copy link
Member

Choose a reason for hiding this comment

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

Why keeping this logic in build-utils.js and repeating it here ?

Copy link
Collaborator

@carlo-nomes carlo-nomes left a comment

Choose a reason for hiding this comment

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

After a clean:slate I get a whole bunch of errors in my console.
(icon.es5.js:808 Error: <path> attribute d: Expected number, "mdi-ubisoft".) and the icons are not working, I think something with mdi?

I also get this warning in my console I didn't seem to get before.

WARNING in ./src/styles/styles.scss (./node_modules/@angular-devkit/build-angular/src/angular-cli-files/plugins/raw-css-loader.js!./node_modules/postcss-loader/src??embedded!./node_modules/sass-loader/lib/loader.js??ref--14-3!./src/styles/styles.scss)
Module Warning (from ./node_modules/postcss-loader/src/index.js):
Warning

(3726:7) start value has mixed support, consider using flex-start instead
 @ ./src/styles/styles.scss 2:14-250
 @ multi ./node_modules/@nationalbankbelgium/stark-core/assets/css/pre-load-style.css ./src/styles/styles.scss ./src/styles/styles.pcss

"plugins": "prepend",
"devServer": "prepend",
"replaceDuplicatePlugins": false
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is prepend needed?

|
+---yourApp
| +---assets
| | +---stark-core // assets from Stark-Core should be available at this location
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the indentation correct here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nop, I'll fix it ;)

|
+---yourApp
| +---assets
| | +---stark-ui // assets from Stark-UI should be available at this location
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the indentation correct here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nop, I'll fix it ;)

// env MONITOR variable set via cross-env
if (process.env.MONITOR) {
MONITOR = !!process.env.MONITOR;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doesn't const MONITOR = !!process.env.MONITOR also work?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

True, it is cleaner... I'll fix it ;)

// env BUNDLE_ANALYZER variable set via cross-env
if (process.env.BUNDLE_ANALYZER) {
BUNDLE_ANALYZER = !!process.env.BUNDLE_ANALYZER;
}
Copy link
Collaborator

@carlo-nomes carlo-nomes Feb 25, 2019

Choose a reason for hiding this comment

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

Doesn't const BUNDLE_ANALYZER = !!process.env.BUNDLE_ANALYZER also work?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

True, it is cleaner... I'll fix it ;)

@carlo-nomes
Copy link
Collaborator

@christophercr, I was wrong it is the update of @mdi/material-icons

@christophercr christophercr force-pushed the feature/angular-cli-custom-builders branch 2 times, most recently from 91eeb47 to a03d172 Compare February 25, 2019 16:55
@christophercr
Copy link
Collaborator Author

@SuperITMan @cnomes I've updated my PR with your remarks. I also fixed the warning about (3726:7) start value has mixed support, consider using flex-start instead .

Can you review this PR again?

@christophercr
Copy link
Collaborator Author

christophercr commented Feb 25, 2019

@cnomes it seems that they noticed the version 3.5.94 from @mdi/material-icons was buggy so they un-released it :P

#1151
https://travis-ci.org/NationalBankBelgium/stark/builds/498287079
https://www.npmjs.com/package/@mdi/angular-material
Templarian/MaterialDesign-Angular-Material#5

Copy link
Member

@SuperITMan SuperITMan left a comment

Choose a reason for hiding this comment

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

Still some improvements we could apply 😊

@@ -26,13 +26,15 @@
"npm": ">=5.6.0"
},
"scripts": {
"build:aot:prod": "npm run clean:dist && npm run clean:aot && cross-env BUILD_AOT=1 npm run webpack -- --config node_modules/@nationalbankbelgium/stark-build/config/webpack.prod.js --progress --profile --bail",
"build:aot:prod": "npm run clean:dist && npm run clean:aot && npm run ng -- build --prod=true --configuration=production",
Copy link
Member

Choose a reason for hiding this comment

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

--prod is enough, you don't need to add =true 😊
Also, you don't need --configuration=production because it is automatically done by Angular CLI when you set --prod.

<% for (let i = 0; i < htmlWebpackPlugin.options.dllFiles.css.length; ++i) { %>
<link href="<%= htmlWebpackPlugin.options.dllFiles.css[i] %>" rel="stylesheet" />
<% } %> <% } %>
<!--<% if (htmlWebpackPlugin.options.dllFiles) { %>-->
Copy link
Member

Choose a reason for hiding this comment

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

@christophercr What about this ? 😊

@@ -26,16 +26,16 @@
"npm": ">=5.6.0"
},
"scripts": {
"build:aot:prod": "npm run clean:dist && npm run clean:aot && cross-env BUILD_AOT=1 npm run webpack -- --config node_modules/@nationalbankbelgium/stark-build/config/webpack.prod.js --progress --profile --bail",
"build:aot:prod:ci-test-env": "npm run clean:dist && npm run clean:aot && cross-env BUILD_AOT=1 npm run webpack -- --config node_modules/@nationalbankbelgium/stark-build/config/webpack.prod.js --progress --profile --bail --ci-test-env",
"build:aot:prod": "npm run clean:dist && npm run clean:aot && npm run ng -- build --prod=true --configuration=production",
Copy link
Member

@SuperITMan SuperITMan Feb 25, 2019

Choose a reason for hiding this comment

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

--prod is enough, you don't need to add =true 😊
Also, you don't need --configuration=production because it is automatically done by Angular CLI when you set --prod.

@@ -1,4 +1,4 @@
{
"cspConnectSrc": "http://localhost:5000 http://localhost:5001 http://localhost:5002 http://localhost:4000 https://nationalbankbelgium.github.io",
"cspConnectSrc": "http://localhost:5000 http://localhost:5001 http://localhost:5002 http://localhost:4000 https://nationalbankbelgium.github.io ws://localhost:4200",
Copy link
Member

Choose a reason for hiding this comment

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

You forgot to remove your change here.
It should be "cspConnectSrc": "http://localhost:5000 http://localhost:5001 http://localhost:5002 http://localhost:4000 https://nationalbankbelgium.github.io",

const METADATA = Object.assign({}, buildUtils.DEFAULT_METADATA, {
HOST: buildUtils.ANGULAR_APP_CONFIG.config.architect.serve.options.host || helpers.getNgCliCommandOption("host") || "localhost", // by default is "localhost"
PORT: buildUtils.ANGULAR_APP_CONFIG.config.architect.serve.options.port || helpers.getNgCliCommandOption("port") || 4200, // by default is 4200
ENV: isProd ? "production" : "development",
Copy link
Member

Choose a reason for hiding this comment

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

Those variables should be part of buildUtils.DEFAULT_METADATA because they are exactly the same in DEV and in PRO...

ENV: isProd ? "production" : "development",
BASE_URL: buildUtils.ANGULAR_APP_CONFIG.buildConfigurations.production.baseHref,
HMR: buildUtils.ANGULAR_APP_CONFIG.buildConfigurations.production.hmr || helpers.hasProcessFlag("hmr"),
AOT: buildUtils.ANGULAR_APP_CONFIG.buildConfigurations.production.aot || helpers.hasProcessFlag("aot"),
WATCH: !(buildUtils.ANGULAR_APP_CONFIG.buildConfigurations.production.watch === false) || !helpers.hasProcessFlag("watch=false"), // by default is true	
IS_DEV_SERVER: helpers.hasProcessFlag("serve") && !isProd

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nop, they are different.... in DEV they are taken from buildUtils.ANGULAR_APP_CONFIG.buildOptions and in PROD from buildUtils.ANGULAR_APP_CONFIG.buildConfigurations.production

"build:aot:dev": "cross-env BUILD_AOT=1 npm run build:dev",
"build:dev": "npm run clean:dist && npm run webpack -- --config node_modules/@nationalbankbelgium/stark-build/config/webpack.dev.js --progress --profile",
"build:dev:monitor": "npx mkdirp reports && npm run build:dev -- --env.monitor",
"build:aot:dev": "npm run build:dev -- --aot=true",
Copy link
Member

Choose a reason for hiding this comment

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

--aot is enough, you don't need to add =true 😊

"server:dev:hmr": "npm run server:dev -- --hot",
"server:aot:dev": "cross-env BUILD_AOT=1 npm run server:dev",
"server:dev": "npm run clean:dist && npm run webpack-dev-server -- --config node_modules/@nationalbankbelgium/stark-build/config/webpack.dev.js --open --progress --profile --watch --content-base src/",
"server:dev:hmr": "npm run server:dev -- --hmr=true --configuration=hmr",
Copy link
Member

Choose a reason for hiding this comment

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

For this specifig case, it's a bit different.
According to the official documentation, you can run npm run server:dev -- --configuration hmr.

Of course you have to adapt add a line in your angular.json.

"server:aot:dev": "cross-env BUILD_AOT=1 npm run server:dev",
"server:dev": "npm run clean:dist && npm run webpack-dev-server -- --config node_modules/@nationalbankbelgium/stark-build/config/webpack.dev.js --open --progress --profile --watch --content-base src/",
"server:dev:hmr": "npm run server:dev -- --hmr=true --configuration=hmr",
"server:aot:dev": "npm run server:dev -- --aot=true",
Copy link
Member

Choose a reason for hiding this comment

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

Same here, you can simply put npm run server:dev -- --aot

"browserTarget": "showcase:build"
"browserTarget": "showcase:build",
"port": 3000,
"open": true
},
"configurations": {
"hmr": {
Copy link
Member

Choose a reason for hiding this comment

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

To make hmr working, please set it like this (according to the official doc):

"hmr": {
  "hmr": true,
  "browserTarget": "showcase:build:hmr"
}

"browserTarget": "starter:build"
"browserTarget": "starter:build",
"port": 3000,
"open": true
},
"configurations": {
"hmr": {
Copy link
Member

Choose a reason for hiding this comment

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

To make hmr working, please set it like this (according to the official doc):

"hmr": {
  "hmr": true,
  "browserTarget": "showcase:build:hmr"
}

@SuperITMan
Copy link
Member

Also, in the commit message, don't forget the mention to BREAKING CHANGE. Otherwise, it won't appear in our CHANGELOG 😕

@SuperITMan SuperITMan self-requested a review February 26, 2019 00:09
Copy link
Member

@SuperITMan SuperITMan left a comment

Choose a reason for hiding this comment

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

Due to a wrong manipulation I have to redo this 😛

@christophercr christophercr force-pushed the feature/angular-cli-custom-builders branch from a03d172 to b91c616 Compare February 26, 2019 13:16
@christophercr
Copy link
Collaborator Author

christophercr commented Feb 26, 2019

@cnomes @SuperITMan I've updated the PR with the latest remarks. Could you please have a look?

I just need to change the commit message with the breaking changes...

@christophercr christophercr force-pushed the feature/angular-cli-custom-builders branch 2 times, most recently from 87c43cf to b97756c Compare February 26, 2019 15:15
@christophercr
Copy link
Collaborator Author

And.. I've updated the commit message to add the breaking changes 😉

…r-builders

ISSUES CLOSED: #883, #146, #114

BREAKING CHANGE: stark-build now integrates with Angular CLI:

   - **stark-build:** now provides partial Webpack configurations to override default configuration from Angular CLI. The application's `angular.json` file must be adapted to use this partial configs from stark-build via [@angular-builders](https://github.com/meltedspark/angular-builders). See [Stark-Build: Ng CLI Customizations](./docs/stark-build/NG_CLI_BUILD_CUSTOMIZATIONS.md)
   - **stark-core:** the application's `angular.json` file must be adapted to add the assets from stark-core to be copied to the application's `assets` folder. See [Stark-Core: Getting Started](./docs/stark-core/GETTING_STARTED.md#assets)
   - **stark-ui:** the application's `angular.json` file must be adapted to add the assets from stark-ui to be copied to the application's `assets` folder. See [Stark-UI: Getting Started](./docs/stark-ui/GETTING_STARTED.md#assets)
@christophercr christophercr force-pushed the feature/angular-cli-custom-builders branch from b97756c to 9a26c00 Compare February 26, 2019 15:29
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.

build: implement builders for using with NG CLI
4 participants