-
Notifications
You must be signed in to change notification settings - Fork 23
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
feat(stark-build): implement integration with Angular CLI via @angular-builders #1148
Conversation
f24adbc
to
3b5e1dc
Compare
b26b40c
to
7b9326e
Compare
showcase/angular.json
Outdated
@@ -88,7 +115,7 @@ | |||
} | |||
}, | |||
"serve": { | |||
"builder": "@angular-devkit/build-angular:dev-server", | |||
"builder": "@angular-builders/dev-server:generic", | |||
"options": { | |||
"browserTarget": "showcase:build" |
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.
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
},
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.
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
starter/angular.json
Outdated
@@ -84,7 +111,7 @@ | |||
} | |||
}, | |||
"serve": { | |||
"builder": "@angular-devkit/build-angular:dev-server", | |||
"builder": "@angular-builders/dev-server:generic", | |||
"options": { | |||
"browserTarget": "starter:build" |
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.
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", |
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 already managed in wepack-dev-server in webpack-partial.dev.js
.
I think we can remove this change 😊
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.
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"],
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.
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"]
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.
True, I'm fixing this
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.
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" |
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.
If you apply the asked modification about the port and the automatic opening, don't forget to apply it here 😊
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 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" |
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 be "browserTarget": "your-app:build:hmr"
starter/package.json
Outdated
@@ -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", |
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.
Same here about the arguments --aot
and --buildOptimizer
showcase/src/index.html
Outdated
<% for (let i = 0; i < htmlWebpackPlugin.options.dllFiles.css.length; ++i) { %> | ||
<link href="<%= htmlWebpackPlugin.options.dllFiles.css[i] %>" rel="stylesheet" /> | ||
<% } %> <% } %> | ||
<!--<% if (htmlWebpackPlugin.options.dllFiles) { %>--> |
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 plan to have support for dll files later ?
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.
@christophercr What about this ? 😊
IS_DEV_SERVER: helpers.hasProcessFlag("serve"), | ||
HMR: helpers.hasProcessFlag("hmr"), | ||
AOT: helpers.hasProcessFlag("aot"), | ||
E2E: helpers.hasProcessFlag("e2e"), |
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 don't see anywhere in our current package.json
the flag --e2e
. Can you confirm it is correct ? 😊
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.
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"), |
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 keeping this logic in build-utils.js
and repeating it here ?
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.
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 |
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 keeping this logic in build-utils.js
and repeating it here ?
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.
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 | ||
} |
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 is prepend
needed?
docs/stark-core/GETTING_STARTED.md
Outdated
| | ||
+---yourApp | ||
| +---assets | ||
| | +---stark-core // assets from Stark-Core should be available at this location |
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.
Is the indentation correct here?
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.
Nop, I'll fix it ;)
docs/stark-ui/GETTING_STARTED.md
Outdated
| | ||
+---yourApp | ||
| +---assets | ||
| | +---stark-ui // assets from Stark-UI should be available at this location |
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.
Is the indentation correct here?
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.
Nop, I'll fix it ;)
// env MONITOR variable set via cross-env | ||
if (process.env.MONITOR) { | ||
MONITOR = !!process.env.MONITOR; | ||
} |
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.
Doesn't const MONITOR = !!process.env.MONITOR
also work?
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.
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; | ||
} |
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.
Doesn't const BUNDLE_ANALYZER = !!process.env.BUNDLE_ANALYZER
also work?
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.
True, it is cleaner... I'll fix it ;)
@christophercr, I was wrong it is the update of |
91eeb47
to
a03d172
Compare
@SuperITMan @cnomes I've updated my PR with your remarks. I also fixed the warning about Can you review this PR again? |
@cnomes it seems that they noticed the version 3.5.94 from #1151 |
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.
Still some improvements we could apply 😊
starter/package.json
Outdated
@@ -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", |
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.
--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
.
showcase/src/index.html
Outdated
<% for (let i = 0; i < htmlWebpackPlugin.options.dllFiles.css.length; ++i) { %> | ||
<link href="<%= htmlWebpackPlugin.options.dllFiles.css[i] %>" rel="stylesheet" /> | ||
<% } %> <% } %> | ||
<!--<% if (htmlWebpackPlugin.options.dllFiles) { %>--> |
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.
@christophercr What about this ? 😊
showcase/package.json
Outdated
@@ -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", |
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.
--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", |
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.
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", |
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.
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
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.
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
showcase/package.json
Outdated
"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", |
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.
--aot
is enough, you don't need to add =true
😊
showcase/package.json
Outdated
"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", |
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.
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.
showcase/package.json
Outdated
"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", |
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.
Same here, you can simply put npm run server:dev -- --aot
"browserTarget": "showcase:build" | ||
"browserTarget": "showcase:build", | ||
"port": 3000, | ||
"open": true | ||
}, | ||
"configurations": { | ||
"hmr": { |
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.
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": { |
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.
To make hmr working, please set it like this (according to the official doc):
"hmr": {
"hmr": true,
"browserTarget": "showcase:build:hmr"
}
Also, in the commit message, don't forget the mention to BREAKING CHANGE. Otherwise, it won't appear in our CHANGELOG 😕 |
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.
Due to a wrong manipulation I have to redo this 😛
a03d172
to
b91c616
Compare
@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... |
87c43cf
to
b97756c
Compare
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)
b97756c
to
9a26c00
Compare
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?
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?
Other information