diff --git a/generators/client/files-angular.js b/generators/client/files-angular.js index 8fb1860f876f..265b2f32899a 100644 --- a/generators/client/files-angular.js +++ b/generators/client/files-angular.js @@ -41,7 +41,9 @@ const files = { '.eslintignore', 'angular.json', 'webpack/utils.js', + 'webpack/proxy.conf.js', 'webpack/webpack.common.js', + 'webpack/webpack.custom.js', 'webpack/webpack.dev.js', 'webpack/webpack.prod.js', 'postcss.config.js', diff --git a/generators/client/templates/angular/angular.json.ejs b/generators/client/templates/angular/angular.json.ejs index 1fb92ce04d23..5980476e0b65 100644 --- a/generators/client/templates/angular/angular.json.ejs +++ b/generators/client/templates/angular/angular.json.ejs @@ -32,7 +32,7 @@ "customWebpackConfig": { "path": "./webpack/webpack.custom.js" }, - "outputPath": "dist/example-ng-app", + "outputPath": "target/classes/static", "index": "src/main/webapp/index.html", "main": "src/main/webapp/app/app.main.ts", "polyfills": "src/main/webapp/app/polyfills.ts", @@ -51,6 +51,31 @@ ], "styles": ["src/main/webapp/content/scss/global.scss", "src/main/webapp/content/scss/vendor.scss"], "scripts": [] + }, + "configurations": { + "production": { + "optimization": true, + "outputHashing": "all", + "sourceMap": false, + "extractCss": true, + "namedChunks": false, + "aot": true, + "extractLicenses": true, + "vendorChunk": false, + "buildOptimizer": true, + "budgets": [ + { + "type": "initial", + "maximumWarning": "2mb", + "maximumError": "5mb" + }, + { + "type": "anyComponentStyle", + "maximumWarning": "6kb", + "maximumError": "10kb" + } + ] + } } }, "serve": { @@ -79,8 +104,7 @@ "skipTests": true } }, - "prefix": "<%= jhiPrefixDashed %>", - "architect": {} + "prefix": "<%= jhiPrefixDashed %>" } }, "defaultProject": "<%= dasherizedBaseName %>", diff --git a/generators/client/templates/angular/tsconfig.json.ejs b/generators/client/templates/angular/tsconfig.json.ejs index 6e4b0672ddaa..dddf053586d4 100644 --- a/generators/client/templates/angular/tsconfig.json.ejs +++ b/generators/client/templates/angular/tsconfig.json.ejs @@ -40,6 +40,11 @@ "importHelpers": true, "allowJs": true }, + "angularCompilerOptions": { + "fullTemplateTypeCheck": true, + "strictInjectionParameters": true, + "preserveWhitespaces": true + }, "include": [ "<%= MAIN_SRC_DIR %>app", "<%= TEST_SRC_DIR %>" diff --git a/generators/client/templates/angular/webpack/proxy.conf.js b/generators/client/templates/angular/webpack/proxy.conf.js deleted file mode 100644 index 33c85721f0e6..000000000000 --- a/generators/client/templates/angular/webpack/proxy.conf.js +++ /dev/null @@ -1,9 +0,0 @@ -const PROXY_CONFIG = [ - { - context: ['/api', '/services', '/management', '/swagger-resources', '/v2/api-docs', '/h2-console', '/auth'], - target: `http://localhost:8080`, - secure: false - } - ]; - - module.exports = PROXY_CONFIG; diff --git a/generators/client/templates/angular/webpack/proxy.conf.js.ejs b/generators/client/templates/angular/webpack/proxy.conf.js.ejs new file mode 100644 index 000000000000..1963aca312b7 --- /dev/null +++ b/generators/client/templates/angular/webpack/proxy.conf.js.ejs @@ -0,0 +1,12 @@ +function setupProxy() { + const tls = process.env.TLS; + const conf = { + context: ['/api', '/services', '/management', '/swagger-resources', '/v2/api-docs', '/h2-console', '/auth'], + target: `http${tls ? 's' : ''}://localhost:8080`, + secure: false, + changeOrigin: tls + }; + return conf; +} + +module.exports = setupProxy(); diff --git a/generators/client/templates/angular/webpack/webpack.custom.js b/generators/client/templates/angular/webpack/webpack.custom.js deleted file mode 100644 index 3d1b314bfc4f..000000000000 --- a/generators/client/templates/angular/webpack/webpack.custom.js +++ /dev/null @@ -1,31 +0,0 @@ -const webpack = require('webpack'); -const MergeJsonWebpackPlugin = require('merge-jsons-webpack-plugin'); - -module.exports = (config, options) => { - console.log(options); - config.plugins.push( - new webpack.DefinePlugin({ - 'process.env': { - BUILD_TIMESTAMP: `'${new Date().getTime()}'`, - // APP_VERSION is passed as an environment variable from the Gradle / Maven build tasks. - VERSION: `'${process.env.hasOwnProperty('APP_VERSION') ? process.env.APP_VERSION : 'DEV'}'`, - // DEBUG_INFO_ENABLED: options.env === 'development', - // The root URL for API calls, ending with a '/' - for example: `"https://www.jhipster.tech:8081/myservice/"`. - // If this URL is left empty (""), then it will be relative to the current context. - // If you use an API server, in `prod` mode, you will need to enable CORS - // (see the `jhipster.cors` common JHipster property in the `application-*.yml` configurations) - SERVER_API_URL: `''` - } - }), - new MergeJsonWebpackPlugin({ - output: { - groupBy: [ - { pattern: './src/main/webapp/i18n/en/*.json', fileName: './i18n/en.json' } - // jhipster-needle-i18n-language-webpack - JHipster will add/remove languages in this array - ] - } - }) - ); - - return config; -}; diff --git a/generators/client/templates/angular/webpack/webpack.custom.js.ejs b/generators/client/templates/angular/webpack/webpack.custom.js.ejs new file mode 100644 index 000000000000..fc5883ed78d0 --- /dev/null +++ b/generators/client/templates/angular/webpack/webpack.custom.js.ejs @@ -0,0 +1,84 @@ +const webpack = require('webpack'); +const MergeJsonWebpackPlugin = require('merge-jsons-webpack-plugin'); +const SimpleProgressWebpackPlugin = require('simple-progress-webpack-plugin'); +const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin'); +const BrowserSyncPlugin = require('browser-sync-webpack-plugin'); + +module.exports = (config, options) => { + // RULES + if (config.mode === 'development') { + config.module.rules.push({ + test: /\.(j|t)s$/, + enforce: 'pre', + loader: 'eslint-loader', + exclude: /node_modules/ + }); + } + + // STATS + if (config.mode === 'development') { + config.stats = 'minimal'; + } + + // PLUGINS + if (config.mode === 'development') { + config.plugins.push( + new FriendlyErrorsWebpackPlugin(), + new BrowserSyncPlugin( + { + https: false, + host: 'localhost', + port: 9000, + proxy: { + target: `http://localhost:4200`, + proxyOptions: { + changeOrigin: false //pass the Host header to the backend unchanged https://github.com/Browsersync/browser-sync/issues/430 + } + }, + socket: { + clients: { + heartbeatTimeout: 60000 + } + } + }, + { + reload: false + } + ) + ); + + if (!process.env.JHI_DISABLE_WEBPACK_LOGS) { + config.plugins.push( + new SimpleProgressWebpackPlugin({ + format: 'compact' + }) + ); + } + } + + config.plugins.push( + new webpack.DefinePlugin({ + 'process.env': { + BUILD_TIMESTAMP: `'${new Date().getTime()}'`, + // APP_VERSION is passed as an environment variable from the Gradle / Maven build tasks. + VERSION: `'${process.env.hasOwnProperty('APP_VERSION') ? process.env.APP_VERSION : 'DEV'}'`, + DEBUG_INFO_ENABLED: true, + // The root URL for API calls, ending with a '/' - for example: `"https://www.jhipster.tech:8081/myservice/"`. + // If this URL is left empty (""), then it will be relative to the current context. + // If you use an API server, in `prod` mode, you will need to enable CORS + // (see the `jhipster.cors` common JHipster property in the `application-*.yml` configurations) + SERVER_API_URL: `''` + } + }), + new MergeJsonWebpackPlugin({ + output: { + groupBy: [ + { pattern: './src/main/webapp/i18n/en/*.json', fileName: './i18n/en.json' } + // jhipster-needle-i18n-language-webpack - JHipster will add/remove languages in this array + ] + } + }) + ); + + return config; +};