From 50f44d8d9d67be87f733c4b8c348909c5376eaef Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Mon, 5 Oct 2020 17:24:36 +0200 Subject: [PATCH] MOBILE-3565 core: Add webpack config aliases --- angular.json | 9 ++++++--- config/webpack.config.js | 31 +++++++++++++++++++++++++++++++ package-lock.json | 31 ++++++++++++++++++++++++++++++- package.json | 3 ++- tsconfig.app.json | 14 +++++++++++++- tsconfig.json | 18 +++++++++++++++--- 6 files changed, 97 insertions(+), 9 deletions(-) create mode 100644 config/webpack.config.js diff --git a/angular.json b/angular.json index 784b4bfa7..e31c182b7 100644 --- a/angular.json +++ b/angular.json @@ -12,7 +12,7 @@ "schematics": {}, "architect": { "build": { - "builder": "@angular-devkit/build-angular:browser", + "builder": "@angular-builders/custom-webpack:browser", "options": { "outputPath": "www", "index": "src/index.html", @@ -39,7 +39,10 @@ "input": "src/global.scss" } ], - "scripts": [] + "scripts": [], + "customWebpackConfig": { + "path": "./config/webpack.config.js" + } }, "configurations": { "production": { @@ -72,7 +75,7 @@ } }, "serve": { - "builder": "@angular-devkit/build-angular:dev-server", + "builder": "@angular-builders/custom-webpack:dev-server", "options": { "browserTarget": "app:build" }, diff --git a/config/webpack.config.js b/config/webpack.config.js new file mode 100644 index 000000000..c3ddbe5ca --- /dev/null +++ b/config/webpack.config.js @@ -0,0 +1,31 @@ +// (C) Copyright 2015 Moodle Pty Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +const { webpack } = require('webpack'); +const { resolve } = require('path'); + +module.exports = (config, options, targetOptions) => { + config.resolve.alias['@'] = resolve('src'); + config.resolve.alias['@addon'] = resolve('src/app/addon'); + config.resolve.alias['@app'] = resolve('src/app'); + config.resolve.alias['@classes'] = resolve('src/app/classes'); + config.resolve.alias['@components'] = resolve('src/app/components'); + config.resolve.alias['@core'] = resolve('src/app/core'); + config.resolve.alias['@directives'] = resolve('src/app/directives'); + config.resolve.alias['@pipes'] = resolve('src/app/pipes'); + config.resolve.alias['@services'] = resolve('src/app/services'); + config.resolve.alias['@singletons'] = resolve('src/app/singletons'); + + return config; +}; diff --git a/package-lock.json b/package-lock.json index cbce4a296..71a7e0df5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,9 +1,38 @@ { "name": "moodlemobile", - "version": "0.0.1", + "version": "3.9.5", "lockfileVersion": 1, "requires": true, "dependencies": { + "@angular-builders/custom-webpack": { + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/@angular-builders/custom-webpack/-/custom-webpack-10.0.1.tgz", + "integrity": "sha512-YDy5zEKVwXdoXLjmbsY6kGaEbmunQxaPipxrwLUc9hIjRLU2WcrX9vopf1R9Pgj4POad73IPBNGu+ibqNRFIEQ==", + "dev": true, + "requires": { + "@angular-devkit/architect": ">=0.1000.0 < 0.1100.0", + "@angular-devkit/build-angular": ">=0.1000.0 < 0.1100.0", + "@angular-devkit/core": "^10.0.0", + "lodash": "^4.17.15", + "ts-node": "^9.0.0", + "webpack-merge": "^4.2.2" + }, + "dependencies": { + "ts-node": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-9.0.0.tgz", + "integrity": "sha512-/TqB4SnererCDR/vb4S/QvSZvzQMJN8daAslg7MeaiHvD8rDZsSfXmNeNumyZZzMned72Xoq/isQljYSt8Ynfg==", + "dev": true, + "requires": { + "arg": "^4.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "source-map-support": "^0.5.17", + "yn": "3.1.1" + } + } + } + }, "@angular-devkit/architect": { "version": "0.1000.8", "resolved": "https://registry.npmjs.org/@angular-devkit/architect/-/architect-0.1000.8.tgz", diff --git a/package.json b/package.json index b3afcdfe4..380cdd86d 100644 --- a/package.json +++ b/package.json @@ -41,15 +41,16 @@ "zone.js": "~0.10.3" }, "devDependencies": { + "@angular-builders/custom-webpack": "^10.0.1", "@angular-devkit/build-angular": "~0.1000.0", "@angular/cli": "~10.0.5", "@angular/compiler": "~10.0.0", "@angular/compiler-cli": "~10.0.0", "@angular/language-service": "~10.0.0", "@ionic/angular-toolkit": "^2.3.0", - "@types/node": "^12.11.1", "@types/jasmine": "~3.5.0", "@types/jasminewd2": "~2.0.3", + "@types/node": "^12.11.1", "codelyzer": "^6.0.0", "jasmine-core": "~3.5.0", "jasmine-spec-reporter": "~5.0.0", diff --git a/tsconfig.app.json b/tsconfig.app.json index 91b32f2fc..9c7f71d78 100644 --- a/tsconfig.app.json +++ b/tsconfig.app.json @@ -2,7 +2,19 @@ "extends": "./tsconfig.json", "compilerOptions": { "outDir": "./out-tsc/app", - "types": [] + "types": [], + "paths": { + "@/*": ["*"], + "@addon/*": ["app/addon/*"], + "@app/*": ["app/*"], + "@classes/*": ["app/classes/*"], + "@components/*": ["app/components/*"], + "@core/*": ["app/core/*"], + "@directives/*": ["app/directives/*"], + "@pipes/*": ["app/pipes/*"], + "@services/*": ["app/services/*"], + "@singletons/*": ["app/singletons/*"] + } }, "files": [ "src/main.ts", diff --git a/tsconfig.json b/tsconfig.json index e80e8cc89..5329205ee 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compileOnSave": false, "compilerOptions": { - "baseUrl": "./", + "baseUrl": "src", "outDir": "./dist/out-tsc", "sourceMap": true, "declaration": false, @@ -14,10 +14,22 @@ "lib": [ "es2018", "dom" - ] + ], + "paths": { + "@/*": ["*"], + "@addon/*": ["app/addon/*"], + "@app/*": ["app/*"], + "@classes/*": ["app/classes/*"], + "@components/*": ["app/components/*"], + "@core/*": ["app/core/*"], + "@directives/*": ["app/directives/*"], + "@pipes/*": ["app/pipes/*"], + "@services/*": ["app/services/*"], + "@singletons/*": ["app/singletons/*"] + } }, "angularCompilerOptions": { "fullTemplateTypeCheck": true, "strictInjectionParameters": true } -} \ No newline at end of file +}