0

Using Durandal's optimization companion Weyland, we can combine all .js and .html files into main-built.js and skip RequireJS by using Almond. We do this as described in the docs: http://durandaljs.com/documentation/Weyland.html and
http://durandaljs.com/documentation/Automating-Builds-with-Visual-Studio.html
(Yes it is an ASP.NET MVC project)

However we are seeing main-built.js growing larger and larger.

What are the considerations for Weyland? Can we approach this differently? Should we approach this differently? If our project grows, so does the main-built file. Startup load will then increase and maybe not all users need download the entire project (security wise users are cut of from different areas).

Hope someone can shed some light on this?

Current Weyland config:

exports.config = function (weyland) {
    weyland.build('main')
        .task.jshint({
            include: 'App/**/*.js'
        })
        .task.uglifyjs({
            include: ['App/**/*.js', 'Scripts/durandal/**/*.js']
        })
        .task.rjs({
            include: ['App/**/*.{js,html}', 'Scripts/durandal/**/*.js'],
            loaderPluginExtensionMaps: {
                '.html': 'text'
            },
            rjs: {
                name: '../Scripts/almond-custom.min', //to deploy with require.js, use the build's name here instead
                insertRequire: ['main'], //not needed for require
                baseUrl: 'App',
                wrap: true, //not needed for require
                paths: {
                    'text': '../Scripts/text',
                    'durandal': '../Scripts/durandal',
                    'plugins': '../Scripts/durandal/plugins',
                    'transitions': '../Scripts/durandal/transitions',
                    'knockout': 'empty:',
                    'bootstrap': 'empty:',
                    'jquery': 'empty:',
                    'i18next': '../Scripts/i18next.amd.withJQuery-1.7.2.min'
                },
                inlineText: true,
                //optimize: 'uglify2',
                optimize: 'none',
                pragmas: {
                    build: true
                },
                stubModules: ['text'],
                keepBuildDir: true,
                out: 'App/main-built.js'
            }
        });
}
clausndk
  • 3,129
  • 2
  • 18
  • 14

1 Answers1

0

I do not know if this helps in your case but apparently it helped in my case do delete the main-built.js file before the weyland build process. You should also make sure that your js files in the App directory do not include minified (uglyfied) JS code since re-minification makes files slightly larger.

However... Weyland is now considered outdated method of building Durandal apps: see this link for that.

I was dealing with the issue that running the Weyland build was starting to take forever. The reason for that was apparently that uglifying the main-built.js file took looong time.
This of course is the file that should not be uglyfied in the first place.

So the solution to this problem is to exclude the main-build.js file from the uglyfication process or... just delete it before you run the build.

I could not find a quick way to format the uglify config to exclude the file so I modified my execution command to delete the file before build:

cd %1
del /Q "App\\main-built.js" 
weyland build
Svakinn
  • 687
  • 10
  • 15