如何解决在Webpack管道中保存编译的TypeScript文件
在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 举报,一经查实,本站将立刻删除。