Skip to content

Add sourcemap path to dynamic file selection #432

Open
@mikicof

Description

Hi all,

Currently our project has multiple js files in multiple folders, so we are using dynamic file selection in our uglify process and sourcemaps creation for debugging.

Our uglify task is the following:

uglify: {
    build: {
        options: {
            sourceMap: true,
            sourceMapIncludeSources: true,
            compress: {
                sequences: true,
                dead_code: true,
                conditionals: true,
                booleans: true,
                unused: true,
                if_return: true,
                join_vars: true,
                drop_console: true
            }
        },
        files: [{
            expand: true,
            src: ['path/to/js/**/*.js'],
            cwd: '.tmp',
            dest: '.tmp'
        }, {
            expand: true,
            src: ['path/to/other/js/**/*.js'],
            cwd: '.tmp',
            dest: '.tmp'
        }]
    }
}

When we load the js along the page (using the common script tag at the header), the sourcemaps works properly, but when we load them by ajax it gives an 404 error.
That is because the sourceMappingURL of the js files are relative to the minified files and not the full path from root, so when the file is ajax loaded, it tries to load them from the document url which is wrong.

I think the best way to overcome this error is specifying the full path in the sourcemaps, but as the files are selected dynamically we cannot specify the path of any of them using sourcemaproot, and it isn't any method to specify it dynamically.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions