Is it possible to stop requireJS from adding the .js file extension automatically?

前端 未结 3 1119
梦谈多话
梦谈多话 2020-12-02 11:53

I\'m using requireJS to load scripts. It has this detail in the docs:

The path that is used for a module name should not include the .js extension,

3条回答
  •  萌比男神i
    2020-12-02 12:54

    requirejs' noext plugin:

    Load scripts without appending ".js" extension, useful for dynamic scripts...

    Documentation

    check the examples folder. All the info you probably need will be inside comments or on the example code itself.

    Basic usage

    Put the plugins inside the baseUrl folder (usually same folder as the main.js file) or create an alias to the plugin location:

    require.config({
        paths : {
            //create alias to plugins (not needed if plugins are on the baseUrl)
            async: 'lib/require/async',
            font: 'lib/require/font',
            goog: 'lib/require/goog',
            image: 'lib/require/image',
            json: 'lib/require/json',
            noext: 'lib/require/noext',
            mdown: 'lib/require/mdown',
            propertyParser : 'lib/require/propertyParser',
            markdownConverter : 'lib/Markdown.Converter'
        }
    });
    
    //use plugins as if they were at baseUrl
    define([
            'image!awsum.jpg',
            'json!data/foo.json',
            'noext!js/bar.php',
            'mdown!data/lorem_ipsum.md',
            'async!http://maps.google.com/maps/api/js?sensor=false',
            'goog!visualization,1,packages:[corechart,geochart]',
            'goog!search,1',
            'font!google,families:[Tangerine,Cantarell]'
        ], function(awsum, foo, bar, loremIpsum){
            //all dependencies are loaded (including gmaps and other google apis)
        }
    );
    

提交回复
热议问题