2019-03-16 15:44:29 -07:00
|
|
|
const path = require('path');
|
2021-03-02 14:34:37 +02:00
|
|
|
|
2022-09-30 06:13:47 -06:00
|
|
|
const coreVersion = require('./package.json').version;
|
2018-07-25 19:17:34 -04:00
|
|
|
const isProduction = process.env.NODE_ENV === 'production';
|
|
|
|
const isTest = process.env.NODE_ENV === 'test';
|
2019-03-22 08:24:46 -07:00
|
|
|
const isESM = process.env.NODE_ENV === 'esm';
|
2018-07-25 19:17:34 -04:00
|
|
|
|
2022-09-28 20:04:00 -06:00
|
|
|
console.info('Build Package:', path.basename(process.cwd()));
|
2019-04-04 11:16:06 -07:00
|
|
|
|
2019-09-30 15:24:15 -04:00
|
|
|
const defaultPlugins = [
|
|
|
|
'lodash',
|
|
|
|
[
|
|
|
|
'babel-plugin-transform-builtin-extend',
|
|
|
|
{
|
|
|
|
globals: ['Error'],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
'transform-export-extensions',
|
|
|
|
'@babel/plugin-proposal-class-properties',
|
|
|
|
'@babel/plugin-proposal-object-rest-spread',
|
|
|
|
'@babel/plugin-proposal-export-default-from',
|
2019-12-16 12:17:37 -05:00
|
|
|
'@babel/plugin-proposal-nullish-coalescing-operator',
|
|
|
|
'@babel/plugin-proposal-optional-chaining',
|
|
|
|
'@babel/plugin-syntax-dynamic-import',
|
|
|
|
'babel-plugin-inline-json-import',
|
2019-09-30 15:24:15 -04:00
|
|
|
];
|
|
|
|
|
2021-03-02 14:34:37 +02:00
|
|
|
const svgo = {
|
2022-09-28 20:04:00 -06:00
|
|
|
plugins: [
|
2021-03-02 14:34:37 +02:00
|
|
|
{
|
2022-09-28 20:04:00 -06:00
|
|
|
name: 'preset-default',
|
|
|
|
params: {
|
|
|
|
overrides: {
|
|
|
|
removeViewBox: false,
|
|
|
|
},
|
|
|
|
},
|
2021-03-02 14:34:37 +02:00
|
|
|
},
|
2022-09-28 20:04:00 -06:00
|
|
|
],
|
2021-03-02 14:34:37 +02:00
|
|
|
};
|
|
|
|
|
2021-02-08 20:01:21 +02:00
|
|
|
function presets() {
|
2019-12-16 12:17:37 -05:00
|
|
|
return [
|
|
|
|
'@babel/preset-react',
|
2021-04-14 14:33:40 +04:00
|
|
|
'@babel/preset-env',
|
2019-12-16 12:17:37 -05:00
|
|
|
[
|
|
|
|
'@emotion/babel-preset-css-prop',
|
|
|
|
{
|
2022-09-28 20:04:00 -06:00
|
|
|
autoLabel: 'always',
|
2019-12-16 12:17:37 -05:00
|
|
|
},
|
|
|
|
],
|
2019-12-18 18:16:02 +02:00
|
|
|
'@babel/typescript',
|
2019-12-16 12:17:37 -05:00
|
|
|
];
|
2021-02-08 20:01:21 +02:00
|
|
|
}
|
2018-07-25 19:17:34 -04:00
|
|
|
|
2021-02-08 20:01:21 +02:00
|
|
|
function plugins() {
|
2019-03-22 08:24:46 -07:00
|
|
|
if (isESM) {
|
|
|
|
return [
|
|
|
|
...defaultPlugins,
|
|
|
|
[
|
|
|
|
'transform-define',
|
|
|
|
{
|
2022-09-30 06:13:47 -06:00
|
|
|
SIMPLE_CMS_CORE_VERSION: `${coreVersion}`,
|
2019-03-22 08:24:46 -07:00
|
|
|
},
|
|
|
|
],
|
|
|
|
[
|
2019-09-30 11:52:26 -04:00
|
|
|
'inline-react-svg',
|
2019-03-22 08:24:46 -07:00
|
|
|
{
|
2021-03-02 14:34:37 +02:00
|
|
|
svgo,
|
2019-03-22 08:24:46 -07:00
|
|
|
},
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2018-07-25 19:17:34 -04:00
|
|
|
if (isTest) {
|
|
|
|
return [
|
|
|
|
...defaultPlugins,
|
2018-08-07 14:46:54 -06:00
|
|
|
[
|
2019-09-30 11:52:26 -04:00
|
|
|
'inline-react-svg',
|
2018-08-07 14:46:54 -06:00
|
|
|
{
|
2021-03-02 14:34:37 +02:00
|
|
|
svgo,
|
2018-07-25 19:17:34 -04:00
|
|
|
},
|
2018-08-07 14:46:54 -06:00
|
|
|
],
|
2018-07-25 19:17:34 -04:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2019-03-25 10:57:17 -07:00
|
|
|
if (!isProduction) {
|
2019-12-16 12:17:37 -05:00
|
|
|
return [...defaultPlugins, 'react-hot-loader/babel'];
|
2019-03-25 10:57:17 -07:00
|
|
|
}
|
|
|
|
|
2019-12-16 12:17:37 -05:00
|
|
|
return defaultPlugins;
|
2021-02-08 20:01:21 +02:00
|
|
|
}
|
2018-07-25 19:17:34 -04:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
presets: presets(),
|
|
|
|
plugins: plugins(),
|
2018-07-17 19:13:52 -04:00
|
|
|
};
|