Skip to content

Commit

Permalink
Add config for dev and prod mode
Browse files Browse the repository at this point in the history
  • Loading branch information
William Marques committed Oct 15, 2019
1 parent 7c76001 commit b38d226
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 43 deletions.
2 changes: 2 additions & 0 deletions generators/client/files-angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
30 changes: 27 additions & 3 deletions generators/client/templates/angular/angular.json.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand Down Expand Up @@ -79,8 +104,7 @@
"skipTests": true
}
},
"prefix": "<%= jhiPrefixDashed %>",
"architect": {}
"prefix": "<%= jhiPrefixDashed %>"
}
},
"defaultProject": "<%= dasherizedBaseName %>",
Expand Down
5 changes: 5 additions & 0 deletions generators/client/templates/angular/tsconfig.json.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
"importHelpers": true,
"allowJs": true
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true,
"preserveWhitespaces": true
},
"include": [
"<%= MAIN_SRC_DIR %>app",
"<%= TEST_SRC_DIR %>"
Expand Down
9 changes: 0 additions & 9 deletions generators/client/templates/angular/webpack/proxy.conf.js

This file was deleted.

12 changes: 12 additions & 0 deletions generators/client/templates/angular/webpack/proxy.conf.js.ejs
Original file line number Diff line number Diff line change
@@ -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();
31 changes: 0 additions & 31 deletions generators/client/templates/angular/webpack/webpack.custom.js

This file was deleted.

84 changes: 84 additions & 0 deletions generators/client/templates/angular/webpack/webpack.custom.js.ejs
Original file line number Diff line number Diff line change
@@ -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;
};

0 comments on commit b38d226

Please sign in to comment.