Migrating from weyland.js to grunt.js

98 views Asked by At

I have a legacy asp.net + durandal.js app that is using weyland as a build optimizer. We are trying to upgrade to grunt to use something newer, but I can't get it to generate minified js build file correctly. I have the following weyland-config file:

exports.config = function(weyland) {
    weyland.build('main')
        .task.jshint({
            include:'App/**/*.js'
        })
        .task.uglifyjs({
            include: ['App/**/*.js', 'Scripts/durandal/**/*.js'],
            exclude: ['App/main-built.js']
        })
        .task.rjs({
            include:['App/**/*.{js,html}', 'Scripts/durandal/**/*.js'],
            loaderPluginExtensionMaps:{
                '.html':'text'
            },
            rjs:{
                name:'../Scripts/almond-custom', 
                insertRequire:['main'], 
                baseUrl : 'App',
                wrap:true, 
                paths : {
                    'text': '../Scripts/text',
                    'durandal': '../Scripts/durandal',
                    'plugins': '../Scripts/durandal/plugins',
                    'transitions': '../Scripts/durandal/transitions',
                    'knockout': 'empty:',
                    'bootstrap': 'empty:',
                    'jquery': 'empty:'
                },
                inlineText: true,
                optimize : 'none',
                pragmas: {
                    build: true
                },
                stubModules : ['text'],
                keepBuildDir: true,
                out:'App/main-built.js'
            }
        });
}

I've been trying to create gruntfile according to this and this and this is what I have:

module.exports = function (grunt) {

    // Project configuration.
    grunt.initConfig({
        jshint: {
            include: 'App/**/*.js'
        },
        durandal: {
            main: {
                src: [
                    "App/**/*.*",
                    "Scripts/durandal/**/*.js"
                ],
                options: {
                    name: '../Scripts/almond-custom',
                    baseUrl: './App/',
                    mainPath: "App/main",
                    paths: {
                        'jquery': '../Scripts/jquery-3.6.0',
                        'text': '../Scripts/text',
                        'knockout': '../Scripts/knockout-3.4.1',
                        'durandal': '../Scripts/durandal',
                        'plugins': '../Scripts/durandal/plugins',
                        'transitions': '../Scripts/durandal/transitions',
                    },
                    exclude: [],
                    optimize: 'none',
                    out: "App/main.js"
                }
            }
        },
        uglify: {
            build: {
                src: 'App/main.js',
                dest: 'App/main-built.js'
            }
        }
    });

    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-requirejs');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks("grunt-durandal");

    // Default task(s).
    grunt.registerTask('default', ['durandal', 'uglify']);

};

But when I try to run grunt I get the following error:

 Error: TypeError: Cannot read property 'normalize' of undefined
>>     at Module.<anonymous> (APP_PATH\node_modules\requirejs\bin\r.js:1218:36)

If I try to only run uglify I get incorrectly minified file (by incorrectly I mean that the application throws errors when trying to use it). Does anybody know how to correctly port it over from weyland to grunt?

0

There are 0 answers