简体   繁体   English

路径通配符不适用于system.js

[英]Path wildcards not working with system.js

According to the system.js documentation , it should be possible to configure paths for system.js with wildcards . 根据system.js 文档 ,应该可以使用通配符为system.js配置路径 However, I have been unable to get this to work. 但是,我无法使它正常工作。 I have a specRunner with jasmine unit tests, and I followed the angular2 testing tutorial to insert a script section so that specs show up. 我有一个带有茉莉花单元测试的specRunner ,并且我按照angular2测试教程插入了脚本部分,以便显示规范。 However, this requires me to manually import each and every spec , when I would like to import *.spec.js to bring in all the tests. 但是,这需要我手动导入每个规范 ,当我想导入* .spec.js进行所有测试时。 Here is my SpecRunner.html showing which code works and which does not. 这是我的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>

Can anyone tell me if it is possible to configure a path for system.js using wildcards ? 谁能告诉我是否可以使用通配符为system.js配置路径?

Paths should contain wildcard in both key and value. 路径应在键和值中都包含通配符。 SystemJS needs to know, what you're mapping. 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'),
])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM