如何使用"杏仁"在" RequireJS"生成一个文件?

时间:2015-03-12 08:49:41

标签: javascript requirejs almond

我有一个RequireJS项目。

我的app.build with require:

({
    appDir: './',
    baseUrl: "js",
    dir: "dist",
    mainConfigFile: "js/main.js",
    modules: [ { name: 'main' } ],
    optimizeCss: 'standard',
    removeCombined: true,
    preserveLicenseComments: false,
    optimize: "uglify",
    uglify: {
        max_line_length: 1000,
        compress: {
            cascade: true,
            drop_console: true,
            keep_fargs: true
        },
        defines: {
            DEBUG: ['name', 'false']
        },
        no_mangle: true
    },
    closure: {
        CompilerOptions: {},
        CompilationLevel: 'SIMPLE_OPTIMIZATIONS',
        loggingLevel: 'WARNING'
    }
})

编译后我有三个js文件 - require.js,main.js,domReady.js 我尝试通过Almond获取单个文件,我添加了一些参数:

({
            appDir: './',
            baseUrl: "js",
            modules: [
                {
                    name: '../lib/almond/almond'
                },
                {
                    name: 'main'
                }
            ],
            include: ['main'],
            insertRequire: ['main'],
            wrap: true,
            dir: "dist",
            mainConfigFile: "js/main.js",
            optimizeCss: 'standard',
            removeCombined: true,
            preserveLicenseComments: false,
            optimize: "uglify",
            uglify: {
                ...
            },
            closure: {
                ...
            }
})

但最后我还有三个档案...... 提前谢谢!

1 个答案:

答案 0 :(得分:1)

解决方案是:

({
    appDir: './',
    baseUrl: "js",
    dir: "dist",
    mainConfigFile: "js/main.js",
    findNestedDependencies: true,
    name: 'main',
    include: ['../lib/almond/almond'],
    insertRequire: ['main'],
    optimizeCss: 'standard',
    removeCombined: true,
    preserveLicenseComments: false,
    optimize: "uglify",
    uglify: {
...
    },
    closure: {
...
    }
})

编译后我有一个文件... 然后通过GULP我在index.html中更改代码

<script src="lib/requirejs/require.js" data-main="js/main.js"></script>

<script src="js/main.js"></script>