Closed Josh-Cena closed 2 years ago
Babel's output contains a
if (
obj === null ||
(typeof obj !== "object" && typeof obj !== "function")
) {
return { default: obj };
}
check, which is lacking in SWC's output. This may be a problem in the core?
Re-filed in upstream. https://github.com/swc-project/swc/issues/4284
```js module.exports = { name: "SWC", mode: "production", entry: "./test.js", output: { filename: "swc-out.js", }, module: { rules: [ { test: /\.[jt]sx?$/i, use: [ { loader: require.resolve("swc-loader"), options: { jsc: { parser: { syntax: "ecmascript", }, target: "es2017", }, module: { type: "commonjs", }, }, }, ], }, ], }, }; ```webpack.config.js
test.js
data.json
Run:
Output:
As reference, here's Babel's equivalent config:
```js module.exports = { name: "Babel", mode: "production", entry: "./test.js", output: { filename: "babel-out.js", }, module: { rules: [ { test: /\.[jt]sx?$/i, use: [ { loader: require.resolve("babel-loader"), options: { presets: [ [ require.resolve("@babel/preset-env"), { targets: { node: "current", }, }, ], ], plugins: [require.resolve("babel-plugin-dynamic-import-node")], }, }, ], }, ], }, }; ```webpack.config.js
Output:
Env: