我正在尝试使用Grunt-browserify并重新解析来解析和捆绑用jsx编写的React组件.我想使用扩展标志,以便我不必指定我的模块的文件扩展名,但我无法让它工作.这是一些测试代码:
一个Gruntfile:
'use strict';
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
browserify: {
dev: {
src: 'src/app.jsx',
dest: 'dest/app.js',
options: {
debug: true,
transform: ['reactify'],
extensions: ['.jsx']
}
}
}
});
grunt.loadNpmTasks('grunt-browserify');
grunt.registerTask('default', ['browserify:dev']);
};
Run Code Online (Sandbox Code Playgroud)
主app文件app.jsx:
'use strict';
var React = require('react');
var Test = require('./components/Test'); // Here is the problem...
React.render(
<Test />,
document.getElementById('test')
);
Run Code Online (Sandbox Code Playgroud)
然后Test.jsx:
'use strict';
var React = require('react');
var Test = React.createClass({
render: function() {
return(
<div>
<p>Some markup</p>
</div>
); …Run Code Online (Sandbox Code Playgroud) 我的Grunt装置发生了一些事情,我不知道它是什么.我正在使用Yeoman来构建我的应用程序,但今天我开始遇到很多Grunt错误.例如,我现在运行时得到以下内容Grunt Test:
Loading "autoprefixer.js" tasks...ERROR
>> Error: Cannot find module 'base64-js'
Loading "connect.js" tasks...ERROR
>> Error: Cannot find module 'cookie-signature'
Loading "imagemin.js" tasks...ERROR
>> Error: Cannot find module './lib/js-yaml.js'
Loading "jshint.js" tasks...ERROR
>> Error: Cannot find module 'jshint'
Loading "uglify.js" tasks...ERROR
>> Error: Cannot find module './source-map/source-map-generator'
Loading "cdnify.js" tasks...ERROR
>> SyntaxError: /Users/Documents/Git/client/node_modules/grunt-google-cdn/node_modules/google-cdn/node_modules/cdnjs-cdn-data/external/cdnjs.json: Unexpected end of input
Loading "grunt-karma.js" tasks...ERROR
>> SyntaxError: /Users/Documents/Git/client/node_modules/karma/node_modules/socket.io/node_modules/engine.io/lib/server.js:390
>> });
>>
>> Unexpected end of input
Loading "ngmin.js" tasks...ERROR
>> Error: Cannot find …Run Code Online (Sandbox Code Playgroud) 我已经挣扎了好几天才想出来,但最后我今天需要你的帮助.
我的回购:https://github.com/seoyoochan/bitsnut-web
我想要实现的目标:
- 加载和优化r.js - 为RequireJS和r.js编写凉亭任务:
任务是:对RequireJS进行minify &uglify&concatenation,并在生产时使用r.js进行优化
- 如何排除js脚本标签在index.html使用wiredep任务并通过RequireJS加载器加载它们时?
我使用Yeoman'Webapp'生成器并生成了脚手架应用程序.
我安装骨干,提线木偶,文本,下划线和等经bower install
我修改bower.json通过删除dependencies只留下"requirejs": "~2.1.16"上dependencies.(devDependencies是空的)
因为我用的[2][grunt-wiredep],一切都自动加载bower_components到index.html.我修改.bowerrc了存储依赖项app/scripts/vendor.
但是,问题是我不知道如何通过ReuqireJS成功加载它们而不是将供应商作为脚本标签加载到里面index.html.我必须为RequireJS和r.js编写一些任务,但不知道如何实现这个目标(grunt-contrib-requirejs虽然我安装了)
我想跟着4的方法来利用r.js在https://github.com/jrburke/requirejs/wiki/Patterns-for-separating-config-from-the-main-module.但我遇到的问题是RequireJS的文档建议不要使用named module,但是anonymous module.我想听听关于我应该如何处理的各种意见.
我非常感谢你的帮助!
javascript backbone.js gruntjs yeoman grunt-contrib-requirejs
我想编写一个Grunt任务,在构建期间,将复制我拥有的所有.html文件,并在/ dist中创建它的.asp版本.
我一直在尝试使用grunt-contrib-copy来实现这一点,这就是我所拥有的:
copy: {
//some other tasks that work...
//copy an .asp version of all .html files
asp: {
files: [{
expand: true,
dot: true,
cwd: '<%= config.app %>',
src: ['{,*/}*.html'],
dest: '<%= config.dist %>',
option: {
process: function (content, srcpath) {
return srcpath.replace(".asp");
}
}
}]
} //end asp task
},
Run Code Online (Sandbox Code Playgroud)
我知道这个process功能实际上并不正确......我已经尝试了一些不同的正则表达式,使其工作无济于事.当我运行asp任务时,Grunt CLI说我已经复制了2个文件,但它们无处可寻.任何帮助表示赞赏.
TLDR;
固定如下
selectedValue = selectedValue.replace(/\s+/g, '')
Run Code Online (Sandbox Code Playgroud)
感谢:Richard Macarthy和Aaron Digulla的回答,这让我想起了正确的答案.
只是很明显,似乎Grunt出于某种原因添加了这个空白.修复非常简单......
原始问题
我有一个JSON请求,它使用d3.js获取要用于数据可视化的JSON文件的内容.
这一切都在本地工作正常,但是当我运行grunt构建时,URL字符串会%20从无处注入其中...
以下是在运行Grunt之前字符串的外观:
d3.json("json/wards-info/"+selectedValue+"-wards-data.json", function(error, newDatas) {
newData = newDatas;
newWardsData = newWardsDatas;
drawMap(newData, newWardsData);
});
Run Code Online (Sandbox Code Playgroud)
其中计算:
http://localhost:8080/app/json/wards-info/liverpool-ward-data.json
Run Code Online (Sandbox Code Playgroud)
运行Grunt后,计算出的URL字符串变为:
http://localhost:8080/dist/json/wards-info/liverpool%20-ward-data.json
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,它似乎是%20在两者之间添加liverpool-ward
这是因为咕噜声,还是因为别的什么?
我有一个令人兴奋的Node应用程序,我想从Heroku托管到Bluemix.这有点复杂,部署运行各种任务,由我的package.js文件的一部分启动:
"scripts": {
"start": "node app.js",
"postinstall": "grunt heroku"
},
Run Code Online (Sandbox Code Playgroud)
这个咕噜咕噜的任务开始在我的Gruntfile.js文件中找到依赖的谈话,比如拉动Bower包,缩小图像,浏览器,移动,文件,清理等.
我想我可以在推送到Bluemix时启动部署任务?如果是这样,它们是否会以类似的方式完成(脚本部分中的命令package.json)来运行我定义的任务Gruntfile.js?
在heroku中,我的整个git repo将被复制到他们的远程,所以一切都在那里,而不仅仅是运行脚本产生dist目录的输出,我认为在Bluemix上会是一样的吗?
最后,在我的包文件中,我将定义npm和节点版本:
"engines": {
"npm": "2.5.1",
"node": "0.12.0"
}
Run Code Online (Sandbox Code Playgroud)
和Heroku将确保它运行特定于我的实例的版本.Bluemix是否相同?
非常感谢你!保罗
我正在尝试最小化一些棱角分明的脚本,但由于某种原因,uglify会无限期地挂起。如果我将JSHint添加到任务列表中,它将运行良好并完成,然后挂在uglify上。
这是我的Gruntfile:
module.exports = function (grunt) {
// Project configuration
grunt.initConfig({
// make node configuration available for use
pkg: grunt.file.readJSON('package.json'),
// configure uglify
uglify: {
options: {
mangle: false
},
my_target: {
dist: {'dist/test.min.js': ['src/test.js']}
}
},
// configure JSHint
jshint: {
app: ['src/*.js']
}
});
// load pluginsng
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
// default
grunt.registerTask('default', ['jshint', 'uglify']);
grunt.registerTask('uglify', ['uglify']);
};
Run Code Online (Sandbox Code Playgroud)
这是我使用的版本:
"devDependencies": {
"grunt": "~0.4.5",
"grunt-contrib-jshint": "~0.11.2",
"grunt-contrib-uglify": "~0.9.1"
}
Run Code Online (Sandbox Code Playgroud)
我跑了grunt -v,在jshint完成后,它将永远输出:
Running "uglify" task
Running "uglify" task
Running …Run Code Online (Sandbox Code Playgroud) 我不能让chai在业力/咕噜声中设置chai-as-promise.
我收到以下错误,当我运行grunt test或karma test/karma.conf.js:
PhantomJS 1.9.8 (Mac OS X 0.0.0) ERROR
ReferenceError: Can't find variable: chai
at /Users/isaac/Sites/ChessGame/node_modules/chai-as-promised/lib/chai-as-promised.js:19
Run Code Online (Sandbox Code Playgroud)
这对于这个问题看起来像是一个类似的问题,但是我遇到的问题是chai-as-promise,而不是sinon-chai.我已经证实node_modules/chai/chai.js存在.
这是我的package.json文件:
{
"name": "chessgame",
"private": true,
"devDependencies": {
"angular-mocks": "^1.4.3",
"chai": "^3.2.0",
"chai-as-promised": "^5.1.0",
"chai-things": "^0.2.0",
"grunt": "^0.4.5",
"grunt-angular-templates": "^0.5.7",
"grunt-autoprefixer": "^2.0.0",
"grunt-concurrent": "^1.0.0",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-compass": "^1.0.0",
"grunt-contrib-concat": "^0.5.0",
"grunt-contrib-connect": "^0.9.0",
"grunt-contrib-copy": "^0.7.0",
"grunt-contrib-cssmin": "^0.12.0",
"grunt-contrib-htmlmin": "^0.4.0",
"grunt-contrib-imagemin": "^0.9.2",
"grunt-contrib-jshint": "^0.11.0",
"grunt-contrib-uglify": "^0.7.0",
"grunt-contrib-watch": "^0.6.1",
"grunt-filerev": "^2.1.2",
"grunt-google-cdn": "^0.4.3",
"grunt-karma": "*",
"grunt-mocha": …Run Code Online (Sandbox Code Playgroud) 我想使用FAKE自动化我的项目的构建过程,这需要我运行一个艰巨的任务.
特别是,我想创建一个在解决方案文件夹的子文件夹中运行grunt构建任务的目标.由于我缺乏F#知识,我无法将多个参数传递给Shell类的静态Exec方法.https://fsharp.github.io/FAKE/apidocs/fake-processhelper-shell.html
这是我到目前为止所得到的:
Target "RunGrunt" (fun _ ->
let errorCode = Shell.Exec "grunt" "build" "\Frontend"
()
)
Run Code Online (Sandbox Code Playgroud)
此操作失败,并显示以下错误消息:
build.fsx(38,23): error FS0003: This value is not a function and cannot be applied
Run Code Online (Sandbox Code Playgroud)
如果我删除最后2个参数,它可以工作,但无法在运行时找到grunt:
System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at Fake.ProcessHelper.start(Process proc) in C:\code\fake\src\app\FakeLib\ProcessHelper.fs:line 22
at Fake.ProcessHelper.asyncShellExec@424-2.Invoke(Process _arg1) in C:\code\fake\src\app\FakeLib\ProcessHelper.fs:line 428
at Microsoft.FSharp.Control.AsyncBuilderImpl.callA@851.Invoke(AsyncParams`1 args)
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.FSharp.Control.AsyncBuilderImpl.commit[a](Result`1 res)
at Microsoft.FSharp.Control.CancellationTokenOps.RunSynchronously[a](CancellationToken …Run Code Online (Sandbox Code Playgroud)