From 1cd690da191b4e95cc0a29c899b674db2e9dcbb8 Mon Sep 17 00:00:00 2001 From: Dotan Simha Date: Thu, 3 Nov 2016 17:39:11 +0200 Subject: [PATCH] Step 1.3: Updated webpack file --- webpack.config.js | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index a7495b78c..47a56f4a0 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -11,9 +11,17 @@ module.exports = { }, devtool: process.env.IONIC_GENERATE_SOURCE_MAP ? process.env.IONIC_SOURCE_MAP_TYPE : '', + externals: [ + 'cordova', + resolveExternals + ], + resolve: { extensions: ['.ts', '.js', '.json'], - modules: [path.resolve('node_modules')] + modules: [path.resolve('node_modules')], + alias: { + 'api': path.resolve(__dirname, 'api') + } }, module: { @@ -31,7 +39,10 @@ module.exports = { }, plugins: [ - ionicWebpackFactory.getIonicEnvironmentPlugin() + ionicWebpackFactory.getIonicEnvironmentPlugin(), + new webpack.ProvidePlugin({ + __extends: 'typescript-extends' + }) ], // Some libraries import Node modules but don't use them in the browser. @@ -39,6 +50,35 @@ module.exports = { node: { fs: 'empty', net: 'empty', - tls: 'empty' + tls: 'empty', + __dirname: true } }; + +function resolveExternals(context, request, callback) { + return meteorPackage(request, callback) || + cordovaPlugin(request, callback) || + callback(); +} + +function meteorPackage(request, callback) { + var match = request.match(/^meteor\/(.+)$/); + var pack = match && match[1]; + + if (pack) { + callback(null, 'window.Package && Package["' + pack + '"]'); + return true; + } +} + +function cordovaPlugin(request, callback) { + var match = request.match(/^cordova\/(.+)$/); + var plugin = match && match[1]; + + if (plugin) { + plugin = camelCase(plugin); + plugin = upperFirst(plugin); + callback(null, 'window.cordova && cordova.plugins && cordova.plugins.' + plugin); + return true; + } +}