所以我有以下的gulp任务:
var gulp = require('gulp');
var source = require('vinyl-source-stream');
var browserify = require('browserify');
var babelify = require("babelify");
gulp.task('make:flare-currency', function() {
return browserify({entries: [
'src/add-new-currency/flare-currency.js',
'src/add-new-currency/currencies/set_up_currencies.js'
]})
.transform(babelify)
.bundle()
.pipe(source('Flare-Currency.js'))
.pipe(gulp.dest('dist/flare/currency/'));
});
我有以下package.json:
{
"name": "flare-collection",
"description": "collection of scripts for the RPG Maker MV system.",
"version": "0.0.1",
"dependencies": {
"gulp": "3.9.0",
"browserify": "11.2.0",
"vinyl-source-stream": "1.1.0",
"babelify": "6.4.0",
"underscore.string": "2.3.0"
}
}
当我尝试时,在src/add_new_currencies/flare_currency.js
var UnderScoreString = require('underscore.string/string');
我明白了:
错误:无法找到模块' underscore.string / string'从 ' /用户/ AdamBalan /文档/耀斑收集/ SRC / add_new_currencies'
我的所有需要声明都要求我执行:var bla = require('some/file/to/include.js')
我的所有课程(我使用的是es6)都位于文件的底部:module.exports = ClassName;
为什么我收到此错误?
更重要的是,为什么我必须包含js文件的路径?
答案 0 :(得分:1)
underscore.string
没有string
子模块(功能)。如果您想加载所有包,请尝试_s = require('underscore.string')
。如果您想加载slugify
之类的单个模块,请尝试slugify = require('underscore.string/slugify')
。
您不需要包含js文件的路径。如果您选择目录,则node.js
会尝试查找index.js
文件。