11
今天下午我一直在嘗試使用Grunt和Require JS。我是text
模塊的忠實粉絲,並使用它來引入我的模板。在基於非Grunt的項目中,我使用了inlineText
和stubModules
要求使用JS選項來排列模板文件,並且效果很好。但是,我無法使用Grunt工作。內聯require.js文本!使用Grunt
需要配置
require.config({
paths: {
// Using Bower for dependency management
text: '../components/requirejs-text/text'
}
});
使用
define(['text!template.html'], function (html) {
// Do stuff with html
});
Gruntfile.js
requirejs: {
dist: {
options: {
baseUrl: 'app/scripts',
optimize: 'none',
preserveLicenseComments: false,
useStrict: true,
wrap: true,
inlineText: true,
stubModules: ['text']
}
}
}
運行後我在控制檯中的各種錯誤:
- 一個未找到文件上
/dist/components/requirejs-text/text.js
- 一個
Load timeout for modules: text!template.html_unnormalized2
兩個問題,那麼:
- 這似乎並沒有被內聯(然後存根)
text.js
代碼 - 它似乎沒有內聯
template.html
文件
任何想法爲什麼它不工作?
什麼是您的文件夾結構是什麼樣子?執行時,你確定'text.js'在'dist'目錄嗎? – 2013-06-21 19:36:42
我得到同樣的問題。對我來說,它看起來像構建工具正在尋找text.js,因爲單詞「text」出現在dependency ['text!template.html']中。我也在使用require文本插件。 – 2013-07-26 16:40:55
你使用哪種require.js庫,因爲有很多? – ghost23 2013-08-14 09:56:22