gpt4 book ai didi

Typescript -> Babel sourcemaps 使用 webpack

转载 作者:搜寻专家 更新时间:2023-10-30 20:38:25 25 4
gpt4 key购买 nike

从 ts-loader 问题中复制粘贴,因为它可能更适合这里:

如何将 typescript sourcemaps 传递给 babel,以便最终 sourcemap 指向原始文件而不是编译后的 typescript 文件?

这是我的开发设置示例:

tsconfig.json:

{
"compilerOptions": {
"target": "es6",
"jsx": "react",
"noImplicitAny": false,
"sourceMap": true
},
"exclude": ["node_modules", "gulpfile.js", "webpack.config.js", "server.js"]
}

webpack.dev.js:

var path = require("path");
var webpack = require("webpack");

module.exports = {
devtool: "eval",
entry: [
"webpack-hot-middleware/client",
"./src/app/index",
],
output: {
path: path.join(__dirname, "build"),
filename: "app.js",
publicPath: "/static/"
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new webpack.ProvidePlugin({
'window.fetch': 'exports?self.fetch!whatwg-fetch'
})
],
resolve: {
extensions: ['', '.ts', '.tsx', '.js']
},
module: {
noParse: [
/\/sinon.js/
],
preLoaders: [{
test: /\.ts(x?)$/,
loader: "tslint",
exclude: /node_modules/
}],
loaders: [
{
test: /\.tsx?$/,
loader: 'babel-loader!ts-loader',
exclude: /node_modules/,
include: path.join(__dirname, 'src')
}
]
}
};

最佳答案

您可以为 webpack 使用 source-map-loader。这是我的 webpack.config.js:

module.exports = {
entry: "./app.ts",
output: {
filename: "./bundle.js",
},

devtool: "source-map",

resolve: {
extensions: ["", ".webpack.js", ".web.js", ".ts", ".js"]
},

module: {
loaders: [
// ts -> ES6 -> babel -> ES5
{ test: /\.tsx?$/, loaders: ["babel-loader", "ts-loader"] }
],

preLoaders: [
{ test: /\.js$/, loader: "source-map-loader" }
]
}
};

tsconfig.js:

{
"compilerOptions": {
"target": "es6",
"sourceMap": true
},
"exclude": [
"node_modules"
]
}

source in chrome devtools

关于Typescript -> Babel sourcemaps 使用 webpack,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35870940/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com