我有这个目录结构:
webapp
├──static
│ ├── app
│ ├── config.js
│ ├── frontpage.js
│ ├── profile.js
│ └── utils.js
Gruntfile.js
我正在尝试使用 grunt-contrib-requirejs 来优化我对profile
和frontpage
. 现在我的 config.js 看起来像:
require.config({
{
baseUrl:"/static/app",
shim: {
bootstrap : { "deps" :['jquery'] } ,
velocity : { "deps" : ['jquery']}
},
paths: {
jquery: "../bower_components/jquery/dist/jquery.min",
bootstrap : "//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min",
requirejs: "../bower_components/requirejs/require",
handlebars: "../bower_components/handlebars/handlebars.min",
velocity: "../bower_components/velocity/velocity.min"
},
packages: []
});
我为 grunt-require-config 尝试了以下配置
requirejs: {
compile: {
options: {
appDir: "static/app",
modules : [
{
name: "profile"
}
],
mainConfigFile: "./static/app/config.js",
optimize: "none",
dir: "./static/build/"
}
}
}
但我收到此错误:
Running "requirejs:compile" (requirejs) task
{ [Error: Error: ERROR: module path does not exist: /static/app/profile.js for module named: profile. Path is relative to: /webapp
[..]
这很奇怪,因为那条路是正确的!
我找不到很多这样的例子,有人可以帮忙吗?
更新:
我只需要调整baseUrl
Gruntfile.js 中的appDir
. requirejs 选项中的 baseUrl 现在与配置中的相同。
requirejs: {
compile: {
options: {
baseUrl: "static/app",
/* modules : [
{
name: "profile"
},
{
name: "frontpage"
}
],*/
mainConfigFile: "./static/app/config.js",
optimize: "none",
dir: "./static/build/"
}
}
}