Skip to content

Commit

Permalink
refactor: use Babel 7 & Webpack3 (via blocks)
Browse files Browse the repository at this point in the history
  • Loading branch information
zcei committed Feb 5, 2018
1 parent 604e8dd commit 0b57e41
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 46 deletions.
9 changes: 9 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"presets": [
["@babel/preset-env", {
"targets": {
"node": "6.10"
}
}]
]
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ typings/
coverage/
test/typescript/axios.js*
sauce_connect.log
dist
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./lib/axios');
module.exports = require('./dist/commonjs/axios');
17 changes: 13 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
"scripts": {
"test": "grunt test && bundlesize",
"start": "node ./sandbox/server.js",
"build": "NODE_ENV=production grunt build",
"clean": "rimraf dist",
"cjs": "babel lib --out-dir dist/commonjs",
"browser": "NODE_ENV=production webpack",
"browser:dev": "webpack",
"build": "npm run clean && npm run cjs && npm run browser",
"preversion": "npm test",
"version": "npm run build && grunt version && git add -A dist && git add CHANGELOG.md bower.json package.json",
"postversion": "git push && git push --tags",
Expand All @@ -31,6 +35,12 @@
},
"homepage": "https://github.com/axios/axios",
"devDependencies": {
"@babel/core": "^7.0.0-beta.39",
"@babel/preset-env": "^7.0.0-beta.39",
"@webpack-blocks/babel": "^1.0.0-rc",
"@webpack-blocks/uglify": "^1.1.0",
"@webpack-blocks/webpack": "^1.0.0-rc",
"babel-cli": "^7.0.0-beta.3",
"bundlesize": "^0.5.7",
"coveralls": "^2.11.9",
"es6-promise": "^4.0.5",
Expand Down Expand Up @@ -60,11 +70,10 @@
"karma-webpack": "^1.7.0",
"load-grunt-tasks": "^3.5.2",
"minimist": "^1.2.0",
"rimraf": "^2.6.2",
"sinon": "^1.17.4",
"webpack": "^1.13.1",
"webpack-dev-server": "^1.14.1",
"url-search-params": "^0.6.1",
"typescript": "^2.0.3"
"webpack": "^3.10.0"
},
"browser": {
"./lib/adapters/http.js": "./lib/adapters/xhr.js"
Expand Down
94 changes: 53 additions & 41 deletions webpack.config.js
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')
}
})
])

0 comments on commit 0b57e41

Please sign in to comment.