【发布时间】:2019-05-05 05:39:31
【问题描述】:
我已经为 React 项目配置了带有 Webpack 的 Typescript。问题是,我无法使用 .JS 源从我的浏览器进行调试。仅生成bundle.js。
tsconfig.json
{
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"module": "commonjs",
"target": "es6",
"jsx": "react"
},
"include": [
"./src/**/**/*"
]
}
webpack.config.js(更新)
const path = require('path')
module.exports = {
mode: 'development',
entry: "./src/index.tsx",
output: {
filename: "bundle.js",
path: path.resolve(__dirname, './dist')
},
resolve: {
// Add '.ts' and '.tsx' as resolvable extensions.
extensions: [".ts", ".tsx", ".js", ".json"]
},
devtool: 'source-map',
module: {
rules: [
// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
{ test: /\.tsx?$/, loader: "ts-loader" },
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{ enforce: "pre", test: /\.js?$/, loader: "source-map-loader" }
]
},
// When importing a module whose path matches one of the following, just
// assume a corresponding global variable exists and use that instead.
// This is important because it allows us to avoid bundling all of our
// dependencies, which allows browsers to cache those libraries between builds.
externals: {
"react": "React",
"react-dom": "ReactDOM",
"react-router-dom": "ReactRouterDOM",
"reactstrap": "Reactstrap",
"flux" : "Flux"
}
};
现在这是我在dist 目录中的输出
.
├── bundle.js
└── bundle.js.map
我的目的是为我的所有 .tsx 文件获取 .js 源,这样我就可以通过使用控制台的源选项卡在浏览器中进行调试。
【问题讨论】:
标签: javascript reactjs typescript webpack