2

我有一个 RequireJS 项目。

我的 app.build 需要:

({
    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: {
                ...
            }
})

但最后我仍然有三个文件......提前谢谢!

4

1 回答 1

1

The solution is:

({
    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: {
...
    }
})

after compile I have a single file... Then via GULP I change code in my index.html

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

to

<script src="js/main.js"></script>
于 2015-03-12T14:17:07.773 回答