如果需要下划线browserify源地图不工作 [英] browserify source map not working if require underscore
问题描述
我用browserify我的角度客户端应用程序。我需要使用下划线。角安装了凉亭和下划线安装NPM
I use browserify for my angular client app. I need to use underscore. angular is installed with bower and underscore is installed with npm
这是我如何运行browserify(NPM)和一饮而尽创建源地图(NPM)
This is how I run browserify (npm) and create source map in gulp (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,我有
In my main.js, I have
//require('underscore')
require('angular')
require('angular-resource')
require('angular-route')
require('./home/home_page.js')
...
如果我不要求('下划线'),源地图正在工作。我可以查看原文件,并设置断点。
if I don't require('underscore'), the source map is working. I can view the original files and set breakpoints.
但是,如果我需要('下划线'),源地图不工作了。我甚至无法查看文件。
But if I require('underscore'), source map is not working anymore. I can't even view the files.
我也尝试安装带有凉亭下划线,但我得到了以下错误:
I also tried installing underscore with bower, but i get the following error:
[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文件夹
Note that both bower (I config'ed the path) and npm put modules in '/Users/[my path]/node_modules' folder
我甚至尝试了main.js只有一个行:要求('下划线')
并没有工作,但空main.js文件的工作。
I even tried a main.js with only one line: require('underscore')
and not working, but empty main.js file works
推荐答案
我有下划线/ browserify
同样的问题。也许更好的办法是排除它在包。只要有一个&LT;脚本&GT;
标签链接到你的下划线
文件。而在包你可以使用 _
直接。
I am having the same issue with underscore/browserify
. Maybe a better way is to exclude it in the bundle. Just have a <script>
tag linking to your underscore
file. And in the bundle you can use _
directly.
如果你正在使用的角度,建议使用一个单独的&LT;脚本&GT;
为好,因为大多数用户可能已经有角
可从CDN另一个角度网站。
If you are using angular, it's recommended to use a separate <script>
as well, since most users probably already have angular
available from CDN for another angular website.
这篇关于如果需要下划线browserify源地图不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!