As title. It's a bit embarrassing that while I know how to do the followings, I still don't know how to achieve what the title suggested:
- I know how to setup
.eslintrc.jsonto work withtsconfig.json. (This is actually very tricky if you want to set all these things up: TypeScript, react, react-jsx,"parserOptions"that requires some changes intsconfig.json, etc) - I know how to setup
babel.config.jsto work withwebpack.config.js. (The only thing I know is that Babel can read TypeScript, so I only need to usebabel-loader)
How to the result .js of the process "TypeScript --> JavaScript --> Old-Version-JavaScript"? These are parts of the webpack.config.js I think relevant:
export default {
mode: 'development',
entry: {
main: path.resolve(curDir, 'src', 'index.tsx'),
},
output: {
path: path.resolve(curDir, 'docs'),
filename: '[name].bundle.[contenthash].js',
clean: true,
},
devtool: 'source-map', // should I delete this?
module: {
rules: [
{
test: /\.css/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(ts|js)x?/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: { cacheCompression: false },
},
},
],
},
}
and babel.config.js: (and Yes I'm using the syntax of the ES6 module, or ESM if you preferred)
export default {
presets: [
'@babel/preset-env', // I don't know what this one is doing?
'@babel/preset-react',
'@babel/preset-typescript',
],
plugins: [
'@babel/plugin-proposal-class-properties',
],
}
This is tsconfig.json:
{
"compilerOptions": {
"incremental": true,
"target": "es6",
"jsx": "preserve",
"module": "es6",
"moduleResolution": "node",
"baseUrl": "src",
"paths": {
"@/*": ["*"]
},
"resolveJsonModule": true,
"allowJs": true,
"noEmit": true,
"isolatedModules": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": false,
"skipLibCheck": true
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"./*.config.*"
],
"exclude": [
"**/node_modules"
]
}
In short I want to the the result similar to run:
npx tsc --watch
and then follows by
npx babel out.js
Thanks in advance.