无法自举角度2 - 没有错误的cosole

时间:2016-03-28 08:20:17

标签: typescript gulp angular transpiler

我正在使用gulp将ts转换为js,我的ts文件在dist文件夹中与其他静态资源一起正确生成。

//tsconfig.js

    {
      "compilerOptions": {
        "outFile": "scripts.js",  //this can be commented to retain the original file structure instead of concatenating into one file
        "target": "es5",
        "module": "system",
        "moduleResolution": "node",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "removeComments": false,
        "noImplicitAny": false
      },
      "exclude": [
        "gulpfile.js",
        "node_modules",
        "typings/main",
        "typings/main.d.ts"
      ]
    }

我使用systemjs导入scripts.js

//index.html

        <!DOCTYPE html>
        <html>
        <head>
            <base href="/">
            <meta charset="UTF-8">
            <title>ZEFR</title>

            <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,300,300italic,700,600,700italic,400italic,600italic,800,800italic' rel='stylesheet' type='text/css'>

            <link rel="stylesheet" type="text/css" href="style.css">
        </head>
        <body>
            <my-app>Loading</my-app>
        </body>
        <script src="lib/es6-shim.js"></script>
        <script src="lib/angular2-polyfills.js"></script>
        <script src="lib/system.src.js"></script>
        <script src="lib/Rx.js"></script>
        <script src="lib/angular2.dev.js"></script>
        <script src="lib/router.dev.js"></script>

        <script>
        System.config({
            packages: {
                dist: {
                    format: 'register',
                    defaultExtention: 'js'
                }
            }
        });
        System.import('scripts.js')
                .then(null, console.error.bind(console))
    </script>
    </html>

script.js是我的串联javascript文件,包含我的所有组件。问题是我在控制台上没有任何错误。 我有一种感觉,我需要针对boot.js而不是script.js。我怎么能在我的dist文件夹中这样做

//my project folder structure

    -public/
      -index.html
      -components/
        -boot/
          -boot.ts
        -app/
           -app.component.ts
         ...
      -dist/
         -scripts.js  //this is the concatenated file of all the js transpiled from ts
         -style.css
         -images/
         -lib/

1 个答案:

答案 0 :(得分:0)

这可以帮到你:

 System.import('dist/scripts')
            .then(null, console.error.bind(console))

您的scripts.js处于dist状态,而您的索引位于父目录中。而且你不需要在那里添加---.js