UNPKG

@jenssimon/webpack-config-sfcc

Version:

A shareable Webpack configuration for SFCC projects

45 lines 1.62 kB
/** * Rules to transpile JavaScript and TypeScript files using swc (https://swc.rs/). * * You can change setting by providing a `.swcrc` file in the root of your project * (see https://swc.rs/docs/configuring-swc). * This also uses the browserslist configuration (see https://github.com/browserslist/browserslist#config-file). */ const swc = (cartridge, { swcTarget: target, transformNodeModules, sourceMap, }) => { // Some packages from `node_modules` need to be transpiled. You can specify a list of packages using the // `transformNodeModules` option. const exclude = (name) => (name.includes('node_modules') ? !(transformNodeModules ?? []).some((module) => new RegExp(String.raw `node_modules[/\\]?${module}`).test(name)) : false); // to reduce DRY code const swcConfig = (test, syntax) => ({ test, exclude, use: { loader: 'swc-loader', options: { jsc: { parser: { syntax, decorators: true, }, transform: { useDefineForClassFields: false, }, target, externalHelpers: true, }, ...sourceMap ? { sourceMap: true, inlineSourcesContent: true, } : {}, }, }, }); return [ swcConfig(/\.m?js$/), swcConfig(/\.ts$/, 'typescript'), ]; }; export default swc; //# sourceMappingURL=swc.js.map