From 0c4f834c0ae24e18b4c93cbb9566396148802e57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Fri, 23 Feb 2018 13:02:56 +0100 Subject: [PATCH] MOBILE-2327 ionic: Use aliases on import paths --- package.json | 6 +- .../messages/providers/mainmenu-handler.ts | 15 ++-- src/app/app.module.ts | 88 +++++++++---------- tsconfig.json | 13 ++- webpack.config.js | 23 +++++ 5 files changed, 91 insertions(+), 54 deletions(-) create mode 100644 webpack.config.js diff --git a/package.json b/package.json index c1569e23d..5652abe4e 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,9 @@ "name": "Moodle Pty Ltd.", "email": "mobile@moodle.com" }, + "config": { + "ionic_webpack": "./webpack.config.js" + }, "repository": { "type": "git", "url": "https://github.com/moodlehq/moodlemobile2.git" @@ -77,7 +80,8 @@ "gulp-rename": "^1.2.2", "gulp-slash": "^1.1.3", "through": "^2.3.8", - "typescript": "2.4.2" + "typescript": "2.4.2", + "webpack-merge": "^4.1.2" }, "browser": { "electron": false diff --git a/src/addon/messages/providers/mainmenu-handler.ts b/src/addon/messages/providers/mainmenu-handler.ts index a5bbc435d..d279301c7 100644 --- a/src/addon/messages/providers/mainmenu-handler.ts +++ b/src/addon/messages/providers/mainmenu-handler.ts @@ -14,14 +14,13 @@ import { Injectable } from '@angular/core'; import { AddonMessagesProvider } from './messages'; -import { CoreMainMenuDelegate, CoreMainMenuHandler, CoreMainMenuHandlerToDisplay } from - '../../../core/mainmenu/providers/delegate'; -import { CoreCronHandler } from '../../../providers/cron'; -import { CoreSitesProvider } from '../../../providers/sites'; -import { CoreEventsProvider } from '../../../providers/events'; -import { CoreAppProvider } from '../../../providers/app'; -import { CoreTextUtilsProvider } from '../../../providers/utils/text'; -import { CoreLocalNotificationsProvider } from '../../../providers/local-notifications'; +import { CoreMainMenuDelegate, CoreMainMenuHandler, CoreMainMenuHandlerToDisplay } from '@core/mainmenu/providers/delegate'; +import { CoreCronHandler } from '@providers/cron'; +import { CoreSitesProvider } from '@providers/sites'; +import { CoreEventsProvider } from '@providers/events'; +import { CoreAppProvider } from '@providers/app'; +import { CoreTextUtilsProvider } from '@providers/utils/text'; +import { CoreLocalNotificationsProvider } from '@providers/local-notifications'; /** * Handler to inject an option into main menu. diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 6648d6c17..b54aeed8e 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -23,54 +23,54 @@ import { TranslateModule, TranslateLoader } from '@ngx-translate/core'; import { TranslateHttpLoader } from '@ngx-translate/http-loader'; import { MoodleMobileApp } from './app.component'; -import { CoreInterceptor } from '../classes/interceptor'; -import { CoreLoggerProvider } from '../providers/logger'; -import { CoreDbProvider } from '../providers/db'; -import { CoreAppProvider } from '../providers/app'; -import { CoreConfigProvider } from '../providers/config'; -import { CoreLangProvider } from '../providers/lang'; -import { CoreTextUtilsProvider } from '../providers/utils/text'; -import { CoreDomUtilsProvider } from '../providers/utils/dom'; -import { CoreTimeUtilsProvider } from '../providers/utils/time'; -import { CoreUrlUtilsProvider } from '../providers/utils/url'; -import { CoreUtilsProvider } from '../providers/utils/utils'; -import { CoreMimetypeUtilsProvider } from '../providers/utils/mimetype'; -import { CoreInitDelegate } from '../providers/init'; -import { CoreFileProvider } from '../providers/file'; -import { CoreWSProvider } from '../providers/ws'; -import { CoreEventsProvider } from '../providers/events'; -import { CoreSitesFactoryProvider } from '../providers/sites-factory'; -import { CoreSitesProvider } from '../providers/sites'; -import { CoreLocalNotificationsProvider } from '../providers/local-notifications'; -import { CoreGroupsProvider } from '../providers/groups'; -import { CoreCronDelegate } from '../providers/cron'; -import { CoreFileSessionProvider } from '../providers/file-session'; -import { CoreFilepoolProvider } from '../providers/filepool'; -import { CoreUpdateManagerProvider } from '../providers/update-manager'; -import { CorePluginFileDelegate } from '../providers/plugin-file-delegate'; -import { CoreSyncProvider } from '../providers/sync'; +import { CoreInterceptor } from '@classes/interceptor'; +import { CoreLoggerProvider } from '@providers/logger'; +import { CoreDbProvider } from '@providers/db'; +import { CoreAppProvider } from '@providers/app'; +import { CoreConfigProvider } from '@providers/config'; +import { CoreLangProvider } from '@providers/lang'; +import { CoreTextUtilsProvider } from '@providers/utils/text'; +import { CoreDomUtilsProvider } from '@providers/utils/dom'; +import { CoreTimeUtilsProvider } from '@providers/utils/time'; +import { CoreUrlUtilsProvider } from '@providers/utils/url'; +import { CoreUtilsProvider } from '@providers/utils/utils'; +import { CoreMimetypeUtilsProvider } from '@providers/utils/mimetype'; +import { CoreInitDelegate } from '@providers/init'; +import { CoreFileProvider } from '@providers/file'; +import { CoreWSProvider } from '@providers/ws'; +import { CoreEventsProvider } from '@providers/events'; +import { CoreSitesFactoryProvider } from '@providers/sites-factory'; +import { CoreSitesProvider } from '@providers/sites'; +import { CoreLocalNotificationsProvider } from '@providers/local-notifications'; +import { CoreGroupsProvider } from '@providers/groups'; +import { CoreCronDelegate } from '@providers/cron'; +import { CoreFileSessionProvider } from '@providers/file-session'; +import { CoreFilepoolProvider } from '@providers/filepool'; +import { CoreUpdateManagerProvider } from '@providers/update-manager'; +import { CorePluginFileDelegate } from '@providers/plugin-file-delegate'; +import { CoreSyncProvider } from '@providers/sync'; // Core modules. -import { CoreComponentsModule } from '../components/components.module'; -import { CoreEmulatorModule } from '../core/emulator/emulator.module'; -import { CoreLoginModule } from '../core/login/login.module'; -import { CoreMainMenuModule } from '../core/mainmenu/mainmenu.module'; -import { CoreCoursesModule } from '../core/courses/courses.module'; -import { CoreFileUploaderModule } from '../core/fileuploader/fileuploader.module'; -import { CoreSharedFilesModule } from '../core/sharedfiles/sharedfiles.module'; -import { CoreCourseModule } from '../core/course/course.module'; -import { CoreSiteHomeModule } from '../core/sitehome/sitehome.module'; -import { CoreContentLinksModule } from '../core/contentlinks/contentlinks.module'; -import { CoreUserModule } from '../core/user/user.module'; -import { CoreGradesModule } from '../core/grades/grades.module'; +import { CoreComponentsModule } from '@components/components.module'; +import { CoreEmulatorModule } from '@core/emulator/emulator.module'; +import { CoreLoginModule } from '@core/login/login.module'; +import { CoreMainMenuModule } from '@core/mainmenu/mainmenu.module'; +import { CoreCoursesModule } from '@core/courses/courses.module'; +import { CoreFileUploaderModule } from '@core/fileuploader/fileuploader.module'; +import { CoreSharedFilesModule } from '@core/sharedfiles/sharedfiles.module'; +import { CoreCourseModule } from '@core/course/course.module'; +import { CoreSiteHomeModule } from '@core/sitehome/sitehome.module'; +import { CoreContentLinksModule } from '@core/contentlinks/contentlinks.module'; +import { CoreUserModule } from '@core/user/user.module'; +import { CoreGradesModule } from '@core/grades/grades.module'; // Addon modules. -import { AddonCalendarModule } from '../addon/calendar/calendar.module'; -import { AddonUserProfileFieldModule } from '../addon/userprofilefield/userprofilefield.module'; -import { AddonFilesModule } from '../addon/files/files.module'; -import { AddonModBookModule } from '../addon/mod/book/book.module'; -import { AddonModLabelModule } from '../addon/mod/label/label.module'; -import { AddonMessagesModule } from '../addon/messages/messages.module'; +import { AddonCalendarModule } from '@addon/calendar/calendar.module'; +import { AddonUserProfileFieldModule } from '@addon/userprofilefield/userprofilefield.module'; +import { AddonFilesModule } from '@addon/files/files.module'; +import { AddonModBookModule } from '@addon/mod/book/book.module'; +import { AddonModLabelModule } from '@addon/mod/label/label.module'; +import { AddonMessagesModule } from '@addon/messages/messages.module'; // For translate loader. AoT requires an exported function for factories. export function createTranslateLoader(http: HttpClient): TranslateHttpLoader { diff --git a/tsconfig.json b/tsconfig.json index 2e450f9f1..911e2b387 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,7 +11,18 @@ "module": "es2015", "moduleResolution": "node", "sourceMap": true, - "target": "es5" + "target": "es5", + "baseUrl": "./src", + "paths": { + "@addon/*": ["addon/*"], + "@classes/*": ["classes/*"], + "@core/*": ["core/*"], + "@providers/*": ["providers/*"], + "@utils": ["providers/utils/*"], + "@components": ["components/*"], + "@directives": ["directives/directives.module"], + "@pipes": ["pipes/pipes.module"] + } }, "include": [ "src/**/*.ts" diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 000000000..113e1ad71 --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,23 @@ +const { resolve } = require('path'); +const webpackMerge = require('webpack-merge'); +const { dev, prod } = require('@ionic/app-scripts/config/webpack.config'); + +const customConfig = { + resolve: { + alias: { + '@addon': resolve('./src/addon'), + '@classes': resolve('./src/classes'), + '@core': resolve('./src/core'), + '@providers': resolve('./src/providers'), + '@utils': resolve('./src/providers/utils'), + '@components': resolve('./src/components'), + '@directives': resolve('./src/directives/directives.module'), + '@pipes': resolve('./src/pipes/pipes.module') + } + } +}; + +module.exports = { + dev: webpackMerge(dev, customConfig), + prod: webpackMerge(prod, customConfig), +} \ No newline at end of file