I recently started a project using Babel 7 with Typescript. Combining these two technologies was a bit of a challenge, but I finally got it working. However, there's still one issue that I'm facing.
During the compilation of my project, all .ts files from ./src/
are converted to .js files in ./dist/
. Dotfiles are correctly ignored, as expected. But I noticed that any files without the .ts extension in ./src/
are also being ignored.
I've tried several different commands to resolve this:
// package.json
"scripts": {
// build1 only compiles the .js files
"build1": "babel src --out-dir dist",
// build2 only compiles the .ts files
"build2": "babel src --out-dir dist --extensions \".ts\"",
// build3 only compiles the .ts files
"build3": "babel src --out-dir dist --extensions \".ts, .js\"",
// build4 only compiles the .js files
"build4": "babel src --out-dir dist --extensions \".js, .ts\""
},
Below is my babel config file
// babel.config.js
module.exports = {
presets: [
"@babel/env",
"@babel/typescript",
],
plugins: [
"transform-dynamic-import",
"@babel/proposal-class-properties",
"@babel/proposal-object-rest-spread"
],
};
Any suggestions?
Thank you!
Update: I discovered that removing the space in the --extensions argument resolves the issue, but it has introduced a new problem. Now, when running the command
"babel src --out-dir dist --extensions \".ts,.js,.json\""
, .json files are also getting converted to .js. My goal is for Babel to transform .ts to .js, compile the .js files, and simply copy any other file as is.