我在尝试排除文件(like so in Browserify)时遇到问题。
使用此命令:
int Student::readRecord(fstream & in, Student s[])
{
int j = 0;
if (!in)
{
cout << "cannot open the file or file does not exists\n";
exit(0);
}
else
{
char name[30];
int g[5];
char ch;
while (in)
{
in >> name;
for (int i = 0; i<5; i++)
{
in >> g[i];
if (i != 4)
in >> ch;
}
s[j].setName(name);
s[j].setGrade(g);
j++;
}
}
return j - 1;
}
它首先编译好,但在对观察文件进行任何更新时会出错。这是完整的输出:
watchify scripts/main.js -o scripts/main.bundle.js -t strictify -v -x scripts/libs.js
这是任何变通办法的已知问题吗?现在,我可以编辑1036 bytes written to scripts/main.bundle.js (0.04 seconds)
fs.js:430
binding.open(pathModule._makeLong(path),
^
TypeError: path must be a string
at Object.fs.open (fs.js:430:11)
at OpenReq.process (/usr/lib/node_modules/watchify/node_modules/chokidar/node_modules/readdirp/node_modules/graceful-fs/graceful-fs.js:55:16)
at OpenReq.Req (/usr/lib/node_modules/watchify/node_modules/chokidar/node_modules/readdirp/node_modules/graceful-fs/graceful-fs.js:126:8)
at new OpenReq (/usr/lib/node_modules/watchify/node_modules/chokidar/node_modules/readdirp/node_modules/graceful-fs/graceful-fs.js:49:7)
at Object.open (/usr/lib/node_modules/watchify/node_modules/chokidar/node_modules/readdirp/node_modules/graceful-fs/graceful-fs.js:41:3)
at ReadStream.open (fs.js:1509:6)
at new ReadStream (fs.js:1496:10)
at Object.fs.createReadStream (fs.js:1450:10)
at Deps.readFile (/usr/lib/node_modules/watchify/node_modules/browserify/node_modules/module-deps/index.js:190:17)
at /usr/lib/node_modules/watchify/node_modules/browserify/node_modules/module-deps/index.js:365:14
并为生产做一个常规的Browserify构建(以排除文件),但是对于开发来说,这会使Watchify任务稍微变慢。
感谢您的帮助!
答案 0 :(得分:0)
一种解决方法是完全跳过Watchify并使用nodemon来处理观看。这是用于开发和生产构建的完整package.json:
{
"private": true,
"devDependencies": {
"node-sass": "latest",
"autoprefixer": "latest",
"browserify": "latest",
"strictify": "latest",
"uglify-js": "latest",
"nodemon": "latest"
},
"scripts": {
"build:main:bundle": "browserify scripts/main.js -o scripts/main.bundle.js -x ./scripts/libs.js -t strictify",
"build:main:uglify": "uglifyjs scripts/main.bundle.js -c -o scripts/main.bundle.js",
"build:main": "npm run build:main:bundle && npm run build:main:uglify",
"build:libs:bundle": "browserify -r ./scripts/libs.js -o scripts/libs.bundle.js -t strictify",
"build:libs:uglify": "uglifyjs scripts/libs.bundle.js -c -o scripts/libs.bundle.js",
"build:libs": "npm run build:libs:bundle && npm run build:libs:uglify",
"build:styles": "node-sass --stdout --output-style compressed styles/styles.scss | autoprefixer -o styles/styles.css",
"build": "npm run build:main && npm run build:libs && npm run build:styles",
"watch:main": "nodemon -e js -w scripts -i scripts/main.bundle.js -x 'npm run build:main:bundle'",
"watch:styles": "nodemon -e scss -w styles -x 'npm run build:styles'",
"watch": "npm run watch:main & npm run watch:styles"
}
}
这允许使用这两个命令进行开发(使用watch)和生产(使用build):
npm run watch
npm run build
唯一需要注意的是做手册
npm run build:libs
无论何时更新scripts / libs.js文件(其中包含jQuery / Backbone / TweenLite等文件,因此您不必经常更新)。有关完整示例,请参阅:Weblate。
感谢NPM for Everything帮助找到解决方案......即使它没有直接解决Watchify问题......