feat: better babel configs
This commit is contained in:
parent
206643e45c
commit
2b87df771b
14
babel.client.config.js
Normal file
14
babel.client.config.js
Normal 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
9
babel.common.config.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
module.exports = function (api) {
|
||||
api.cache(true);
|
||||
const presets = [];
|
||||
const plugins = [];
|
||||
return {
|
||||
presets,
|
||||
plugins
|
||||
};
|
||||
}
|
|
@ -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
15
babel.server.config.js
Normal 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;
|
||||
}
|
|
@ -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",
|
||||
|
|
|
@ -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'),
|
||||
);
|
||||
|
|
|
@ -15,6 +15,7 @@ const config = {
|
|||
],
|
||||
use: {
|
||||
loader: 'babel-loader',
|
||||
options: {},
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
|
@ -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'),
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue
Block a user