我使用了 yeoman 生成器(html5 网站)。
我有一个现有项目,我想将其转换为 grunt/bower 工作流程。
我有一个来自旧项目的 .js 文件,它可以执行我想要的操作。 将其复制到基于 Bower/grunt 的新项目的开发文件夹中不会导致它连接到最终的单个 mainsite.js。
所以我检查了 gruntfile.js 并将其添加到此处:
concat : {
options: {
banner: '<%= banner %>',
stripBanners: false
},
main : {
src : [
'bower_components/jquery/dist/jquery.js',
'bower_components/jQueryui/ui/jquery-ui.js',
'bower_components/jqueryui-touch-punch/jquery.ui.touch-punch.js ',
'bower_components/RWD-FitText.js/jquery.fittext.js',
'bower_components/BrowserDetection.js/BrowserDetection.js',
'bower_components/respond/dest/respond.src.js',
'main-2k15-dribble/JavaScript/Main.js',
'main-2k15-dribble/JavaScript/mainsite.js',
this added---> 'main-2k15-dribble/JavaScript/jribble.js'
],
dest : 'main-2k15-dribble-pub/js/mainsite.js'
}
},
我特别想知道我需要做什么才能将现有的 javascript 添加到由 grunt 和 Bower 管理的项目中?
一般来说,我从未见过关于哪个文件夹意味着什么以及添加到脚手架项目的工作流程的清晰描述。但我觉得一定有一些维基或其他东西教这个!我不相信数以百万计的开发人员通过反复试验发现了这一点......
最佳答案
我无法猜测您是否执行了此操作,但您需要加载 grunt-contrib-concat
npm,然后注册一个任务来执行此操作,因此您的 Gruntfile.js 应如下所示:
'use strict';
module.exports = function (grunt) {
// Project Configuration
grunt.initConfig({
concat: {
options: {
banner: '<%= banner %>',
stripBanners: false
},
main: {
src: [
'bower_components/jquery/dist/jquery.js',
'bower_components/jQueryui/ui/jquery-ui.js',
'bower_components/jqueryui-touch-punch/jquery.ui.touch-punch.js ',
'bower_components/RWD-FitText.js/jquery.fittext.js',
'bower_components/BrowserDetection.js/BrowserDetection.js',
'bower_components/respond/dest/respond.src.js',
'main-2k15-dribble/JavaScript/Main.js',
'main-2k15-dribble/JavaScript/mainsite.js',
'main-2k15-dribble/JavaScript/jribble.js'],
dest: 'main-2k15-dribble-pub/js/mainsite.js'
}
},
});
require('load-grunt-tasks')(grunt);
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.registerTask('concat', ['concat']);
};
然后运行它:
grunt concat
关于javascript - 我在哪里注册我的 JS 以便 grunt 添加它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31877328/