2015-06-25 33 views
8

我對我的角度客戶端應用使用browserify。我需要使用下劃線。角安裝有涼亭和下劃線安裝有NPM如果需要下劃線,browserify源地圖不起作用

我這是怎麼運行browserify(NPM)和創建一飲而盡(NPM)源地圖

gulp.task('browserify', function() { 
    return browserify(dir.script_from + '/main.js', {debug: true}) 
     .bundle() 
     .pipe(source('bundle.js')) // gives streaming vinyl file object 
     .pipe(buffer()) // <----- convert from streaming to buffered vinyl file object 
     .pipe(sourcemaps.init({loadMaps: true})) 
     .pipe(uglify()) // now gulp-uglify works 
     .pipe(sourcemaps.write('./')) 
     .pipe(gulp.dest(dir.script_to)); 
}); 

在我main.js,我有

//require('underscore') 
require('angular') 
require('angular-resource') 
require('angular-route') 
require('./home/home_page.js') 
... 

如果我不需要('下劃線'),源地圖正在工作。我可以查看原始文件並設置斷點。

enter image description here

但是,如果我需要( '下劃線'),源地圖不再工作。我甚至無法查看這些文件。

enter image description here

我也嘗試安裝與鮑爾強調,但我得到了以下錯誤:

[23:59:02] Starting 'browserify'... 
events.js:85 
     throw er; // Unhandled 'error' event 
      ^
Error: Cannot find module 'underscore' from '/Users/[my path]/app/client/script' 

注意兩個涼亭(我config'ed路徑),在NPM放模塊的/用戶/ [我的路徑]/node_modules'文件夾

我甚至嘗試了main.js只有一行:require('underscore')和不工作,但空main.js文件工作

+0

你有錯誤?如:「下劃線未定義」 – marcel

+0

@marcel npm沒有錯誤,'找不到'涼亭。 – John

+1

你是怎麼安裝'underscore'的? – marcel

回答

1

我有同樣的問題

require: ['node_modules/underscore'] 

的package.json underscore/browserify。也許更好的方法是將其排除在捆綁中。只需將<script>標籤鏈接到您的underscore文件即可。在包中,您可以直接使用_

如果您正在使用angular,建議還使用單獨的<script>,因爲大多數用戶可能已經有CDN的angular可用於另一個角色網站。

3

gulp正在檢查根目錄中的下劃線。嘗試在config.js或的package.json

config.js加下劃線的路徑

"underscore": "./node_modules/underscore"