Webpack的第一次加载时间很慢

时间:2018-10-11 07:51:25

标签: angular visual-studio webpack asp.net-core-2.0

我是Webpack的新手,但遇到一个问题,即我的初始运行速度很慢。我正在使用Visual Studio。几天前已经花了我几天的时间将我的应用程序正确放置在正确的位置,所以我不想再重复一次,因此我想先在这里寻求帮助。

我不确定如何调试花费这么长时间准备的东西,或者为什么加载如此缓慢。

这是我的配置:

const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const AotPlugin = require('@ngtools/webpack').AotPlugin;
const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;
const ExtractTextPlugin = require("extract-text-webpack-plugin");

module.exports = (env) => {
    // Configuration in common to both client-side and server-side bundles
    const isDevBuild = !(env && env.prod);
    const sharedConfig = {
        mode: "development",
        stats: { modules: false },
        context: __dirname,
        resolve: { extensions: ['.js', '.ts'] },
        output: {
            filename: '[name].js',
            publicPath: '/dist/' // Webpack dev middleware, if enabled, handles requests for this URL prefix
        },
        module: {
            rules: [
                { test: /\.ts$/, use: isDevBuild ? ['awesome-typescript-loader?silent=true', 'angular2-template-loader', 'angular2-router-loader'] : '@ngtools/webpack' },
                { test: /\.html$/, use: 'html-loader?minimize=false' },
                { test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' },
                {
                    test: /\.(woff|woff2|svg|eot|ttf)$/,
                    use: {
                        loader: "file-loader",
                        options: {
                            name: "fonts/[name].[ext]"
                        }
                    }
                },
                { // regular css files
                    test: /\.css$/,
                    loader: ['to-string-loader'].concat(ExtractTextPlugin.extract({
                        fallback: "style-loader",
                        use: 'css-loader?importLoaders=1',
                    }))
                },
                { // sass / scss loader for webpack
                    test: /\.(sass|scss)$/,
                    loader: ['to-string-loader'].concat(ExtractTextPlugin.extract(['css-loader', 'sass-loader']))
                }
            ]
        },
        plugins: [
            new CheckerPlugin(),
            new ExtractTextPlugin({
                filename: "style.css"
            })
        ]
    };

    // Configuration for client-side bundle suitable for running in browsers
    const clientBundleOutputDir = './wwwroot/dist';
    const clientBundleConfig = merge(sharedConfig, {
        entry: { 'main-client': './ClientApp/boot.browser.ts' },
        output: { path: path.join(__dirname, clientBundleOutputDir) },
        plugins: [
            new webpack.DllReferencePlugin({
                context: __dirname,
                manifest: require('./wwwroot/dist/vendor-manifest.json')
            }
            )
        ].concat(isDevBuild ? [
            // Plugins that apply in development builds only
            new webpack.SourceMapDevToolPlugin({
                filename: '[file].map', // Remove this line if you prefer inline source maps
                moduleFilenameTemplate: path.relative(clientBundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk
            })
        ] : [
                // Plugins that apply in production builds only
                new webpack.optimize.UglifyJsPlugin(),
                new AotPlugin({
                    tsConfigPath: './tsconfig.json',
                    entryModule: path.join(__dirname, 'ClientApp/app/app.browser.module#AppModule'),
                    exclude: ['./**/*.server.ts']
                })
            ])
    });

    // Configuration for server-side (prerendering) bundle suitable for running in Node
    const serverBundleConfig = merge(sharedConfig, {
        resolve: { mainFields: ['main'] },
        entry: { 'main-server': './ClientApp/boot.server.ts' },
        module: {
            rules: [
            ]
        },
        plugins: [
            new webpack.DllReferencePlugin({
                context: __dirname,
                manifest: require('./ClientApp/dist/vendor-manifest.json'),
                sourceType: 'commonjs2',
                name: './vendor'
            })
        ].concat(isDevBuild ? [] : [
            // Plugins that apply in production builds only
            new AotPlugin({
                tsConfigPath: './tsconfig.json',
                entryModule: path.join(__dirname, 'ClientApp/app/app.server.module#AppModule'),
                exclude: ['./**/*.browser.ts']
            })
        ]),
        output: {
            libraryTarget: 'commonjs',
            path: path.join(__dirname, './ClientApp/dist')
        },
        target: 'node',


  devtool: 'inline-source-map'
});

return [clientBundleConfig, serverBundleConfig];

};

这是package.json:

"@angular/animations": "5.2.11",
    "@angular/common": "5.2.11",
    "@angular/compiler": "5.2.11",
    "@angular/compiler-cli": "5.2.11",
    "@angular/core": "5.2.11",
    "@angular/forms": "5.2.11",
    "@angular/http": "5.2.11",
    "@angular/platform-browser": "5.2.11",
    "@angular/platform-browser-dynamic": "5.2.11",
    "@angular/platform-server": "5.2.11",
    "@angular/router": "5.2.11",
    "@ng-bootstrap/ng-bootstrap": "1.1.2",
    "@ngtools/webpack": "6.1.2",
    "@types/chai": "4.0.1",
    "@types/jasmine": "2.5.53",
    "@types/webpack-env": "1.13.0",
    "ajv": "^6.0.0",
    "angular2-multiselect-dropdown": "2.9.0",
    "angular2-notifications": "1.0.2",
    "angular2-router-loader": "0.3.5",
    "angular2-template-loader": "0.6.2",
    "angular2-text-mask": "^8.0.4",
    "angular-tree-component": "^7.0.1",
    "aspnet-prerendering": "^3.0.1",
    "aspnet-webpack": "3.0.0",
    "awesome-typescript-loader": "3.2.1",
    "bootstrap": "4.1.3",
    "css": "^2.2.3",
    "css-loader": "0.28.4",
    "echarts": "^3.7.1",
    "es6-shim": "0.35.3",
    "event-source-polyfill": "0.0.9",
    "expose-loader": "0.7.3",
    "extract-text-webpack-plugin": "4.0.0-beta.0",
    "file-loader": "1.1.11",
    "font-awesome": "^4.7.0",
    "html-loader": "0.4.5",
    "chai": "4.0.2",
    "isomorphic-fetch": "2.2.1",
    "jasmine-core": "2.6.4",
    "jquery": "3.2.1",
    "json-loader": "0.5.4",
    "karma": "1.7.0",
    "karma-cli": "1.0.1",
    "karma-chai": "0.1.0",
    "karma-chrome-launcher": "2.2.0",
    "karma-jasmine": "1.1.0",
    "karma-webpack": "3.0.0",
    "material-design-icons": "^3.0.1",
    "ngx-perfect-scrollbar": "5.3.5",
    "node-sass": "4.9.2",
    "popper.js": "1.14.3",
    "preboot": "4.5.2",
    "raw-loader": "0.5.1",
    "reflect-metadata": "0.1.10",
    "rxjs": "5.5.11",
    "sass-loader": "7.1.0",
    "simple-line-icons": "^2.4.1",
    "style-loader": "0.18.2",
    "text-mask-addons": "3.8.0",
    "to-string-loader": "1.1.5",
    "typescript": "2.6.2",
    "url-loader": "1.0.1",
    "webpack": "4.16.3",
    "webpack-dev-middleware": "3.1.3",
    "webpack-hot-middleware": "2.22.3",
    "webpack-merge": "4.1.4",
    "zone.js": "0.8.12"

非常感谢! 尼古拉

0 个答案:

没有答案