【问题标题】:Path wildcards not working with system.js路径通配符不适用于 system.js
【发布时间】:2016-01-13 14:51:17
【问题描述】:

根据system.js documentation,应该可以用wildcards为system.js配置paths。但是,我一直无法让它工作。我有一个带有茉莉花单元测试的 specRunner,我按照angular2 testing tutorial 插入了一个脚本部分,以便显示规范。但是,当我想导入 *.spec.js 以引入所有测试时,这需要我手动导入 每个规范。这是我的 SpecRunner.html,显示了哪些代码有效,哪些无效。

<script>
    // Configure systemjs to use the .js extension for imports from the src/js folder
    System.config({
        packages: {
            'src/js': {defaultExtension: 'js'}
        }
    });

    // Import spec files: Does NOT work
    System.paths['specs'] = 'src/js/*.spec';
    Promise.all([
        System.import('specs')
    ])

    // Import spec files: Does work
    System.paths['specs'] = 'src/js/greeter.spec';
    Promise.all([
        System.import('specs'),
    ])

    // Import spec files: Does work
    Promise.all([
        System.import('src/js/greeter.spec')
    ])
</script>

谁能告诉我是否可以使用通配符为 system.js 配置路径?

【问题讨论】:

    标签: javascript jasmine angular systemjs


    【解决方案1】:

    路径的键和值都应包含通配符。 SystemJS 需要知道你在映射什么。

    ...
    // Should work like this
    System.paths['specs/*'] = 'src/js/*.spec';
    Promise.all([
        System.import('specs/greeter')
    ])
    
    //Here, you're essentially aliasing
    System.paths['specs'] = 'src/js/greeter.spec';
    Promise.all([
        System.import('specs');
        // above is equivalent to:
        System.import('src/js/greeter.spec'),
    ])
    

    【讨论】:

      猜你喜欢
      • 2018-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-29
      • 2011-07-12
      • 2023-03-19
      • 2019-10-13
      • 1970-01-01
      相关资源
      最近更新 更多