feat: better babel configs

This commit is contained in:
cha0s 2019-05-05 17:03:15 -05:00
parent 206643e45c
commit 2b87df771b
8 changed files with 53 additions and 19 deletions

14
babel.client.config.js Normal file
View File

@ -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;
}

9
babel.common.config.js Normal file
View File

@ -0,0 +1,9 @@
module.exports = function (api) {
api.cache(true);
const presets = [];
const plugins = [];
return {
presets,
plugins
};
}

View File

@ -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
};
}

15
babel.server.config.js Normal file
View File

@ -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;
}

View File

@ -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",

View File

@ -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'),
);

View File

@ -15,6 +15,7 @@ const config = {
],
use: {
loader: 'babel-loader',
options: {},
},
},
{

View File

@ -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'),
);