1

我正在使用 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/
4

1 回答 1

0

这应该可以帮助您:

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

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

于 2016-03-28T08:22:38.177 回答