当前位置: 代码迷 >> JavaScript >> 我在哪里注册我的JS,以便由grunt添加?
  详细解决方案

我在哪里注册我的JS,以便由grunt添加?

热度:40   发布时间:2023-06-07 11:42:53.0

我使用了yeoman生成器(html5站点)。

我有一个现有项目,想要转换为grunt / bower工作流程。

我有一个.js文件,该文件可以满足旧项目的要求。 将其复制到新的基于Bower / Grunt的项目的development文件夹中,不会导致将其串联到最终的单个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管理的项目中需要做什么?

通常,我从未见过关于文件夹的含义的清晰描述,该文件夹意味着将什么工作流程添加到脚手架项目中。 但是我觉得一定有一些Wiki或一些教书的东西! 我不相信开发人员的mi幸行为是通过错误和错误发现的...

我无法猜测您是否执行了此操作,但是您需要加载 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