Where does source-map-loader fit into TypeScript compilation with Webpack?
我正在将TypeScript添加到当前全JavaScript Web应用程序的构建过程中,该应用程序的构建过程围绕Webpack进行构造。我一直在关注TypeScript \\从JavaScript进行迁移,并且对建议的Webpack配置有疑问?1,为方便起见,下面复制了以下内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | module.exports = { entry:"./src/index.ts", output: { filename:"./dist/bundle.js", }, // Enable sourcemaps for debugging webpack's output. devtool:"source-map", resolve: { // Add '.ts' and '.tsx' as resolvable extensions. extensions: ["",".webpack.js",".web.js",".ts",".tsx",".js"] }, module: { loaders: [ // All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'. { test: /\\.tsx?$/, loader:"awesome-typescript-loader" } ], preLoaders: [ // All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'. { test: /\\.js$/, loader:"source-map-loader" } ] }, // Other options... }; |
You can use
awesome-typescript-loader , a TypeScript loader, combined withsource-map-loader for easier debugging.
另一篇文章仅添加了一些额外的信息:
Both of these dependencies will let TypeScript and Webpack play well together.
awesome-typescript-loader helps Webpack compile your TypeScript code using the TypeScripta€?s standard configuration file namedtsconfig.json .source-map-loader uses any sourcemap outputs from TypeScript to inform webpack when generating its own sourcemaps. This will allow you to debug your final output file as if you were debugging your original TypeScript source code.
最后,
source-map-loader extracts existing source maps from all JavaScript entries. This includes both inline source maps as well as those linked via URL. All source map data is passed to webpack for processing as per a chosen source map style specified by the devtool option inwebpack.config.js .
好的。因此,
此外,我的印象是Webpack在配置中不处理中间文件,
1:请注意,此Webpack配置使用过时的语法,在
它与TypeScript编译本身没有任何关系,并且您不需要它来获取源映射以用于自己的源。但是,您可能由于以下原因而需要它,正如在
This loader is especially useful when using 3rd-party libraries having their own source maps. If not extracted and processed into the source map of the webpack bundle, browsers may misinterpret source map data. source-map-loader allows webpack to maintain source map data continuity across libraries so ease of debugging is preserved.
它是预加载器的原因是因为必须在