Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Babel 7 & Webpack3 (via blocks) #1334

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ email:
on_failure: change
on_success: never
before_script:
- npm run build
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- sleep 3 # give xvfb some time to start
Expand Down
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');
4 changes: 2 additions & 2 deletions lib/adapters/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ var httpFollow = require('follow-redirects').http;
var httpsFollow = require('follow-redirects').https;
var url = require('url');
var zlib = require('zlib');
var pkg = require('./../../package.json');
var createError = require('../core/createError');
var enhanceError = require('../core/enhanceError');
var pkginfo = require('pkginfo')(module);

/*eslint consistent-return:0*/
module.exports = function httpAdapter(config) {
Expand All @@ -24,7 +24,7 @@ module.exports = function httpAdapter(config) {
// Only set header if it hasn't been set in config
// See https://github.com/axios/axios/issues/69
if (!headers['User-Agent'] && !headers['user-agent']) {
headers['User-Agent'] = 'axios/' + pkg.version;
headers['User-Agent'] = 'axios/' + pkginfo.version;
}

if (data && !utils.isStream(data)) {
Expand Down
21 changes: 16 additions & 5 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,19 +70,20 @@
"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",
"webpack-dev-server": "^1.16.5"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was just wrongly sorted in the package.json beforehand. The dev dependency can be removed in the Karma branch, as until then the karma config has a dependency on the Webpack dev server

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes to make the tests run in this PR, will get removed later on

},
"browser": {
"./lib/adapters/http.js": "./lib/adapters/xhr.js"
},
"typings": "./index.d.ts",
"dependencies": {
"follow-redirects": "^1.2.5",
"is-buffer": "^1.1.5"
"is-buffer": "^1.1.5",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this used here, or was it there before ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just the comma, as pkginfo was added 😂

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the utils for now, later on we might get rid of it when moving to lodash

"pkginfo": "^0.4.1"
},
"bundlesize": [
{
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')
}
})
])