Google 闭包 base.js & 模块

Google closure base.js & modules

我试图在开发时在我的浏览器中简单地加载 google 闭包模块,所以我不需要任何疯狂的高级编译。

我的 index.js 包含:

goog.module("Widgets.index");

var Widgets$app = goog.require("Widgets.app");
/* rest of the code */

我的 index.html 包含以下内容:

<script src="closure/base.js"></script>
<script src="index.js"></script>

我在我的控制台中得到以下信息:

Module Widgets.index has been loaded incorrectly. 
Note, modules cannot be loaded as normal scripts.
They require some kind of pre-processing step

如何预处理 index.js? 我只想在我的浏览器中加载一些简单的 google 模块,这是开发时间。不需要任何疯狂的(缓慢的?)优化..

您的入口点作为脚本包含在页面上,但将其自身定义为模块。这就是错误消息告诉您的内容。相反:

index.js

goog.provide("Widgets.index");

var Widgets$app = goog.require("Widgets.app");
/* rest of the code */