Coffeescript r、 每次我尝试在Coffee脚本中分配变量时,js都会抛出一个错误
所以我用r.js构建了一堆文件,其中一些是咖啡脚本。我正在使用Require插件Coffeescript r、 每次我尝试在Coffee脚本中分配变量时,js都会抛出一个错误,coffeescript,Coffeescript,所以我用r.js构建了一堆文件,其中一些是咖啡脚本。我正在使用Require插件Require cs来处理这个问题 下面是我的Require.js配置,一个la rjs: rjs.optimize({ baseUrl: SRC_PATH, include: channelMap[channel], optimize: 'none', stubModules: ['cs', 'tpl', 'less', 'text'], exclude: ['normali
Require cs
来处理这个问题
下面是我的Require.js配置,一个la rjs:
rjs.optimize({
baseUrl: SRC_PATH,
include: channelMap[channel],
optimize: 'none',
stubModules: ['cs', 'tpl', 'less', 'text'],
exclude: ['normalize', 'coffee-script', 'underscore'],
CoffeeScript: {
header: false,
// since we use AMD, there's no need for IIFE
bare: true
},
separateCSS: true,
skipModuleInsertion: true,
// If something needs to be present for tests too and not only for
// the build step, then add it tools/karma-amd.js instead
paths: _.extend({
'less-builder': 'vendor/require-less/less-builder',
'normalize': 'vendor/require-less/normalize'
}, rjsPaths),
wrap: true,
less: {
paths: [path.join(BASE_SHOP_FOLDER, 'static', 'zalando', 'css', channel)]
},
out: path.join(BUILD_PATH, channel, BUILD_BASE_FILE_NAME + '.js')
}, function () {
// this needs to be async because less builder uses
// process.nextTick() to write the file
process.nextTick(done);
});
即使是最简单的.coffee文件似乎也会严重失败。例如
define [], ->
foo = "hello world"
return foo
引发以下错误:
the variable "foo" can't be assigned with undefined because it has not been declared before
foo = "hello world"
^^^
当我使用旧版本的
1.6.3
替换require cs
的coffee script.js
时,一切正常。我无法重新创建问题:
$ cat ./etc/temp1.coffee
define [], ->
foo = "hello world"
return foo
$ coffee --version
CoffeeScript version 1.7.1
$ which coffee
/home/dev/.nvm/v0.10.23/bin/coffee
$ coffee -cp ./etc/temp1.coffee
// Generated by CoffeeScript 1.7.1
(function() {
define([], function() {
var foo;
foo = "hello world";
return foo;
});
}).call(this);
$ coffee -cpb ./etc/temp1.coffee
// Generated by CoffeeScript 1.7.1
define([], function() {
var foo;
foo = "hello world";
return foo;
});
顺便说一句,您的代码可以编译。尝试转到并单击
Try COFFEESCRIPT
,您将看到它是有效的代码
从define[],()->code…
,我假设您正在使用带有require.js的CoffeeScript插件。我敢打赌,您的问题出在require.js
配置中(应该是您的main.js
文件或您命名的任何文件),因为您得到的错误看起来很奇怪,就像JavaScript解释器试图运行您编写的无效代码(对于JavaScript,即:)。也就是说,你的插件根本不存在
如果你给我你需要的配置,也许我可以编辑这个答案,帮助你更多
干杯
编辑
我看到你编辑了你的问题,但你给我提供了错误的文件。您向我展示的是r.js
优化器配置,而不是指定如何加载cs.js
和coffee script.js
文件的main.js
。错误可能在您的优化器中,但如果不查看其他配置,我就无法知道
再重复一遍,告诉我你的程序的入口点,即加载在HTML中的数据主文件。原来问题出在我以前版本的1.7.1
上。有人美化了它,破坏了一切。当我特意从获取coffee-script.js时,一切都如广告所示。你是如何安装编译器的?你能提供一个链接/命令吗?这是优化器的r.js配置,我能看到main.js文件吗?在那里你可以指定路径的工作方式(即cs.js和coffeescript.js文件应该在哪里)是的,很好,我用的是require!让我编辑我的原始问题以反映这一点。