如何在没有gulp/grunt/webpack的情况下将google-closure-compiler-js用于node.js应用程序? [英] How to use google-closure-compiler-js for a node.js app without gulp/grunt/webpack?

查看:123
本文介绍了如何在没有gulp/grunt/webpack的情况下将google-closure-compiler-js用于node.js应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档没有任何单独使用此示例,确实这样说:

The docs don't have any examples of using this on its own but they do say this:

除非您使用的是Gulp或Webpack插件,否则需要通过标志指定代码. jsCode和externs都接受包含{src,path,sourceMap}形式的对象的数组.使用path,您可以构建一个虚拟文件系统以与ES6或CommonJS导入配合使用-尽管对于CommonJS,请确保将processCommonJsModules设置为true.

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"文件:

I've created a "compile.js" file based on the docs:

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,但未输出.不知道从这里去哪里...

In my "./server/server.js" file, I put a console.log but it doesn't output. Not sure where to go from here...

推荐答案

icidasset/quotes .

在我看来,该路径不适合您使用时使用.

It appears, to me, that path is not intended to be used as you are using it.

报价:

使用path,您可以构建用于ES6或CommonJS导入的虚拟文件系统-尽管对于CommonJS,请确保设置processCommonJsModules: true.

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做些事情.

So instead you must expand your own sources, something webpack and gulp must be doing for you when you go that route.

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

这篇关于如何在没有gulp/grunt/webpack的情况下将google-closure-compiler-js用于node.js应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