2016-05-04 32 views
7

只是把這個在那裏,看看別人是有這個問題...打字稿編譯速度極慢> 12S

我已經建立一個角2應用程序使用的WebPack作爲我的生成工具打字稿,這一切運作良好,但我已經注意到打字稿編譯超級超級慢,我現在在12秒......,並且其相當清楚,這都是由於打字稿編譯過程造成的......

我已經使用ts-裝載機或awesome-typescript-loader有類似的結果,如果我註釋掉這個裝載機,我的編譯時間會下降到1秒左右....

之後研究它似乎是'正常'編譯打字稿時'慢',但是12secs是正常的?

舊文章暗示這可能是由於節點版本衝突,我目前正在運行v4.4.2 ...

任何情況下,任何人我的WebPack代碼是如何察覺以下一些錯誤有..註釋的代碼在醜化部分是由於對角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上運行角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" 
    ] 
} 

回答

-1

請分享給你tsconfig.json。很有可能你有noEmitOnError設置爲true,這意味着編譯器是被迫在任何發射之前檢查整個代碼庫

請將其設置爲false。

+0

嘿@basart感謝您的建議,我用我的tsconfig更新了我的問題......我沒有設置該選項,但是當我添加它時沒有太大的影響...... –

2

我會堅持awesome-typescript-loader。它有一些性能選項,你可以啓用:緩存選項,只有transpile選項:

"awesomeTypescriptLoaderOptions": { 
    "useCache": true, 
    "transpileOnly": true 
} 

這兩對編譯次顯著的改善。