问题描述
在Webpack创建JS包之前,是否可以在Webpack的管道中“拦截并保存”来自TypeScript的JS文件?我正在努力寻找可以转储已编译JS文件的选项。
$ tsc
成功创建了transpiled/index.js
,但$ webpack
未创建,似乎忽略了选项tsconfig.json:compilerOptions:outDir
。
项目结构
├── dist
│ └── bundle.js
├── src
│ └── index.tsx
├── transpiled
│ └── index.js
├── tsconfig.json
└── webpack.config.js
index.tsx
import React from 'react'
import ReactDOM from 'react-dom'
const Header = ({ name }: { name: string }) => <h1>{name}</h1>
ReactDOM.render(<Header name="Foo Bar" />,null)
tsconfig.json
{
"compilerOptions": {
"outDir": "./transpiled","target": "esnext","module": "esnext","jsx": "react","strict": true,"esModuleInterop": true,"skipLibCheck": true,"forceConsistentCasingInFileNames": true
}
}
webpack.config.js
module.exports = {
entry: './src/index.tsx',mode: 'development',module: {
rules: [{
test: /\.tsx?$/,loader: 'ts-loader',exclude: /node_modules/,}],},output: { filename: 'bundle.js' },};
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)