Skip to content

Commit 11b9489

Browse files
committed
working webpack 5
1 parent 628357f commit 11b9489

File tree

9 files changed

+910
-3826
lines changed

9 files changed

+910
-3826
lines changed

gulpfile.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ function watchWebpack(done) {
8787
watch: true,
8888
cache: true,
8989
bail: false,
90+
infrastructureLogging: {
91+
level: 'verbose'
92+
},
93+
stats: {
94+
logging: 'verbose'
95+
},
9096
devtool: 'eval-source-map',
9197
plugins: [
9298
...config.plugins || [],
@@ -98,13 +104,13 @@ function watchWebpack(done) {
98104
open: !(process.env.DOCKER_MODE)
99105
})
100106
]
101-
},
107+
},
102108
(err, stats) => {
103109
if (err) {
104110
console.error(err);
105111
}
106112
if (stats.hasErrors() && stats.compilation.errors) {
107-
stats.compilation.errors.forEach(function(e){console.error(e,'\n');});
113+
stats.compilation.errors.forEach((e) => {console.error(e,'\n');});
108114
}
109115
console.log(stats.toString());
110116
return done(err);

karma.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = function(config) {
77
basePath: '',
88
// frameworks to use
99
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
10-
frameworks: ['mocha'],
10+
frameworks: ['webpack', 'mocha'],
1111
// list of files / patterns to load in the browser
1212
files: [
1313
'src/client/tests/index.ts',

package-lock.json

+808-3,741
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+27-28
Original file line numberDiff line numberDiff line change
@@ -67,56 +67,55 @@
6767
"@types/request": "2.48.5",
6868
"angular-router-loader": "0.8.5",
6969
"angular2-template-loader": "0.6.2",
70-
"autoprefixer": "10.0.1",
70+
"autoprefixer": "10.2.4",
7171
"awesome-typescript-loader": "5.2.1",
72-
"browser-sync": "2.26.12",
73-
"browser-sync-webpack-plugin": "2.2.2",
74-
"chai": "4.2.0",
75-
"circular-dependency-plugin": "5.2.0",
72+
"browser-sync": "2.26.14",
73+
"browser-sync-webpack-plugin": "2.3.0",
74+
"chai": "4.3.0",
75+
"circular-dependency-plugin": "5.2.2",
7676
"concurrently": "5.3.0",
77-
"copy-webpack-plugin": "6.1.1",
78-
"core-js": "3.6.5",
79-
"css-loader": "3.5.3",
77+
"copy-webpack-plugin": "7.0.0",
78+
"core-js": "3.8.3",
79+
"css-loader": "5.0.1",
8080
"cssnano": "4.1.10",
8181
"fibers": "5.0.0",
82-
"file-loader": "6.1.0",
82+
"file-loader": "6.2.0",
8383
"gulp": "4.0.2",
8484
"gulp-typescript": "5.0.1",
8585
"html-loader": "1.3.2",
8686
"html-webpack-link-type-plugin": "1.1.0",
87-
"html-webpack-plugin": "3.2.0",
87+
"html-webpack-plugin": "5.0.0",
8888
"html-webpack-skip-assets-plugin": "1.0.0",
8989
"istanbul-instrumenter-loader": "3.0.1",
90-
"karma": "5.2.3",
90+
"karma": "6.1.0",
9191
"karma-chrome-launcher": "3.1.0",
9292
"karma-coverage-istanbul-reporter": "3.0.3",
9393
"karma-mocha": "2.0.1",
9494
"karma-mocha-reporter": "2.2.5",
9595
"karma-sourcemap-loader": "0.3.8",
96-
"karma-webpack": "4.0.2",
97-
"mini-css-extract-plugin": "0.11.3",
98-
"mocha": "8.1.3",
96+
"karma-webpack": "5.0.0",
97+
"mini-css-extract-plugin": "1.3.5",
98+
"mocha": "8.2.1",
9999
"normalize-scss": "7.0.1",
100100
"nyc": "15.1.0",
101-
"postcss": "8.1.1",
102-
"postcss-loader": "4.0.2",
101+
"postcss": "8.2.4",
102+
"postcss-loader": "5.0.0",
103103
"reflect-metadata": "0.1.13",
104-
"resolve-url-loader": "3.1.2",
105104
"rimraf": "3.0.2",
106-
"sass": "1.26.11",
107-
"sass-loader": "10.0.4",
108-
"source-map-loader": "1.1.1",
109-
"supertest": "5.0.0",
110-
"terser-webpack-plugin": "4.2.2",
105+
"sass": "1.32.6",
106+
"sass-loader": "11.0.0",
107+
"source-map-loader": "2.0.0",
108+
"supertest": "6.1.3",
109+
"terser-webpack-plugin": "5.1.1",
111110
"to-string-loader": "1.1.6",
112111
"ts-mockito": "2.6.1",
113-
"ts-node": "9.0.0",
114-
"tslib": "2.0.1",
115-
"typescript": "4.0.3",
112+
"ts-node": "9.1.1",
113+
"tslib": "2.1.0",
114+
"typescript": "4.1.3",
116115
"url-loader": "4.1.1",
117-
"webpack": "4.44.2",
118-
"webpack-bundle-analyzer": "3.9.0",
119-
"webpack-cli": "3.3.12",
116+
"webpack": "5.21.1",
117+
"webpack-bundle-analyzer": "4.4.0",
118+
"webpack-cli": "4.5.0",
120119
"webpack-node-externals": "2.5.2",
121120
"webpack-nomodule-plugin": "1.1.0",
122121
"workbox-cacheable-response": "6.1.0",

src/client/modules/app.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import {NgModule} from '@angular/core';
22
import {RouterModule} from '@angular/router';
33
import {BrowserModule, BrowserTransferStateModule} from '@angular/platform-browser';
44
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
5+
import { HTTP_INTERCEPTORS } from '@angular/common/http';
56
import {SharedModule} from '@modules/shared';
6-
import {AppComponent} from '@components/app/component';
77
import {IsLoggedInGuard, NotLoggedInGuard} from '@guards'
8+
import { HttpConnectionInterceptor } from '@services/connection/interceptor';
9+
import {AppComponent} from '@components/app/component';
810

911
@NgModule({
1012
bootstrap: [
@@ -17,14 +19,21 @@ import {IsLoggedInGuard, NotLoggedInGuard} from '@guards'
1719
BrowserTransferStateModule,
1820
RouterModule.forRoot(
1921
[
20-
{path: 'login', canLoad: [NotLoggedInGuard], canActivateChild: [NotLoggedInGuard], loadChildren: './routes/+login#LoginLazyModule'},
21-
{path: 'signup', canLoad: [NotLoggedInGuard], canActivateChild: [NotLoggedInGuard], loadChildren: './routes/+signup#SignupLazyModule'},
22-
{path: '', canLoad: [IsLoggedInGuard], canActivateChild: [IsLoggedInGuard], loadChildren: './routes/+demo#DemoLazyModule'},
22+
{path: 'login', canLoad: [NotLoggedInGuard], canActivateChild: [NotLoggedInGuard], loadChildren: () => import('./routes/+login').then(m => m.LoginLazyModule)},
23+
{path: 'signup', canLoad: [NotLoggedInGuard], canActivateChild: [NotLoggedInGuard], loadChildren: () => import('./routes/+signup').then(m => m.SignupLazyModule)},
24+
{path: '', canLoad: [IsLoggedInGuard], canActivateChild: [IsLoggedInGuard], loadChildren: () => import('./routes/+demo').then(m => m.DemoLazyModule)},
2325
]
2426
)
2527
],
2628
declarations: [
2729
AppComponent,
30+
],
31+
providers: [
32+
{
33+
provide: HTTP_INTERCEPTORS,
34+
useClass: HttpConnectionInterceptor,
35+
multi: true,
36+
}
2837
]
2938
})
3039
export class AppModule {}

src/server/routes/auth.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import {Router} from 'express';
2-
import {createHash} from 'crypto';
3-
import * as uuid from 'uuid/v4';
4-
import {Observable} from 'rxjs';
5-
import {flatMap, switchMap} from 'rxjs/operators';
2+
import {switchMap} from 'rxjs/operators';
63
import {Config} from '../models/config';
74
import {User} from '../models/user';
85

src/server/services/auth.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export class AuthService {
136136
if (isValid) {
137137
return of(user);
138138
} else {
139-
throwError({Status: 400, Message: 'email or password is incorrect'});
139+
return throwError({Status: 400, Message: 'email or password is incorrect'});
140140
}
141141
})
142142
);

webpack.config.js

+38-39
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@ const autoprefixer = require('autoprefixer');
1010
const cssnano = require('cssnano');
1111
const CopyWebpackPlugin = require('copy-webpack-plugin');
1212
const CircularDependencyPlugin = require('circular-dependency-plugin');
13-
const TerserPlugin = require('terser-webpack-plugin');
13+
const TerserPlugin = require('terser-webpack-plugin');
1414
const AotPlugin = require('@ngtools/webpack').AngularCompilerPlugin;
1515
const NormalModuleReplacementPlugin = webpack.NormalModuleReplacementPlugin;
16+
const DefinePlugin = webpack.DefinePlugin;
1617
const bundles = [/^polyfills/i, /^commons(~)?/i, /^vendors~/i, /^app/i, /^styles/i, /.*/];
1718

1819
const config = {
1920
mode: 'none',
2021
entry: {
21-
app: path.join(__dirname,'./src/client/main.ts'),
22-
polyfills: path.join(__dirname,'./src/client/polyfills.ts'),
22+
app: path.join(__dirname, './src/client/main.ts'),
23+
polyfills: path.join(__dirname, './src/client/polyfills.ts'),
2324
styles: path.join(__dirname, './src/client/scss/styles.scss')
2425
},
2526
output: {
@@ -29,7 +30,7 @@ const config = {
2930
},
3031
resolve: {
3132
extensions: ['.ts', '.js', '.json', '.scss', '.css'],
32-
mainFields: [ 'module' ],
33+
mainFields: ['module', 'browser', 'main'],
3334
alias: {
3435
'/assets': path.join(__dirname, './src/client/assets')
3536
}
@@ -50,29 +51,22 @@ const config = {
5051
{
5152
loader: 'css-loader',
5253
options: {
53-
// url: false
54-
}
55-
},
56-
{
57-
loader:'resolve-url-loader',
58-
options: {
59-
root: path.join(__dirname, './src/client'),
60-
debug: true
54+
esModule: false
6155
}
6256
},
6357
{
6458
loader: 'postcss-loader',
6559
options: {
6660
postcssOptions: {
6761
plugins: [
68-
autoprefixer({remove: false, flexbox: true}),
69-
cssnano({zindex: false})
62+
autoprefixer({ remove: false, flexbox: true }),
63+
cssnano({ zindex: false })
7064
]
7165
}
7266
}
7367
},
7468
{
75-
loader:'sass-loader',
69+
loader: 'sass-loader',
7670
options: {
7771
sassOptions: {
7872
includePaths: [path.join(__dirname, './src/client/scss')]
@@ -102,20 +96,14 @@ const config = {
10296
options: {
10397
postcssOptions: {
10498
plugins: [
105-
autoprefixer({remove: false, flexbox: true}),
106-
cssnano({zindex: false})
99+
autoprefixer({ remove: false, flexbox: true }),
100+
cssnano({ zindex: false })
107101
],
108102
}
109103
}
110104
},
111105
{
112-
loader:'resolve-url-loader',
113-
options: {
114-
root: path.join(__dirname, './src/client')
115-
}
116-
},
117-
{
118-
loader:'sass-loader',
106+
loader: 'sass-loader',
119107
options: {
120108
sassOptions: {
121109
includePaths: [path.join(__dirname, './src/client/scss')]
@@ -136,19 +124,19 @@ const config = {
136124
},
137125
{
138126
test: /font(s)?\.svg/,
139-
exclude: /\.svg\.js/,
127+
exclude: /\.svg\.js/,
140128
use: [
141129
{
142130
loader: 'url-loader',
143131
options: {
144-
limit: 10*1024,
132+
limit: 10 * 1024,
145133
name: 'fonts/[name].svg'
146134
}
147135
}
148136
]
149137
},
150-
// images
151-
{
138+
// images
139+
{
152140
test: /assets\/.*?\.((jpg)|(png)|(gif)|(bmp)|(webp)|(svg))/,
153141
loader: 'url-loader',
154142
// exclude: [path.join(__dirname, './src/client/assets')],
@@ -160,19 +148,26 @@ const config = {
160148
// templateUrl
161149
{
162150
test: /\.html$/,
163-
use: 'html-loader'
151+
use: [
152+
{
153+
loader: 'html-loader',
154+
options: {
155+
minimize: true
156+
}
157+
}
158+
]
164159
}
165160
]
166161
},
167162
optimization: {
168163
// runtimeChunk: 'single',
169164
flagIncludedChunks: true,
170-
occurrenceOrder: true,
171165
sideEffects: true,
172166
usedExports: true,
173167
concatenateModules: true,
174168
providedExports: true,
175169
splitChunks: {
170+
chunks: 'async',
176171
hidePathInfo: true,
177172
minSize: 30000,
178173
maxSize: 977000, // try and stay below recomended size
@@ -184,22 +179,21 @@ const config = {
184179
vendors: {
185180
test: /[\\/]node_modules[\\/]/,
186181
priority: -10,
182+
reuseExistingChunk: true,
187183
},
188184
default: {
189185
name: 'commons',
190186
minChunks: 2,
191187
reuseExistingChunk: true,
192188
priority: -20
193189
}
194-
}
190+
}
195191
},
196192
minimize: true,
197193
},
198194
plugins: [
199195
new TerserPlugin({
200196
parallel: true,
201-
sourceMap: process.env.BUILD_MODE === 'development',
202-
cache: true,
203197
terserOptions: {
204198
compress: true,
205199
output: {
@@ -214,19 +208,19 @@ const config = {
214208
hash: false,
215209
showErrors: false,
216210
excludeAssets: [/styles\..*js/i],
217-
chunksSortMode: (a,b) => {
211+
chunksSortMode: (a, b) => {
218212
return bundles.findIndex(pattern => pattern.test(a)) - bundles.findIndex(pattern => pattern.test(b));
219213
},
220214
}),
221215
new HtmlWebpackSkipAssetsPlugin(),
222216
new HtmlWebpackLinkTypePlugin(),
223-
new NoModulePlugin({filePatterns: ['polyfills.**.js']}),
217+
new NoModulePlugin({ filePatterns: ['polyfills.**.js'] }),
224218
new AotPlugin({
225219
tsConfigPath: path.join(__dirname, './src/client/tsconfig.app.json'),
226220
mainPath: path.join(__dirname, './src/client/main.ts'),
227221
typeChecking: false,
228222
}),
229-
new MiniCssExtractPlugin ({
223+
new MiniCssExtractPlugin({
230224
filename: '[name].[contenthash].min.css'
231225
}),
232226
new CircularDependencyPlugin({
@@ -253,13 +247,18 @@ const config = {
253247
}
254248
]
255249
}),
256-
new NormalModuleReplacementPlugin(/environments\/environment/, function(resource) {
257-
resource.request = resource.request.replace(/environment$/, (process.env.BUILD_MODE === 'development' ? 'devEnvironment':'prodEnvironment'));
250+
new NormalModuleReplacementPlugin(/environments\/environment/, function (resource) {
251+
resource.request = resource.request.replace(/environment$/, (process.env.BUILD_MODE === 'development' ? 'devEnvironment' : 'prodEnvironment'));
252+
}),
253+
new DefinePlugin({
254+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
255+
'process.env.NODE_DEBUG': JSON.stringify(process.env.NODE_DEBUG),
256+
'process.type': JSON.stringify(process.type),
257+
'process.version': JSON.stringify(process.version),
258258
}),
259259
new workbox.InjectManifest({
260260
swSrc: path.join(__dirname, './src/client/sw.js'),
261261
swDest: 'sw.js',
262-
// importsDirectory: 'wb-assets',
263262

264263
exclude: [
265264
/styles\..*\.min\.js/i, // empty bundle file from extractText

0 commit comments

Comments
 (0)