Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update transpiling target #27195

Merged
merged 12 commits into from
May 9, 2024
33 changes: 33 additions & 0 deletions apps/demos/utils/bundle/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
const path = require('path');
const fs = require('fs-extra');
const Builder = require('systemjs-builder');
const babel = require('@babel/core');
const url = require('url');


// https://stackoverflow.com/questions/42412965/how-to-load-named-exports-with-systemjs/47108328
const prepareModulesToNamedImport = () => {
Expand Down Expand Up @@ -58,6 +61,7 @@ const getDefaultBuilderConfig = (framework, additionPaths, map) => ({
},
'devextreme/*': {
build: true,
transpile: true,
},
'devexpress-gantt': {
build: true,
Expand All @@ -72,6 +76,7 @@ const getDefaultBuilderConfig = (framework, additionPaths, map) => ({
},
paths: {
'devextreme/*': '../../node_modules/devextreme/cjs/*',
"devextreme/bundles/dx.custom.config.js": "../../node_modules/devextreme/bundles/dx.custom.config.js",
'devexpress-gantt': '../../node_modules/devexpress-gantt/dist/dx-gantt.min.js',
'devexpress-diagram': '../../node_modules/devexpress-diagram/dist/dx-diagram.min.js',
[`devextreme-${framework}/*`]: `../../node_modules/devextreme-${framework}/${['react', 'vue'].includes(framework) ? 'cjs/*' : '*'}`,
Expand Down Expand Up @@ -199,6 +204,34 @@ const prepareConfigs = (framework)=> {
bundleOpts: {
minify,
uglify: { mangle: true },
async fetch(load, fetch) {
if(load?.metadata?.transpile) {
// access to path-specific meta if required: load?.metadata?.babelOptions
const babelOptions = {
plugins: [
'@babel/plugin-transform-nullish-coalescing-operator',
'@babel/plugin-transform-object-rest-spread',
'@babel/plugin-transform-optional-catch-binding',
'@babel/plugin-transform-optional-chaining',
]
};

const result = new Promise((resolve) => {
// systemjs-builder uses babel 6, so we use babel 7 here for transpiling ES2020
babel.transformFile(url.fileURLToPath(load.name), babelOptions, (err, result) => {
if(err) {
fetch(load).then(r => resolve(r));
console.log('Unexpected transipling error (babel 7): ' + err);
} else {
resolve(result.code);
}
});
})
return result;
} else {
return fetch(load);
}
},
},
};
};
Expand Down
Loading
Loading