Module 闭包编译器是否支持js文件所需的CommonJS样式?
我正在尝试使用谷歌闭包编译器 我遵循了带有processCommonJsModules标志的google闭包编译器js中的示例:Module 闭包编译器是否支持js文件所需的CommonJS样式?,module,google-closure-compiler,commonjs,Module,Google Closure Compiler,Commonjs,我正在尝试使用谷歌闭包编译器 我遵循了带有processCommonJsModules标志的google闭包编译器js中的示例: gulp.task('script', function () { return gulp.src('./src/app/index.js') .pipe(compiler({ compilationLevel: 'SIMPLE', warningLevel: 'VERBOSE', jsOutputFile: 'outp
gulp.task('script', function () {
return gulp.src('./src/app/index.js')
.pipe(compiler({
compilationLevel: 'SIMPLE',
warningLevel: 'VERBOSE',
jsOutputFile: 'output.min.js', // outputs single file
createSourceMap: true,
processCommonJsModules: true
}));
.pipe(gulp.dest('./dist'));
});
而且,index.js
包含require('./app.js')
这不起作用,错误消息也没有什么帮助:
[17:59:04] src\app\index.js:2 (JSC_COMMONJS_MODULE_LOAD_ERROR)
[17:59:04] Failed to load module "./app.js"
[17:59:04] require('./app.js');
就这些。它只是说编译失败了,没有提到原因
我已经阅读了closurecompiler repository()中有关模块的文档,我发现有一个描述:路径必须是绝对路径或相对路径,并且省略文件扩展名
我尝试了以下四种方法,但没有一种有效:
requure('./app.js')
requure('./app')
requure('/absolute/path/to/app.js')
requure('/absolute/path/to/app')
或者,我遗漏了什么吗?闭包编译器不会发现源文件-您必须传入所有可能的模块源。此外,还需要使用,以便编译器正确地排序源文件 我希望您的吞咽脚本类似于:
gulp.task('script', function () {
// modify this to get all of your source files
return gulp.src('./src/app/**')
.pipe(compiler({
compilationLevel: 'SIMPLE',
warningLevel: 'VERBOSE',
jsOutputFile: 'output.min.js', // outputs single file
createSourceMap: true,
processCommonJsModules: true,
dependency_mode: 'LOOSE',
entry_point: './src/app/index'
}));
.pipe(gulp.dest('./dist'));
});