Dojo 1.10自定义构建输出目录位置错误

时间:2018-02-13 21:41:25

标签: javascript dojo

我正在尝试实现以下所示的一般示例: https://dojotoolkit.org/documentation/tutorials/1.10/modules_advanced/

我的目录结构与"默认"不匹配。

/
    index.html
    js/
        lib/
            dojo/
            dijit/
            dojox/
        my/

当我对开发目录运行时,一切都很好!在运行时使用此配置:

<script>
            var dojoConfig = {
                baseUrl: "/lib/_site/js/",
                tlmSiblingsofDojo: false,
                async: 1,
                hasCache: {
                    // these are the values given above, not-built client code may test for these so they need to be available
                    "dojo-built": 1,
                    "dojo-loader": 1,
                    "dojo-undef-api": 0,
                    dom: 1,
                    "host-browser": 1,

                    // Disable deferred instrumentation by default in the built version.
                    "config-deferredInstrumentation": 0,

                    // Dojo loader has built-in "has" api. Since dojoConfig is used
                    // by Dojo loader, we can set the default here.
                    "dojo-has-api": 1,

                    // default
                    "config-selectorEngine": "lite",

                    "esri-featurelayer-webgl": 0,

                    "esri-promise-compatibility": 0,
                    "esri-promise-compatibility-deprecation-warnings": 1
                },
                packages: [
                    {
                        name: "dojo",
                        location: "lib/dojo"
                    },
                    {
                        name: "dijit",
                        location: "lib/dijit"
                    },
                    {
                        name: "dojox",
                        location: "lib/dojox"
                    },
                    {
                        name: "dstore",
                        location: "lib/dstore"
                    },
                    {
                        name: "dgrid",
                        location: "lib/dgrid"
                    },
                    {
                        name: "esri",
                        location: "lib/esri"
                    },
                    {
                        name: "moment",
                        location: "lib/moment",
                        main: "moment"
                    },
                    {
                        name: "my",
                        location: "my",
                        main: "app"
                    }
                ]
            };

        </script>
        <script src="~/lib/_site/dist/js/lib/dojo/dojo.js"></script>

Dojo正确定位&#34;我的&#34;和其他&#34; libs&#34;。但是如果我尝试为生产做一个优化的自定义构建,除了&#34; my&#34;之外,一切都是一样的。目录被复制到&#34; lib&#34;目录,但dojo仍在寻找它应该在哪里?

输出目录如下所示:

/
        index.html
        js/
            lib/
                dojo/
                dijit/
                dojox/
                my/

我正在使用此配置文件来构建优化的包..

*
 * Based on the dojo-boilerplate
 * https://github.com/csnover/dojo-boilerplate
 * and https://github.com/tomwayson/esri-slurp-example
 *
 * Please refer to the Dojo Build tutorial for more details
 * http://dojotoolkit.org/documentation/tutorials/1.10/build/
 * Look to `util/build/buildControlDefault.js` for more information on available options and their default values.
 */

