我来自 AMD,似乎已经做错了什么。
我做了这样的设置:
client/js/index.js (entry point)
client/js/test.js
我希望它建立:
build/app.js
index.js
需要test.js
这样:
var test = require('./test');
我的gulp
watchify
任务如下所示:
var gulp = require('gulp');
var gutil = require('gulp-util');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var watchify = require('watchify');
// https://github.com/gulpjs/gulp/blob/master/docs/recipes/fast-browserify-builds-with-watchify.md
gulp.task('watch', function () {
var bundler = watchify(browserify('./client/js/index.js', watchify.args));
bundler.on('update', rebundle);
function rebundle () {
return bundler.bundle()
// Log errors if they happen.
.on('error', function(e) {
gutil.log('Browserify Error', e.message);
})
.pipe(source('app.js'))
.pipe(gulp.dest('./build'));
}
return rebundle();
});
不过,编译后的代码看起来是错误的,因为test.js
我看到绝对本地路径对于任何使用该代码的人来说肯定是损坏的或冗余的?
PS我正在运行没有args的任务(只是gulp watch
)
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({"./client/js/index.js":[function(require,module,exports){
var test = require('./test');
var ab = function(a, b2) {
return a + b2;
};
module.exports = ab;
},{"./test":"/Users/dtobias/Sites/browserify-test/client/js/test.js"}],"/Users/dtobias/Sites/browserify-test/client/js/test.js":[function(require,module,exports){
var helloworld = function () {
console.log('hello world');
};
module.exports = helloworld;
},{}]},{},["./client/js/index.js"]);