-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use Babel 7 & Webpack3 (via blocks)
- Loading branch information
Showing
5 changed files
with
77 additions
and
46 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"presets": [ | ||
["@babel/preset-env", { | ||
"targets": { | ||
"node": "6.10" | ||
} | ||
}] | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ typings/ | |
coverage/ | ||
test/typescript/axios.js* | ||
sauce_connect.log | ||
dist |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
module.exports = require('./lib/axios'); | ||
module.exports = require('./dist/commonjs/axios'); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,56 @@ | ||
var webpack = require('webpack'); | ||
var config = {}; | ||
const { | ||
addPlugins, | ||
createConfig, | ||
defineConstants, | ||
entryPoint, | ||
env, | ||
setOutput, | ||
sourceMaps, | ||
resolve | ||
} = require('@webpack-blocks/webpack') | ||
const babel = require('@webpack-blocks/babel') | ||
const uglify = require('@webpack-blocks/uglify') | ||
|
||
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' | ||
}, | ||
node: { | ||
process: false | ||
}, | ||
devtool: 'source-map' | ||
}; | ||
const path = require('path') | ||
|
||
config.plugins = [ | ||
new webpack.DefinePlugin({ | ||
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV) | ||
module.exports = createConfig([ | ||
entryPoint('./lib/axios.js'), | ||
setOutput({ | ||
path: path.resolve(__dirname, 'dist/browser'), | ||
filename: 'bundle.js', | ||
library: 'axios', | ||
libraryTarget: 'var' | ||
}), | ||
defineConstants({ | ||
'process.env.NODE_ENV': process.env.NODE_ENV || 'development', | ||
'process.env.TARGET_ENV': 'browser' | ||
}), | ||
babel({ | ||
presets: [ | ||
['@babel/env', { targets: 'last 2 versions, ie 11', modules: false }] | ||
] | ||
}), | ||
env('production', [ | ||
setOutput({ | ||
filename: 'bundle.min.js' | ||
}), | ||
uglify() | ||
]), | ||
env('development', [ | ||
uglify({ | ||
uglifyOptions: { | ||
output: { | ||
beautify: false, | ||
preserve_line: true | ||
}, | ||
mangle: false | ||
} | ||
}) | ||
]; | ||
|
||
if (uglify) { | ||
config.plugins.push( | ||
new webpack.optimize.UglifyJsPlugin({ | ||
compressor: { | ||
warnings: false | ||
} | ||
}) | ||
); | ||
} | ||
|
||
return config; | ||
} | ||
|
||
['axios', 'axios.min'].forEach(function (key) { | ||
config[key] = generateConfig(key); | ||
}); | ||
|
||
module.exports = config; | ||
]), | ||
// TODO: tree shaking instead of explicit replace | ||
resolve({ | ||
alias: { | ||
'./adapters/http': path.resolve(__dirname, 'lib/adapters/xhr') | ||
} | ||
}) | ||
]) |