From 45d60952b70d65bf2fb4943722e4209d9ecbfc77 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Wed, 16 Sep 2020 16:54:56 +0200 Subject: [PATCH] [WIP] fix webpack dependencies with global variables Using: - expose-loader - exports-loader - import-loader - https://medium.com/@drgenejones/using-webpack-with-legacy-angular-spas-exposing-global-variables-to-child-modules-599e32f373c9 --- app/frontend/src/javascript/app.js | 2 +- config/webpack/environment.js | 2 +- config/webpack/loaders/expose_app.js | 2 +- config/webpack/loaders/imports.js | 2 +- package.json | 1 + yarn.lock | 9 +++++++++ 6 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/frontend/src/javascript/app.js b/app/frontend/src/javascript/app.js index 1500a8d38..bc8dbcf1e 100644 --- a/app/frontend/src/javascript/app.js +++ b/app/frontend/src/javascript/app.js @@ -6,7 +6,7 @@ */ // eslint-disable-next-line no-use-before-define -const Application = Application || {}; +var Application = Application || {}; Application.Constants = angular.module('application.constants', []); Application.Services = angular.module('application.services', []); diff --git a/config/webpack/environment.js b/config/webpack/environment.js index ee7b64eb4..753fee1b0 100644 --- a/config/webpack/environment.js +++ b/config/webpack/environment.js @@ -25,7 +25,7 @@ environment.loaders.append('sass', sass); environment.loaders.append('fonts', fonts); environment.loaders.append('expose-app', exposeApp); -environment.loaders.append('imports', imports); +// environment.loaders.append('imports', imports); environment.splitChunks(); diff --git a/config/webpack/loaders/expose_app.js b/config/webpack/loaders/expose_app.js index 876f48275..c731d1c5b 100644 --- a/config/webpack/loaders/expose_app.js +++ b/config/webpack/loaders/expose_app.js @@ -2,6 +2,6 @@ module.exports = { test: require.resolve('../../../app/frontend/src/javascript/app.js'), loader: 'expose-loader', options: { - exposes: 'app' + exposes: 'Application Application' } }; diff --git a/config/webpack/loaders/imports.js b/config/webpack/loaders/imports.js index 8ae644bf3..c77c3b31d 100644 --- a/config/webpack/loaders/imports.js +++ b/config/webpack/loaders/imports.js @@ -5,7 +5,7 @@ module.exports = { loader: 'imports-loader', options: { imports: [ - 'default app Application' + 'default Application Application' ] } } diff --git a/package.json b/package.json index bc82156f6..29f37c962 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "eslint-plugin-node": "~11.0.0", "eslint-plugin-promise": "~4.2.1", "eslint-plugin-standard": "~4.0.1", + "exports-loader": "^1.1.0", "expose-loader": "^1.0.0", "file-loader": "^6.1.0", "html-loader": "^1.3.0", diff --git a/yarn.lock b/yarn.lock index afead4bd0..532b6ad91 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3488,6 +3488,15 @@ expand-tilde@^2.0.0, expand-tilde@^2.0.2: dependencies: homedir-polyfill "^1.0.1" +exports-loader@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/exports-loader/-/exports-loader-1.1.0.tgz#26a16706e4cf533145de24c1419baf33b624fb5c" + integrity sha512-zGB2SujiAyO0Rwn4GQ17/HlT8cwmT8abcBeZpr2R3sItJ5sI5Y9BzNzus3H9tH1iWLAoJLi9N3TP54D2+j859Q== + dependencies: + loader-utils "^2.0.0" + schema-utils "^2.7.0" + source-map "^0.6.1" + expose-loader@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/expose-loader/-/expose-loader-1.0.0.tgz#1676dde8fce6662584e17f8531e24d2afe8dae11"