zoukankan      html  css  js  c++  java
  • ☀【SeaJS】SeaJS Grunt构建

    如何使用Grunt构建一个中型项目?
    https://github.com/twinstony/seajs-grunt-build

    spmjs
    http://docs.spmjs.org/doc/index

    package.json

    {
        "name": "hi",
        "version": "0.0.1",
        "devDependencies": {
            "grunt": "*",
            "grunt-cmd-transport": "*",
            "grunt-cmd-concat": "*",
            "grunt-contrib-clean": "*"
        }
    }

    Gruntfile.js

    module.exports = function(grunt) {
        grunt.initConfig({
            transport: {
                options: {
                    idleading: 'dist/'
                },
                target: {
                    expand: true, 
                    cwd: '.',
                    src: ['module1.js', 'module2.js'],
                    dest: '.build'
                }
            },
            concat: {
                options: {
                    include: 'relative'
                },
                target: {
                    expand: true,
                    cwd: '.build',
                    src: ['*.js'],
                    dest: 'dist'
                }
            },
            clean: {
                build: ['.build']
            }
        });
        
        grunt.loadNpmTasks('grunt-cmd-transport')
        grunt.loadNpmTasks('grunt-cmd-concat')
        grunt.loadNpmTasks('grunt-contrib-clean')
    
        grunt.registerTask('build', ['transport', 'concat'/*, 'clean'*/])
    }

    module1.js

    define(function(require, exports, module) {
        var module1 = {}
        module1.say = function(word) {
            console.log(word)
        }
        module.exports = module1 
    })

    module2.js

    define(function(require, exports, module) {
        var module1 = require('./module1')
        module1.say('hi')
    })

    test.html

    <!doctype html>
    <html>
    <head>
        <meta charset="utf-8">
        <title></title>
    </head>
    <body>
        <script src="sea.js"></script>
        <script>
            seajs.use('./dist/module2')
        </script>
    </body>
    </html>

    grunt build → dist/module2.js

    define("dist/module2", [ "./module1" ], function(require, exports, module) { // 执行路径匹配的
        var module1 = require("./module1");
        module1.say("hi");
    });
    
    define("dist/module1", [], function(require, exports, module) {
        var module1 = {};
        module1.say = function(word) {
            console.log(word);
        };
        module.exports = module1;
    });

    grunt-cmd-transport

    spmjs / grunt-cmd-transport
    https://github.com/spmjs/grunt-cmd-transport

    grunt-cmd-concat

    spmjs / grunt-cmd-concat
    https://github.com/spmjs/grunt-cmd-concat

    dynamic mappings

  • 相关阅读:
    377. Combination Sum IV
    字符串全排列,并去重。
    字符串全排列,并去重。
    智乐活,查找一片区域
    每日一题:华为初级题库——字符个数统计
    每日一题:华为初级题库——字符串替换
    总结菜鸟最近做题目的易错地方
    每日一题:华为初级题库——报数
    每日一题:华为初级题库——最大公约数
    每日一题:华为初级题库——图片整理
  • 原文地址:https://www.cnblogs.com/jzm17173/p/3460145.html
Copyright © 2011-2022 走看看