gpt4 book ai didi

javascript - 如何在没有 gulp/grunt/webpack 的情况下将 google-closure-compiler-js 用于 node.js 应用程序?

转载 作者:行者123 更新时间:2023-11-30 00:02:22 25 4
gpt4 key购买 nike

docs没有任何单独使用它的例子,但他们确实是这样说的:

Unless you're using the Gulp or Webpack plugins, you'll need to specify code via flags. Both jsCode and externs accept an array containing objects in the form {src, path, sourceMap}. Using path, you can construct a virtual filesystem for use with ES6 or CommonJS imports—although for CommonJS, be sure to set processCommonJsModules: true.

我已经根据文档创建了一个“compile.js”文件:

const compile = require('google-closure-compiler-js').compile;
const flags = {
jsCode: [{path: './server/server.js'}],
processCommonJsModules: true
};
const out = compile(flags);
console.info(out.compiledCode);

在我的“./server/server.js”文件中,我放了一个 console.log 但它没有输出。不知道从这里去哪里......

最佳答案

借自icidasset/quotes .

在我看来,该路径并不打算像您使用的那样使用。

引用:

Using path, you can construct a virtual filesystem for use with ES6 or CommonJS imports—although for CommonJS, be sure to set processCommonJsModules: true.

因此,您必须扩展自己的资源,当您走这条路时,webpack 和 gulp 必须为您做些什么。

files=['./server/server.js']
files.map(f => {
const out = compile({
jsCode: [{ src: f.content }],
assumeFunctionWrapper: true,
languageIn: 'ECMASCRIPT5'
});
return out;
}

关于javascript - 如何在没有 gulp/grunt/webpack 的情况下将 google-closure-compiler-js 用于 node.js 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39925364/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com