Separate Angular2 TypeScript files and JavaScript files into different folders, maybe 'dist‘

后端 未结 16 2270
清酒与你
清酒与你 2020-11-28 19:52

I am using the 5 min quickstart from angular.io website, which contain a file structure like this:

angular2-quickstart
 app
   app.component.ts
   boot.ts
 i         


        
16条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-28 20:13

    Adding on top of what raheel shan said. I had to make additional change in index.html to reflect to import correct javascript file now.

    Here is summary from my side.

    tsconfig.json

    Before

    {
      "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "moduleResolution": "node",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "lib": [ "es2015", "dom" ],
        "noImplicitAny": true,
        "suppressImplicitAnyIndexErrors": true
      }
    }
    

    After:

    {
      "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "moduleResolution": "node",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "lib": [ "es2015", "dom" ],
        "noImplicitAny": true,
        "suppressImplicitAnyIndexErrors": true,
        "outDir": "dist"
      },
      "exclude": [ 
        "node_modules",
        "typings/main",
        "typings/main.d.ts"
      ]
    }
    

    systemjs.config.js

    Before:

    'app': 'app',
    

    After:

    'app': 'dist/app', //'app
    

    index.html

    Before:

    System.import('main.js').catch(function(err){ console.error(err); });
    

    After:

    System.import('dist/main.js').catch(function(err){ console.error(err); });
    

提交回复
热议问题