var profile = {
    optimizeOptions: {
        languageIn: "ECMASCRIPT6",
        languageOut: "ECMASCRIPT5"
    },

    // `basePath` is relative to the directory containing this profile file; in this case, it is being set to the
    // src/ directory, which is the same place as the `baseUrl` directory in the loader configuration.
    basePath: "./js/",
    tlmSiblings:false,
    action: "release",
    optimize: "closure", // requires Java 6 or later: http://code.google.com/p/closure-compiler/wiki/FAQ
    layerOptimize: "closure",
    useSourceMaps: false,
    cssOptimize: "comments",
    copyTests: false,
    internStrings: true,
    mini: true,

    // The default selector engine is not included by default in a dojo.js build in order to make mobile builds
    // smaller. We add it back here to avoid that extra HTTP request. There is also an "acme" selector available; if
    // you use that, you will need to set the `selectorEngine` property in index.html, too.
    selectorEngine: "lite",
    // Strips all calls to console functions within the code. You can also set this to "warn" to strip everything
    // but console.error, and any other truthy value to strip everything but console.warn and console.error.
    // This defaults to "normal" (strip all but warn and error) if not provided.
    stripConsole: "none",

    // dojoBootText: "require.boot && require.apply(null, require.boot);",
    insertAbsMids: 0,
    // If present and truthy, instructs the loader to consume the cache of layer member modules
    noref: true,

    // A list of packages that will be built. The same packages defined in the loader should be defined here in the
    // build profile.
    packages: [
        // "app" is a sample path for your application
        // set this accordingly
        {
            name: "my",
            location: "my"
        },
        {
            name: "dojo",
            location: "lib/dojo"
        },
        {
            name: "dijit",
            location: "lib/dijit"
        },
        {
            name: "dojox",
            location: "lib/dojox"
        },
        {
            name: "dstore",
            location: "lib/dstore"
        },
        {
            name: "dgrid",
            location: "lib/dgrid"
        },
        {
            name: "esri",
            location: "lib/esri"
        },
        {
            name: "moment",
            location: "lib/moment",
            main: "moment",
            trees: [
                // don"t bother with .hidden, tests, min, src, and templates
                [".", ".", /(\/\.)|(~$)|(test|txt|src|min|templates)/]
            ],
            resourceTags: {
                amd: function (filename, mid) {
                    return /\.js$/.test(filename);
                }
            }
        }

    ],

    // Any module in an application can be converted into a "layer" module, which consists of the original module +
    // additional dependencies built into the same file. Using layers allows applications to reduce the number of HTTP
    // requests by combining all JavaScript into a single file.
    layers: {
        // This is the main loader module. It is a little special because it is treated like an AMD module even though
        // it is actually just plain JavaScript. There is some extra magic in the build system specifically for this
        // module ID.
        "dojo/dojo": {
            // By default, the build system will try to include `dojo/main` in the built `dojo/dojo` layer, which adds
            // a bunch of stuff we do not want or need. We want the initial script load to be as small and quick to
            // load as possible, so we configure it as a custom, bootable base.
            boot: true,
            customBase: true,
            include: [
                "dojo/domReady",

                /** enforce some modules loading */
                /** not included because dom is -1 */
                "dojo/_base/browser",
                "esri/core/request/script",

                // esri stuff for 3D maps
                "esri/portal/support/layersCreator",
                "esri/views/3d/layers/VectorTileLayerView3D"
            ]
            // You can define the locale for your application if you like
            // includeLocales: ["en-us"]
        },
        "esri/identity/IdentityManager": {
            include: [
                "esri/identity/IdentityManager"
            ]
        },
        "esri/views/MapView": {
            include: [
                "esri/views/MapView",
                "esri/views/2d/layers/GraphicsLayerView2D",
                "esri/views/2d/layers/FeatureLayerView2D",
                "esri/views/2d/layers/TiledLayerView2D"
            ],
            exclude: [
                "esri/widgets/support/widget"
            ]
        },
        "esri/views/SceneView": {
            include: [
                "esri/views/SceneView",
                "esri/layers/graphics/controllers/I3SOnDemandController",
                "esri/layers/SceneLayer",
                "esri/views/3d/layers/ElevationLayerView3D",
                "esri/views/3d/layers/FeatureLayerView3D",
                "esri/views/3d/layers/SceneLayerView3D",
                "esri/views/3d/layers/TiledLayerView3D"
            ],
            exclude: [
                "esri/widgets/support/widget"
            ]
        },
        "esri/WebMap": {
            include: [
                "esri/WebMap"
            ]
        },
        "esri/WebScene": {
            include: [
                "esri/WebScene"
            ]
        },
        "esri/layers/VectorTileLayer": {
            include: [
                "esri/layers/VectorTileLayer"
            ]
        },
        "esri/views/2d/layers/VectorTileLayerView2D": {
            include: [
                "esri/views/2d/layers/VectorTileLayerView2D"
            ],
            exclude: ["esri/views/MapView"]
        },
        "esri/views/2d/layers/support/FeatureLayerView2DWebGL": {
            include: [
                "esri/views/2d/layers/support/FeatureLayerView2DWebGL"
            ],
            exclude: ["esri/views/MapView"]
        },
        "esri/core/workers/WorkerConnection": {
            include: [
                "esri/core/workers/WorkerConnection"
            ]
        },
        "esri/views/vectorTiles/WorkerTileHandler": {
            include: [
                "esri/views/vectorTiles/WorkerTileHandler"
            ]
        },
        "esri/widgets/support/widget": {
            include: [
                "esri/widgets/support/widget"
            ]
        }
    }

我无法弄明白为什么!我尝试了十几种变体。我没有试图复制&#34;我的&#34;目录回到正确的位置,因为我不应该!如果我无法弄清楚并且手动复制确实有效,我将在dojo构建过程中添加一个副本。 BTW-使用NPM和grunt。

有什么想法吗?非常感谢您的时间和专业知识!!

干杯!

BTW-使用NPM和咕噜声。 编辑:以下是用于运行自定义构建的咕噜声。

  

关于自定义构建的快速说明。我试图&#34;烘烤&#34;默认   通过在构建中定义&#34; defaultConfig来构建构建   简介,因为它似乎没有工作。所以我硬连线了   dojoConfig如上图所示。请参阅应用程序构建配置文   部分:   https://dojotoolkit.org/documentation/tutorials/1.10/build/index.html

所以我的grunt文件的内容很重要:

module.exports = function (grunt) {
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        clean: {
            options: {
                force: true
            },
            any: {
                src: ''
            }
        },
        dojo: {
            dist: {
                options: {
                    releaseDir: '../dist/js/lib',
                }
            },
            options: {
                profile: 'site.profile.js',
                dojo: './js/lib/dojo/dojo.js',
                load: 'build',
                cwd: './',
                basePath: './js/'
            }
        }
    });

    require('load-grunt-tasks')(grunt, { scope: 'devDependencies' });
    require('time-grunt')(grunt);
    grunt.registerTask('none', function () { });
    grunt.registerTask('default', 'dist');

    grunt.registerTask('my-dojo', function () {
        grunt.config('clean.any.src', ['./dist/js/lib']);
        grunt.task.run('clean:any');
        grunt.task.run('dojo');
        grunt.config('clean.any.src', ['./dist/js/lib/**/*.uncompressed.js']);
        grunt.task.run('clean:any');
    });
};

如上所述,它将所有内容复制到releaseDir,包括&#34; my&#34;,它应该以./dist/js结尾。

0 个答案:

没有答案