Created
December 31, 2017 00:24
-
-
Save jayserdny/86308c5d9a801716f541db56a757445b to your computer and use it in GitHub Desktop.
Please use this file for your webpack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* The webpack config exports an object that has a valid webpack configuration | |
* For each environment name. By default, there are two Ionic environments: | |
* "dev" and "prod". As such, the webpack.config.js exports a dictionary object | |
* with "keys" for "dev" and "prod", where the value is a valid webpack configuration | |
* For details on configuring webpack, see their documentation here | |
* https://webpack.js.org/configuration/ | |
*/ | |
var path = require('path'); | |
var webpack = require('webpack'); | |
var ionicWebpackFactory = require(process.env.IONIC_WEBPACK_FACTORY); | |
var ModuleConcatPlugin = require('webpack/lib/optimize/ModuleConcatenationPlugin'); | |
var PurifyPlugin = require('@angular-devkit/build-optimizer').PurifyPlugin; | |
var optimizedProdLoaders = [ | |
{ | |
test: /\.json$/, | |
loader: 'json-loader' | |
}, | |
{ | |
test: /\.js$/, | |
loader: [ | |
{ | |
loader: process.env.IONIC_CACHE_LOADER | |
}, | |
{ | |
loader: '@angular-devkit/build-optimizer/webpack-loader', | |
options: { | |
sourceMap: true | |
} | |
}, | |
] | |
}, | |
{ | |
test: /\.ts$/, | |
loader: [ | |
{ | |
loader: process.env.IONIC_CACHE_LOADER | |
}, | |
{ | |
loader: '@angular-devkit/build-optimizer/webpack-loader', | |
options: { | |
sourceMap: true | |
} | |
}, | |
{ | |
loader: process.env.IONIC_WEBPACK_LOADER | |
} | |
] | |
} | |
]; | |
function getProdLoaders() { | |
if (process.env.IONIC_OPTIMIZE_JS === 'true') { | |
return optimizedProdLoaders; | |
} | |
return devConfig.module.loaders; | |
} | |
var devConfig = { | |
entry: process.env.IONIC_APP_ENTRY_POINT, | |
output: { | |
path: '{{BUILD}}', | |
publicPath: 'build/', | |
filename: '[name].js', | |
devtoolModuleFilenameTemplate: ionicWebpackFactory.getSourceMapperFunction(), | |
}, | |
devtool: process.env.IONIC_SOURCE_MAP_TYPE, | |
resolve: { | |
extensions: ['.ts', '.js', '.json'], | |
modules: [path.resolve('node_modules')], | |
alias: { | |
'api': path.resolve(__dirname, 'src/api/server') | |
} | |
}, | |
externals: [ | |
resolveExternals | |
], | |
module: { | |
loaders: [ | |
{ | |
test: /\.json$/, | |
loader: 'json-loader' | |
}, | |
{ | |
test: /\.ts$/, | |
loader: process.env.IONIC_WEBPACK_LOADER | |
} | |
] | |
}, | |
plugins: [ | |
ionicWebpackFactory.getIonicEnvironmentPlugin(), | |
ionicWebpackFactory.getCommonChunksPlugin(), | |
new webpack.ProvidePlugin({ | |
__extends: 'typescript-extends' | |
}) | |
], | |
// Some libraries import Node modules but don't use them in the browser. | |
// Tell Webpack to provide empty mocks for them so importing them works. | |
node: { | |
fs: 'empty', | |
net: 'empty', | |
tls: 'empty', | |
__dirname: true | |
} | |
}; | |
var prodConfig = { | |
entry: process.env.IONIC_APP_ENTRY_POINT, | |
output: { | |
path: '{{BUILD}}', | |
publicPath: 'build/', | |
filename: '[name].js', | |
devtoolModuleFilenameTemplate: ionicWebpackFactory.getSourceMapperFunction(), | |
}, | |
devtool: process.env.IONIC_SOURCE_MAP_TYPE, | |
resolve: { | |
extensions: ['.ts', '.js', '.json'], | |
modules: [path.resolve('node_modules')], | |
alias: { | |
'api': path.resolve(__dirname, 'src/api/server') | |
} | |
}, | |
externals: [ | |
resolveExternals | |
], | |
module: { | |
loaders: getProdLoaders() | |
}, | |
plugins: [ | |
ionicWebpackFactory.getIonicEnvironmentPlugin(), | |
ionicWebpackFactory.getCommonChunksPlugin(), | |
new ModuleConcatPlugin(), | |
new PurifyPlugin(), | |
new webpack.ProvidePlugin({ | |
__extends: 'typescript-extends' | |
}) | |
], | |
// Some libraries import Node modules but don't use them in the browser. | |
// Tell Webpack to provide empty mocks for them so importing them works. | |
node: { | |
fs: 'empty', | |
net: 'empty', | |
tls: 'empty', | |
__dirname: true | |
} | |
}; | |
function resolveExternals(context, request, callback) { | |
return resolveMeteor(request, callback) || | |
callback(); | |
} | |
function resolveMeteor(request, callback) { | |
var match = request.match(/^meteor\/(.+)$/); | |
var pack = match && match[1]; | |
if (pack) { | |
callback(null, 'Package["' + pack + '"]'); | |
return true; | |
} | |
} | |
module.exports = { | |
dev: devConfig, | |
prod: prodConfig | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment