Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 用npm脚本替换gulp任务_Node.js_Webpack_Gulp_Npm Scripts - Fatal编程技术网

Node.js 用npm脚本替换gulp任务

Node.js 用npm脚本替换gulp任务,node.js,webpack,gulp,npm-scripts,Node.js,Webpack,Gulp,Npm Scripts,我的gulpfile.js中有一个gulp任务,如下所示: gulp.task('build', function() { let webPath = './webpack.config.dev.js'; if (process.env.var) { webpackConfigPath = './webpack.config.' + process.env.var + '.js'; } const webCon = require(webPat

我的gulpfile.js中有一个gulp任务,如下所示:

gulp.task('build', function() {
    let webPath = './webpack.config.dev.js';

    if (process.env.var) {
        webpackConfigPath = './webpack.config.' + process.env.var + '.js';
    }

    const webCon = require(webPath);

    return gulp.src('/js/index.js')
        .pipe(webpackStream(webCon, require("webpack")))
        .pipe(gulp.dest(BUILD_PATH));
});
function buildApp() {
    let webPath = '/webpack.config.dev.js';
    if (process.env.var) {
        webpath = '/webpack.config.' + process.env.var + '.js';
    }
    const webCon= require(webpackConfigPath);

    let readStr = fs.createReadStream('/ui/js/index.js');
    let writeStr = fs.createWriteStream('/src/main/resources/public/app.js');

    readStr.pipe(webpackStream(webpackConfig, require("webpack")))
        .pipe(writeStr);
}
为了替换它并摆脱我的吞咽依赖,我使用了fs extra软件包,并编写了一个函数,如下所示:

gulp.task('build', function() {
    let webPath = './webpack.config.dev.js';

    if (process.env.var) {
        webpackConfigPath = './webpack.config.' + process.env.var + '.js';
    }

    const webCon = require(webPath);

    return gulp.src('/js/index.js')
        .pipe(webpackStream(webCon, require("webpack")))
        .pipe(gulp.dest(BUILD_PATH));
});
function buildApp() {
    let webPath = '/webpack.config.dev.js';
    if (process.env.var) {
        webpath = '/webpack.config.' + process.env.var + '.js';
    }
    const webCon= require(webpackConfigPath);

    let readStr = fs.createReadStream('/ui/js/index.js');
    let writeStr = fs.createWriteStream('/src/main/resources/public/app.js');

    readStr.pipe(webpackStream(webpackConfig, require("webpack")))
        .pipe(writeStr);
}
然而,这引发了一个错误,即

TypeError: file.isNull is not a function
    at Stream.<anonymous> (path\node_modules\webpack-stream\index.js:95:14)
    at Stream.stream.write (path\node_modules\through\index.js:26:11)
    at ReadStream.ondata (_stream_readable.js:727:22)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
    at internal/fs/streams.js:191:12
    at FSReqCallback.wrapper [as oncomplete] (fs.js:470:5)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! esg-scoring-model@0.0.1 build: `node build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the esg-scoring-model@0.0.1 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     path\AppData\Roaming\npm-cache\_logs\2020-01-27T20_31_56_858Z-debug.log
TypeError:file.isNull不是函数
在溪流中。(path\node\u modules\webpack stream\index.js:95:14)
在Stream.Stream.write(path\node\u modules\through\index.js:26:11)
在ReadStream.ondata(_stream_readable.js:727:22)
在ReadStream.emit(events.js:210:5)
在addChunk(_stream_readable.js:309:12)
在readableAddChunk(_stream_readable.js:290:11)
在ReadStream.Readable.push(_stream_Readable.js:224:10)
在内部/fs/streams.js:191:12
在FSReqCallback.wrapper[as oncomplete](fs.js:470:5)
npm错误!代码失效循环
npm错误!错误1
npm错误!esg评分-model@0.0.1build:`node build.js`
npm错误!退出状态1
npm错误!
npm错误!在esg评分中失败-model@0.0.1构建脚本。
npm错误!这可能不是npm的问题。上面可能还有其他日志输出。
npm错误!此运行的完整日志可在以下位置找到:
npm错误!path\AppData\Roaming\npm缓存\\u日志\2020-01-27T20\u 31\u 56\u 858Z-debug.log

有什么建议吗?

它在哪里失败了,比如哪个呼叫?@Mikkel它在readStr.pipe(…)上失败了,我怀疑可能是这样。我认为
require(“webpack”)
应该可以,假设
webpackStream
是一个webpack函数,那么肯定是
webpackConfig
错了。代码片段没有显示这是如何得到的defined@Mikkel你是对的,我又看了一眼我的网页配置文件,发现了问题所在。非常感谢。