WordPress.org

Ideas

RequireJS

  1. Stephan Vierkant
    Member

    12345
  2. ByronicEntity
    Member

    wp_enqueue_script('requirejs', '//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.15/require.min.js');
    $app_base = get_template_directory_uri() . '/scripts';
    wp_localize_script( 'requirejs', 'require', array(
        'baseUrl' => $app_base,
        'deps'    => array( $app_base . '/main.js')
    ));

    Add a requirejs.config({}) inside main.js. If you would like to use the baseUrl like I did in the code example you can use

    requirejs.config({
         baseUrl: requirejs.toUrl('');
    });

    Granted this isn't as simple as data-main="scripts/main.js" but it essentially does the same thing.

    Posted: 3 years ago #
  3. tylercollier
    Member

    Thanks @ByronicEntity. I didn't read the links from Stephan Vierkant, but this was pretty easy.

    Posted: 2 years ago #

RSS feed for this topic

Reply

You must log in to post.

  • Rating

    12345
    9 Votes
  • Status

    This idea is under consideration