replace duplicating babel config with common excludes getter

This commit is contained in:
Vyrtsev Mikhail
2019-07-29 13:47:35 -05:00
committed by Umputun
parent 1d01a21480
commit 734eb0ebf3
+17 -27
View File
@@ -19,6 +19,20 @@ const NODE_ID = 'remark42';
console.log(`NODE_ENV = ${env}`);
console.log(`REMARK_ENV = ${remarkUrl}`);
/**
* Generates excludes for babel-loader
*
* Exclude is a module that has >=es6 code and resides in node_modules.
* By defaut babel-loader ignores everything from node_modules,
* so we have to exclude from ignore these modules
*/
function getExcluded() {
const modules = ['markdown-toolbar-element'];
const exclude = new RegExp(`node_modules\\/(?!(${modules.map(m => m.replace(/\//g, '\\/')).join('|')})\\/).*`);
return { exclude };
}
const commonStyleLoaders = [
'css-loader',
{
@@ -62,37 +76,13 @@ module.exports = () => ({
rules: [
{
test: /\.js(x?)$/,
oneOf: [
{
include: /node_modules\/@github\/markdown-toolbar-element/,
use: {
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env',
{
targets: {
browsers: ['> 1%', 'android >= 4.4.4', 'ios >= 9', 'IE >= 11'],
},
useBuiltIns: 'usage',
corejs: 3,
},
],
],
},
},
},
{
exclude: /node_modules/,
use: 'babel-loader',
},
],
use: 'babel-loader',
...getExcluded(),
},
{
test: /\.ts(x?)$/,
exclude: /node_modules/,
use: ['babel-loader', 'ts-loader'],
...getExcluded(),
},
{
test: /\.s?css$/,