Webpack 4 - Sourcemaps

徘徊边缘 提交于 2019-12-19 05:12:30

问题


This article webpack 4: mode and optimization seems to suggest that when mode is set to development the devtool is set to eval.

I was expecting this to trigger sourcemap generation but running the webpack-4-quickstart in either development or production mode results in no sourcemaps being generated.

How can I generate sourcemaps with webpack 4?


回答1:


I think what you are expecting is extracted file including source maps like 'bundle.js.map', but eval type doesn't generate separate file:

eval - Each module is executed with eval() and //@ sourceURL. This is pretty fast. The main disadvantage is that it doesn't display line numbers correctly since it gets mapped to transpiled code instead of the original code (No Source Maps from Loaders).

But you can always do it by manually configuring devtool property like:

devtool: 'source-map'

which will extract source-maps to a file. Here are described types of sourcemaps along with their costs and benefits.

EDIT:

Actually there is a issue on github with a PR related to this. Right now UglifyJS plugin has set sourceMap: false even in production mode and it doesn't let extracting source-maps to separate file even with devtool set.




回答2:


The easiest setup is to add the devtool: 'sourcemaps' as before.

module.exports = {
  devtool: 'source-map',
  ...
};

But this generates sourcemaps both for development or production mode.



来源:https://stackoverflow.com/questions/48986641/webpack-4-sourcemaps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!