System.js不会在wordpress上导入供应商

时间:2016-02-06 14:34:45

标签: javascript wordpress angular systemjs

我正在尝试在wordpress上重新创建Angular2 Quickstart tutorial,但我遇到了SystemJs导入的问题。 尝试从Angular2导入会导致此错误:

GET http://localhost/wp-content/themes/ng2-wordpress/angular2/core 404 (Not Found)

我不明白它为什么要寻找物理路径,而不是SystemJs模块。

这是我的SystemJs脚本:

app/system-start.js

System.config({
    baseURL: baseUrl,
    packages: {
        app: {
            main: 'main',
            format: 'register',
            defaultExtension: 'js'
        }
    }
});

System.import('app')
    .then(null, console.error.bind(console));

app/main.ts(当然是编译的):

import {bootstrap}    from 'angular2/platform/browser'
import {AppComponent} from './app.component'

bootstrap(AppComponent);

我正在把这些东西放到html标题中:

functions.php

function enqueue_script() {
    function register_vendor_script($script, $path) {
        wp_register_script($script, get_stylesheet_directory_uri().'/node_modules/'.$path);
    }

    register_vendor_script('es6-shim', 'es6-shim/es6-shim.min.js');
    register_vendor_script('system-polyfills', 'systemjs/dist/system-polyfills.js');
    register_vendor_script('angular2-polyfills', 'angular2/bundles/angular2-polyfills.js');

    register_vendor_script('system', 'systemjs/dist/system.src.js');
    register_vendor_script('Rx', 'rxjs/bundles/Rx.js');
    register_vendor_script('angular2', 'angular2/bundles/angular2.dev.js');

    wp_enqueue_script('system-start',
        get_stylesheet_directory_uri().'/app/system-start.js',
        array('es6-shim', 'system-polyfills', 'angular2-polyfills', 'system', 'Rx', 'angular2')
    );
    wp_localize_script(
        'system-start',
        'baseUrl',
        trailingslashit(get_template_directory_uri())
    );
}
add_action('wp_enqueue_scripts', 'enqueue_script');

0 个答案:

没有答案