Angular 2 webpack缓慢初始加载

时间:2017-03-02 10:51:44

标签: angular

我正在使用webpack处理Angular 2。开发和生产的最初缓慢有点慢。对于Firefox,它需要将近4秒。在我的索引文件中,我只调用bootstrap。

Firefox example

这是我的webpack.congif.js

var path = require('path');
var webpack = require('webpack');

const HtmlWebpackPlugin = require('html-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');

function root(args) {
    args = Array.prototype.slice.call(arguments, 0);
    return path.join.apply(path, [__dirname].concat(args));
}

module.exports = {
    resolve: {
        extensions: ['.ts', '.js', '.html',  '.css']
    },

loaders:[ExtractTextPlugin.extract('style', 'css-loader'), 'to-string', 'css']

    devtool: 'cheap-module-source-map',

    module: {
        rules: [{
            test: /\.js$/,
            loader: 'source-map',
            enforce: 'pre'
        }, {
            test: /\.ts$/,
            loader: 'awesome-typescript-loader',
            exclude: /(node_modules)/
        }]
    },

    entry: {+
        'app': './src/main.ts'
    },

    devServer: {
        outputPath: root('dist'),
        watchOptions: {
            poll: true
        },
        stats: {
            modules: false,
            cached: false,
            colors: true,
            chunks: false
        }
    },

    output: {
        path: root('dist'),
        filename: '[name].[hash].js',
        sourceMapFilename: '[name].[hash].map',
        chunkFilename: '[id].[hash].chunk.js'
    },

    plugins: [
        // fix the warning in ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js
        new webpack.ContextReplacementPlugin(
            /angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
            root('./src')
        ),

        new HtmlWebpackPlugin({
            template: 'index.html',
            chunksSortMode: 'dependency'
        }),
        new CopyWebpackPlugin([
            { from: 'i18n/', to: 'i18n' }
        ]),

        new webpack.optimize.OccurrenceOrderPlugin(true)
    ]
};

任何想法如何加快它将是非常有帮助的

0 个答案:

没有答案