diff --git a/babel.client.config.js b/babel.client.config.js new file mode 100644 index 0000000..3de8f70 --- /dev/null +++ b/babel.client.config.js @@ -0,0 +1,14 @@ +const common = require('./babel.common.config'); + +module.exports = function(api) { + const config = common(api); + // Presets. + config.presets.push('@babel/preset-react'); + config.presets.push('@babel/preset-env'); + // Plugins. + config.plugins.push('@babel/plugin-proposal-object-rest-spread'); + if (process.argv.find((arg) => '--hot' === arg)) { + config.plugins.push('react-hot-loader/babel'); + } + return config; +} diff --git a/babel.common.config.js b/babel.common.config.js new file mode 100644 index 0000000..5da11a5 --- /dev/null +++ b/babel.common.config.js @@ -0,0 +1,9 @@ +module.exports = function (api) { + api.cache(true); + const presets = []; + const plugins = []; + return { + presets, + plugins + }; +} diff --git a/babel.config.js b/babel.config.js deleted file mode 100644 index e8f732b..0000000 --- a/babel.config.js +++ /dev/null @@ -1,19 +0,0 @@ -module.exports = function (api) { - api.cache(true); - - const presets = [ - '@babel/preset-react', - '@babel/preset-env', - ]; - const plugins = [ - '@babel/plugin-proposal-object-rest-spread', - ]; - if (process.argv.find((arg) => '--hot' === arg)) { - plugins.push('react-hot-loader/babel'); - } - - return { - presets, - plugins - }; -} diff --git a/babel.server.config.js b/babel.server.config.js new file mode 100644 index 0000000..3495972 --- /dev/null +++ b/babel.server.config.js @@ -0,0 +1,15 @@ +const common = require('./babel.common.config'); + +module.exports = function(api) { + const config = common(api); + // Presets. + config.presets.push([ + '@babel/preset-env', + { + targets: { + node: 'current', + }, + }, + ]); + return config; +} diff --git a/package.json b/package.json index 3866000..14254fd 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,12 @@ "version": "1.0.0", "author": "cha0s", "license": "MIT", + "browserslist": [ + "last 1 version", + "> 1%", + "maintained node versions", + "not dead" + ], "devDependencies": { "@babel/core": "7.3.4", "@babel/plugin-proposal-object-rest-spread": "7.3.4", diff --git a/webpack.client.config.js b/webpack.client.config.js index f2ec55a..2adbc38 100644 --- a/webpack.client.config.js +++ b/webpack.client.config.js @@ -36,6 +36,10 @@ config.devServer = { watchContentBase: true, }; config.devtool = 'eval-source-map'; +// Babel config file. +config.module.rules[0].use.options.configFile = path.resolve( + __dirname, 'babel.client.config.js' +); config.module.rules[1].use.options.paths.push( path.resolve(__dirname, 'client'), ); diff --git a/webpack.common.config.js b/webpack.common.config.js index b1ad7e0..dba6c61 100644 --- a/webpack.common.config.js +++ b/webpack.common.config.js @@ -15,6 +15,7 @@ const config = { ], use: { loader: 'babel-loader', + options: {}, }, }, { diff --git a/webpack.server.config.js b/webpack.server.config.js index 9484511..f6c51ce 100644 --- a/webpack.server.config.js +++ b/webpack.server.config.js @@ -24,6 +24,10 @@ config.externals = [ whitelist: /(?:@avocado|webpack\/hot\/signal)/, }), ]; +// Babel config file. +config.module.rules[0].use.options.configFile = path.resolve( + __dirname, 'babel.server.config.js' +); config.module.rules[1].use.options.paths.push( path.resolve(__dirname, 'server'), );