How to use source map to find minification error

前端 未结 1 940
日久生厌
日久生厌 2021-02-09 19:38

I work with Angular and RequireJS. I tried to use RequireJS optimization, and now my application is not working. I am sure it\'s due to minification.

Uncaught Erro

相关标签:
1条回答
  • 2021-02-09 20:05

    Here are the steps which should make it working for you:

    1. In Chrome's Developer Tools click the settings icon (bottom right corner).
    2. In the settings dialog, check "Enable source maps".
    3. Open the web page you want to debug.
    4. Open the Developer Tools (in this new tab)
    5. Reload the page
      • It's important, otherwise Chrome will not download map file.
    6. Press the error link you want to inspect
      • It's on the right of your error, i.e. main.js:12.
    7. That's it. You should be now redirected to human-readable, non-minified version of your script.

    If source maps are still not working:

    1. Make sure minified JS file contains, at the very bottom, something like:

      //# sourceMappingURL=main.js.map

    2. Make sure mapping file is being downloaded. It should be listed in "Network" section of Developer Tools as downloaded during page reload. It should look like this:

      source map file download status

    3. Maybe RequireJS's minification strips out the sourceMappingURL comment from your output JS file?

      Make sure that you're using uglify2 method and you've enabled generateSourceMaps option. Here is relevant part of my requirejs target config from Grunt:

    requirejs: {
      compile: {
        options: {
          /* some other options here */
          optimize: 'uglify2',
          logLevel: 0,
          preserveLicenseComments: false,
          generateSourceMaps: true
        }
      }
    }
    
    0 讨论(0)
提交回复
热议问题