Skip to content

Commit

Permalink
Converting to UMD
Browse files Browse the repository at this point in the history
  • Loading branch information
mzabriskie committed Aug 11, 2015
1 parent e49237c commit 2abe8eb
Showing 1 changed file with 34 additions and 53 deletions.
87 changes: 34 additions & 53 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,41 @@
var webpack = require('webpack');

var EXTERNAL_PROMISE = '{Promise: Promise}';
var config = {};
var base = {
entry: './index.js',
output: {
path: 'dist/',
filename: 'axios.js',
sourceMapFilename: 'axios.map',
library: 'axios'
},
externals: [
{
'./adapters/http': 'var undefined'
}
],
devtool: 'source-map'
};

['amd', 'global', 'amd-standalone', 'global-standalone'].forEach(function (key) {
config[key] = JSON.parse(JSON.stringify(base));
config[key + '-min'] = JSON.parse(JSON.stringify(base));

config[key + '-min'].plugins = [
new webpack.optimize.UglifyJsPlugin()
];
function generateConfig(name) {
var uglify = name.indexOf('min') > -1;
var config = {
entry: './index.js',
output: {
path: 'dist/',
filename: name + '.js',
sourceMapFilename: name + '.map',
library: 'axios',
libraryTarget: 'umd'
},
externals: [
{
'./adapters/http': 'var undefined'
}
],
devtool: 'source-map'
};

if (uglify) {
config.plugins = [
new webpack.optimize.UglifyJsPlugin({
compressor: {
warnings: false
}
})
];
}

return config;
}

['axios', 'axios.min'].forEach(function (key) {
config[key] = generateConfig(key);
});

config['amd'].output.filename = 'axios.amd.js';
config['amd'].output.sourceMapFilename = 'axios.amd.map';
config['amd'].output.libraryTarget = 'amd';

config['amd-standalone'].output.filename = 'axios.amd.standalone.js';
config['amd-standalone'].output.sourceMapFilename = 'axios.amd.standalone.map';
config['amd-standalone'].output.libraryTarget = 'amd';
config['amd-standalone'].externals[0]['es6-promise'] = EXTERNAL_PROMISE;

config['amd-min'].output.filename = 'axios.amd.min.js';
config['amd-min'].output.sourceMapFilename = 'axios.amd.min.map';
config['amd-min'].output.libraryTarget = 'amd';

config['amd-standalone-min'].output.filename = 'axios.amd.standalone.min.js';
config['amd-standalone-min'].output.sourceMapFilename = 'axios.amd.standalone.min.map';
config['amd-standalone-min'].output.libraryTarget = 'amd';
config['amd-standalone-min'].externals[0]['es6-promise'] = EXTERNAL_PROMISE;

config['global-standalone'].output.filename = 'axios.standalone.js';
config['global-standalone'].output.sourceMapFilename = 'axios.standalone.map';
config['global-standalone'].externals[0]['es6-promise'] = EXTERNAL_PROMISE;

config['global-min'].output.filename = 'axios.min.js';
config['global-min'].output.sourceMapFilename = 'axios.min.map';

config['global-standalone-min'].output.filename = 'axios.standalone.min.js';
config['global-standalone-min'].output.sourceMapFilename = 'axios.standalone.min.map';
config['global-standalone-min'].externals[0]['es6-promise'] = EXTERNAL_PROMISE;

module.exports = config;

0 comments on commit 2abe8eb

Please sign in to comment.