Skip to content

Commit 6d804cf

Browse files
Merge pull request #35 from strongbox/issue-1691
Issue-1691: Improve strongbox-web-ui build process and various cleanups.
2 parents db03d51 + 7e1fd64 commit 6d804cf

File tree

8 files changed

+207
-159
lines changed

8 files changed

+207
-159
lines changed

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ pipeline {
124124
}
125125

126126
sh "mvn deploy:deploy-file " +
127-
" -Dfile=./dist/packaging/strongbox-web-ui.zip " +
127+
" -Dfile=./dist/strongbox-web-ui.zip " +
128128
" -DrepositoryId=" + SERVER_ID +
129129
" -Durl=" + SERVER_URL +
130130
" -DartifactId=" + ARTIFACT_ID +

angular.json

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,27 @@
1717
"build": {
1818
"builder": "@angular-devkit/build-angular:browser",
1919
"options": {
20+
"baseHref": "/",
2021
"deployUrl": "/static/assets/",
21-
"outputPath": "dist/strongbox-web-ui",
22-
"index": "src/index.html",
22+
"outputPath": "dist/strongbox-web-ui/static/assets",
23+
"index": {
24+
"input": "src/index.html",
25+
"output": "../../index.html"
26+
},
2327
"main": "src/main.ts",
2428
"polyfills": "src/polyfills.ts",
2529
"tsConfig": "src/tsconfig.app.json",
2630
"assets": [
2731
{
2832
"glob": "**/*.*",
2933
"input": "src/assets",
30-
"output": "/"
34+
"output": "./"
3135
}
3236
],
3337
"styles": [
3438
"src/styles.scss"
3539
],
40+
"resourcesOutputPath": "./",
3641
"scripts": []
3742
},
3843
"configurations": {
@@ -75,8 +80,11 @@
7580
"serve": {
7681
"builder": "@angular-devkit/build-angular:dev-server",
7782
"options": {
78-
"deployUrl": "/",
79-
"browserTarget": "strongbox-web-ui:build"
83+
"browserTarget": "strongbox-web-ui:build",
84+
"proxyConfig": "./tools/proxy.conf.js",
85+
"servePath": "/static/assets",
86+
"baseHref": "/",
87+
"deployUrl": "/static/assets/"
8088
},
8189
"configurations": {
8290
"production": {

package.json

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,16 @@
44
"scripts": {
55
"ng": "ng",
66
"start": "ng serve --aot",
7-
"build": "npm run clean-dist && ng build",
8-
"build-prod": "npm run clean-dist && ng build --prod --aot --no-progress",
9-
"build-prod-stage": "npm run clean-dist && ng build --prod --aot --configuration=stage --no-progress",
10-
"build-prod-source-map": "npm run clean-dist && ng build --prod --aot --source-map && ./node_modules/.bin/source-map-explorer dist/strongbox-web-ui/main.*.js",
11-
"serve-packaged": "./node_modules/.bin/http-server dist/packaging/strongbox-web-ui -p 4206 -g -c-1 -o",
12-
"clean-dist": "./node_modules/.bin/rimraf dist/packaging dist/strongbox-web-ui",
7+
"build": "npm run clean-dist && ng build --prod --aot",
8+
"postbuild": "./node_modules/.bin/webpack --config ./tools/webpack.config.js",
9+
"build-source-map": "npm run clean-dist && npm run build -- --source-map && source-map-explorer dist/strongbox-web-ui/static/assets/main-es5.*.js && source-map-explorer dist/strongbox-web-ui/static/assets/main-es2015.*.js",
10+
"serve-packaged": "./node_modules/.bin/http-server dist/strongbox-web-ui -p 4206 -g -c-1 -o",
11+
"clean-dist": "./node_modules/.bin/rimraf dist",
1312
"clean-install": "./node_modules/.bin/rimraf node_modules && npm cache clear --force && npm install",
1413
"postinstall": "npm run webdriver-update && npm run patch-antlr4 && npm run antlr4",
15-
"ci-build": "npm run clean-dist && npm run build-prod && npm run package",
16-
"ci-build-stage": "npm run clean-dist && npm run build-prod-stage && npm run package",
14+
"ci-build": "npm run clean-dist && npm run build -- --no-progress",
1715
"ci-test": "ng test --browsers HeadlessChrome,HeadlessFirefox",
1816
"ci-e2e": "ng e2e --port 4201 --protractor-config ./e2e/protractor-ci.conf.js",
19-
"package": "./node_modules/.bin/rimraf dist/packaging/* && ./node_modules/.bin/webpack --env.configuration=prod",
2017
"test": "ng test --watch --browsers Chrome --source-map=false",
2118
"lint": "ng lint",
2219
"e2e": "ng e2e --port 4201",
@@ -56,14 +53,13 @@
5653
"ngx-toastr": "~10.0.4",
5754
"ngx-virtual-scroller": "^3.0.3",
5855
"open-sans-fontface": "^1.4.0",
59-
"replace-in-file": "^5.0.2",
6056
"rxjs": "~6.4.0",
6157
"tslib": "^1.9.0",
6258
"zone.js": "~0.9.1"
6359
},
6460
"devDependencies": {
65-
"@angular-devkit/build-angular": "0.801.0",
66-
"@angular/cli": "~8.0.2",
61+
"@angular-devkit/build-angular": "0.803.25",
62+
"@angular/cli": "~8.3.25",
6763
"@angular/compiler-cli": "8.1.0",
6864
"@angular/language-service": "8.1.0",
6965
"@ngxs/devtools-plugin": "^3.3.4",
@@ -93,7 +89,7 @@
9389
"karma-summary-reporter": "~1.6.0",
9490
"karma-verbose-reporter": "~0.0.6",
9591
"protractor": "~5.4.1",
96-
"replace": "^1.0.0",
92+
"replace-in-file": "^5.0.2",
9793
"rimraf": "^2.6.2",
9894
"rxjs-marbles": "^5.0.3",
9995
"source-map-explorer": "^1.6.0",

src/index.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
<html lang="en">
33
<head>
44
<title>Strongbox</title>
5-
6-
<base href="/">
7-
85
<meta charset="utf-8">
96
<meta name="viewport" content="width=device-width, initial-scale=1">
107
</head>

strongbox-settings.sh

Lines changed: 0 additions & 7 deletions
This file was deleted.

tools/proxy.conf.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const filter = function(pathname, req) {
2+
return req.method === 'GET' && pathname.match('^/(index\.html)?$')
3+
};
4+
5+
const LOCAL_IP = '127.0.0.1';
6+
7+
const PROXY_CONFIG = [
8+
{
9+
context: filter,
10+
target: `http://${LOCAL_IP}:4200/static/assets`,
11+
secure: false,
12+
logLevel: "debug"
13+
},
14+
{
15+
context: [
16+
"/api",
17+
"/storages"
18+
],
19+
target: `http://${LOCAL_IP}:48080`,
20+
secure: false,
21+
logLevel: "debug",
22+
changeOrigin: true
23+
}
24+
];
25+
26+
module.exports = PROXY_CONFIG;

tools/webpack.config.js

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
const path = require('path');
2+
const glob = require('glob');
3+
4+
const CompressionPlugin = require('compression-webpack-plugin');
5+
const FileManagerPlugin = require('filemanager-webpack-plugin');
6+
const ManifestPlugin = require('webpack-manifest-plugin');
7+
8+
const angularJson = require('../angular.json');
9+
const packageJson = require('../package.json');
10+
11+
12+
const appName = angularJson.defaultProject;
13+
const buildOptions = angularJson.projects['strongbox-web-ui'].architect.build.options;
14+
15+
const projectRootPath = (...appendPaths) => {
16+
return path.resolve(__dirname, '../', appendPaths ? appendPaths.join('/') : '');
17+
};
18+
19+
const appPath = projectRootPath('src', 'app');
20+
21+
const distPath = (...appendPaths) => {
22+
const rootPath = buildOptions.outputPath;
23+
const deployUrl = ('' + buildOptions.deployUrl).replace(/(^\/|\/+$)/mg, '');
24+
const count = (deployUrl.match(/\//g) || []).length;
25+
let traverse = '';
26+
27+
for (let i = 0; i <= count; i++) {
28+
traverse += '../';
29+
}
30+
31+
return path.resolve(rootPath, traverse, appendPaths ? appendPaths.join('/') : '');
32+
};
33+
34+
const assetsPath = (...appendPaths) => {
35+
return distPath('static/assets', appendPaths);
36+
};
37+
38+
console.log();
39+
console.log(`
40+
_____ _ _
41+
/ ____|| | | |
42+
| (___ | |_ _ __ ___ _ __ __ _ | |__ ___ __ __
43+
\\___ \\ | __|| '__|/ _ \\ | '_ \\ / _\` || '_ \\ / _ \\\\ \\/ /
44+
____) || |_ | | | (_) || | | || (_| || |_) || (_) |> <
45+
|_____/ \\__||_| \\___/ |_| |_| \\__, ||_.__/ \\___//_/\\_\\
46+
__/ |
47+
|___/
48+
`);
49+
console.log();
50+
console.log('Options:');
51+
console.table([
52+
{'key': 'rootPath', 'value': projectRootPath()},
53+
{'key': 'appPath', 'value': appPath},
54+
{'key': 'distPath', 'value': distPath()},
55+
{'key': 'outputPath', 'value': buildOptions.outputPath},
56+
{'key': 'assetsPath', 'value': assetsPath()},
57+
{'key': 'baseHref', 'value': buildOptions.baseHref},
58+
{'key': 'deployUrl', 'value': buildOptions.deployUrl},
59+
{'key': 'version', 'value': packageJson.version}
60+
], ['key', 'value']);
61+
console.log('\n');
62+
63+
module.exports = {
64+
mode: 'production',
65+
entry: [
66+
...glob.sync( distPath() + '/*.*'),
67+
...glob.sync(assetsPath() + '/*.*'),
68+
],
69+
output: {
70+
path: distPath(),
71+
filename: '[name]',
72+
},
73+
module: {
74+
rules: [
75+
{
76+
test: /.*/,
77+
exclude: [/\.html/],
78+
use: [{
79+
loader: 'file-loader',
80+
options: {
81+
name: '[name].[ext]',
82+
outputPath: '/' + path.relative(distPath(), assetsPath())
83+
}
84+
}]
85+
},
86+
{
87+
test: /\.html/,
88+
use: [{
89+
loader: 'file-loader',
90+
options: {
91+
name: '[name].[ext]',
92+
outputPath: '/' + path.relative(distPath(), distPath())
93+
}
94+
}]
95+
}
96+
]
97+
},
98+
plugins: [
99+
new CompressionPlugin({
100+
filename: '[path].gz[query]',
101+
algorithm: 'gzip',
102+
test: /\.(js|css|woff|woff2|ttf|svg|eot)$/,
103+
threshold: 10240,
104+
minRatio: 0.9,
105+
}),
106+
new CompressionPlugin({
107+
filename: '[path].br[query]',
108+
algorithm: 'brotliCompress',
109+
test: /\.(js|css|woff|woff2|ttf|svg|eot)$/,
110+
compressionOptions: { level: 11 },
111+
threshold: 10240,
112+
minRatio: 0.9,
113+
}),
114+
new ManifestPlugin({
115+
basePath: distPath(),
116+
fileName: 'assets-manifest.json',
117+
/**
118+
* https://github.com/danethurber/webpack-manifest-plugin/blob/1.x/README.md#hooks-options
119+
* {
120+
* path: string,
121+
* chunk: Chunk,
122+
* name: string|null,
123+
* isInitial: boolean,
124+
* isAsset: boolean,
125+
* isModuleAsset: boolean
126+
* }
127+
*/
128+
map: (data) => {
129+
return {
130+
path: data.path.replace('/index.html', '/'),
131+
name: path.basename(data.name),
132+
isInitial: data.isInitial,
133+
isChunk: data.chunk,
134+
isAsset: data.isAsset,
135+
isModuleAsset: data.isModuleAsset
136+
}
137+
},
138+
filter: (data) => {
139+
return data.name.match(/main\.main$/) === null;
140+
}
141+
}),
142+
new FileManagerPlugin({
143+
onEnd: {
144+
delete: [ distPath('main') ],
145+
archive: [{
146+
source: distPath(),
147+
destination: distPath('../') + '/' + appName + '.zip',
148+
format: 'zip',
149+
options: {
150+
zlib: {
151+
level: 9
152+
}
153+
}
154+
}]
155+
}
156+
})
157+
]
158+
};

0 commit comments

Comments
 (0)