javascript - 我在哪里注册我的 JS 以便 grunt 添加它?

标签 javascript node.js gruntjs bower yeoman

我使用了 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/

相关文章:

node.js - npm 脚本的时间/性能指标

node.js - socketio广播消息只发送给一个

node.js - 在 Elastic Beanstalk 中更新 Nodejs 版本

javascript - 如何解决 "Access Denied: Invalid token, wrong code"的问题?

node.js - grunt-contrig-imagemin 警告 : Cannot call method 'replace' of undefined

javascript - 错误 : Must use import to load ES Module: D:\node_modules\react-markdown\index. 不支持 ES 模块的 js require()

javascript - 如何垂直对齐一行中两个元素的中心?

javascript - 自定义嵌入了 iframe 的谷歌地图

javascript - 为什么人们在 render() 中从 React 中的状态属性定义变量?

javascript - 我的项目中可以有多个 gruntjs 文件用于代码组织吗?