簡體   English   中英

嘗試使用grunt-contrib-uglify創建源地圖時出錯

[英]Error trying to create sourcemap with grunt-contrib-uglify

我正在嘗試為從ngBoilerplate模板派生的AngularJS應用程序添加源地圖,該模板使用grunt進行構建,並使用grunt-contrib-uglify將JavaScript源代碼壓縮到一個app.js文件中。

問題在於,grunt不能真正將源映射寫入磁盤,並出現這種神秘的錯誤(使用grunt --verbose,僅進行了少量編輯):

Running "uglify" task

Running "uglify:compile" (uglify) task
Verifying property uglify.compile exists in config...OK
Files: release/assets/MyApp-1.0.0.debug.js -> release/assets/MyApp-1.0.0.js
Options: banner="", footer="", compress={"warnings":false}, mangle={}, beautify=false, report="min", expression=false, sourceMap
Minifying with UglifyJS...Reading release/assets/MyApp-1.0.0.debug.js...OK
OK
Writing release/assets/MyApp-1.0.0.js...OK
Writing release/assets/MyApp-1.0.0.js.map...ERROR
Warning: Unable to write "release/assets/MyApp-1.0.0.map" file (Error code: undefined). Use --force to continue.

Aborted due to warnings.

關鍵部分是:

警告:無法寫入“ release / assets / MyApp-1.0.0.map”文件(錯誤代碼:未定義)。 使用--force繼續。

現在您可能會想說這是Grunt Uglify源圖“無法編寫”的重復,只是這種情況很簡單,在這種情況下, 問問者正在使用具有較舊版本軟件包的新配置樣式,從而導致錯誤Unable to write "true" file 就我而言不是這樣。 很明顯,它試圖寫入的文件名是正確的(JS文件加上“ .map”擴展名),但是系統無法做到這一點,並給出了非常無用的“錯誤代碼:未定義”。

來自packages.json文件的版本-我清除了node_modules文件夾,然后重新運行npm install以確保這是正在使用的內容:

"devDependencies": {
  "grunt": "0.4.5",
  "grunt-recess": "0.6.1",
  "grunt-contrib-jshint": "0.10.0",
  "grunt-contrib-concat": "0.4.0",
  "grunt-contrib-watch": "0.6.1",
  "grunt-contrib-uglify": "0.5.0",
  "grunt-karma": "0.6.2",
  "grunt-ngmin-with-comments": "0.0.3",
  "grunt-html2js": "0.2.3",
  "grunt-groundskeeper": "0.1.9",
  "lodash": "2.4.1",
  "grunt-contrib-clean": "0.5.0",
  "grunt-contrib-copy": "0.5.0",
  "grunt-contrib-connect": "^0.7.1"
}

在node_modules內部,uglify uglify-js版本為2.4.14。

我的Gruntfile配置不完全是樣板ngBoilerplate-我已經對其進行了一些修改,以便獲得未最小化的.debug.js和最小化的.js。 這里是:

uglify: {
    compile: {
        options: {
            sourceMap: true
        },
        files: {
            '<%= minJs %>': '<%= debugJs %>'
        }
    }
}

我也嘗試過:

  • 指定sourceMapName屬性
    • 作為字符串
    • 作為使用jsName並將其附加“ .map”的函數
    • 作為不嘗試在release / assets子目錄中寫入的函數
  • 不使用grunt模板,而是明確指定minJ和debugJ的文件名。

沒事。 有任何想法嗎?

我在使用不同的設置時遇到了相同的錯誤。 如果禁用源地圖,一切都會很好。 我花了幾個小時調試錯誤並放棄了。

只需切換到較舊的grunt-contrib-uglify,例如〜0.4,直到他們找出問題所在。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM