TypeScript编译速度极慢> 12S

时间:2016-05-04 23:52:32

标签: performance typescript angular webpack

只是把它放在那里看看是否有其他人遇到这个问题......

我使用webpack作为我的构建工具构建了一个带有typescript的角度2应用程序,它一切运行良好,但我注意到typescript编译超级超慢,我现在在12秒......,它的漂亮明确这完全是由于打字稿编译过程....

我使用ts-loader或awesome-typescript-loader得到了类似的结果,如果我注释掉这个加载器,我的构建时间会下降到1秒左右....

经过一些研究,在编写打字稿时看起来像'正常'是'慢'次,但正常情况下是12秒?

旧帖子暗示可能是由于节点版本冲突,我目前正在运行v4.4.2 ......

如果有人在那里发现错误,我的webpack代码如下:Uglify部分中的注释代码是由于角度2侧的某些“错误”......

const path = require('path');
const merge = require('webpack-merge');
const webpack = require('webpack');

const NpmInstallPlugin = require('npm-install-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const TARGET = process.env.npm_lifecycle_event;

const PATHS = {
  app: path.join(__dirname, 'app'),
  dist: path.join(__dirname, 'dist')
};

const common = {
  entry: {
    vendor: ['./app/vendor.ts'],
    main: ['./app/boot.component.ts']
  },
  output: {
    filename: '[name].[hash].bundle.js',
    path: PATHS.dist
  },
  resolve: {
    extensions: ['', '.js', '.ts']
  },
  plugins: [
    new HtmlWebpackPlugin({
      title: 'Qarrot Performance',
      template: 'index.template.ejs',
      commonStyles: [
        '/public/styles/vendor/normalize.css',
        '/public/styles/main.css'
      ],
      commonScripts: [],
      baseHref: '/',
      unsupportedBrowser: true,
      mobile: true,
      appMountId: 'app'
    }),
  ],
  module: {
    loaders: [
      {
        test: /\.ts$/,
        exclude: /node_modules/,
        loaders: ['ts-loader']
      },
      {
        test: /\.scss$/,
        loader: 'raw-loader!sass-loader'
      },
      {
        test: /\.html$/,
        loader: "html"
      }
    ]
  }
}

// Dev Settings
if(TARGET === 'start' || !TARGET) {
  module.exports = merge(common, {
    devtool: 'eval-source-map',
    devServer: {
      contentBase: PATHS.build,
      historyApiFallback: true,
      hot: true,
      inline: true,
      progress: true,
      stats: 'errors-only',
    },
    plugins: [
      new webpack.HotModuleReplacementPlugin(),
      new NpmInstallPlugin({
        save: true
      })
    ]
  });
}

// Prod Settings
if(TARGET === 'build') {
  module.exports = merge(common, {
    devtool: 'cheap-module-source-map',
    plugins: [
      // new webpack.optimize.UglifyJsPlugin({
      //   beautify: false,
      //   mangle: false,
      //   compress : { screw_ie8 : true },
      //   comments: false
      // }),
      new webpack.optimize.DedupePlugin(),
      new webpack.DefinePlugin({
        'process.env.NODE_ENV': '"production"'
      }),
      new CopyWebpackPlugin([
            { from: 'public', to: 'public' }
      ]),
      new webpack.optimize.CommonsChunkPlugin({
        names: ['vendor', 'manifest']
      }),
    ]
  });
}

我也在Mac上运行Angular 2 beta.15和webpack 1.12版,下面是我的tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  },
  "compileOnSave": false,
  "exclude": [
    "node_modules",
    "typings/main",
    "typings/main.d.ts"
  ]
}

2 个答案:

答案 0 :(得分:5)

我会坚持$affectedTR。它有一些您可以启用的性能选项:缓存选项和仅限转换选项:

awesome-typescript-loader

这两项都在编译时有了显着的改进。

答案 1 :(得分:0)

请与您分享tsconfig.json。很可能你将noEmitOnError设置为true,这意味着编译器强制在任何发射之前强制检查整个代码库

请将其设为false。