How to configure webpack to NOT recompile angular every time?

I recently started working on a simple HTML5 + angular2 canvas game for routing, displaying highscores, etc. Since I do not touch the core of angular2, I would like NOT to recompile everything and merge everything together into one large file. Much more I would prefer to have angular2 core + http + router, and my application is in separate files.

Now I get almost 5 MB-package and even more .map, which pause my computer for a while when loading in the browser (the mouse gets stuck, the music stops playing for an instant, half), which is very annoying (I think this is due to the size of the package). Can I use multiple entry points to get this working?

Here is my webpack configurator:

module.exports = {
  devtool: 'source-map',
  entry: './src/app/bootstrap',
  output: {
    path: __dirname + '/dist', publicPath: 'dist/', filename: 'bundle.js'
  },
  resolve: {
    extensions: ['', '.js', '.ts']
  },
  module: {
    loaders: [
      {
        test: /\.ts/, loaders: ['ts-loader'], exclude: /node_modules/
      }
    ]
  }
};

angular 2.0.0-beta.0 webpack 1.12.2

+4
2

: .

: . .

, .

var path = require('path');

var webpack = require('webpack');
var CommonsChunkPlugin = webpack.optimize.CommonsChunkPlugin;
var ProvidePlugin = webpack.ProvidePlugin;
//var UglifyJsPlugin = webpack.optimize.UglifyJsPlugin;

module.exports = {
    devtool: 'source-map',
    debug: true, // set false in production
    cache: true,

    entry: {
        'vendor': './src/vendor.ts', // third party dependencies
        'app': './src/app/app.ts' // our app
    },

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

    resolve: {
        extensions: ['', '.ts', '.js', '.json', '.css', '.html']
    },

    module: {
        loaders: [
            {
                test: /\.ts$/,
                loader: 'ts-loader',
                query: {
                    'ignoreDiagnostics': [
                        2403, // 2403 -> Subsequent variable declarations
                        2300, // 2300 -> Duplicate identifier
                        2374, // 2374 -> Duplicate number index signature
                        2375  // 2375 -> Duplicate string index signature
                    ]
                },
                exclude: [/\.(spec|e2e)\.ts$/, /node_modules\/(?!(ng2-.+))/]
            },

            // Support for *.json files.
            {test: /\.json$/, loader: 'json-loader'},

            // support for .css
            {test: /\.css$/, loaders: ['style', 'css']},
        ],
        noParse: [/angular2-polyfills/]
    },

    plugins: [
        new CommonsChunkPlugin({name: 'vendor', filename: 'vendor.js', minChunks: Infinity}),
        new CommonsChunkPlugin({name: 'common', filename: 'common.js', minChunks: 2, chunks: ['app', 'vendor']}),
        new ProvidePlugin({
            $: "jquery",
            jQuery: "jquery",
            Cookies: "js-cookie"
        })
//        new UglifyJsPlugin() // use for production
    ],

    // Other module loader config
    tslint: {
        emitErrors: true,
        failOnHint: false
    },
    // our Webpack Development Server config
    devServer: {
        contentBase: 'src',
        publicPath: '/__build__',
        colors: true,
        progress: true,
        port: 3000,
        displayCached: true,
        displayErrorDetails: true,
        inline: true
    }
};

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

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

, . Angular 2/Bootstrap 4/OAuth2 Github project, Webpack.

Angular ( RxJS ) , vendor.ts, .

vendor.ts:

require('./css/bootstrap.css');
require('./css/main.css');

import 'angular2/bundles/angular2-polyfills';

import 'angular2/platform/browser';
import 'angular2/core';
import 'angular2/http';
import 'angular2/router';

index.html.

<script src="dist/common.js"></script>
<script src="dist/vendor.js"></script>
<script src="dist/app.js"></script>

, , , index.html .

, , . Github, .

+6

: , webpack Angular 2 5 : script html , , , , system.js webpack, , "".js ", webpack:

<body>

<my-app></my-app>

<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>
<script src="bundle.js"></script>

</body>

webpack, :

var webpack = require("webpack");

module.exports = {
  entry: './src/boot.ts',
  output: {
    filename: 'bundle.js'
  },
  devtool: 'source-map',
  resolve: {
    extensions: ['', '.ts', '.js']
  },
  module: {
    loaders: [
      { test: /\.ts$/, loader: 'ts-loader' }
    ]
  },
  plugins: [
    new webpack.IgnorePlugin(/angular2/)
  ]
};
0
source

Source: https://habr.com/ru/post/1622432/


All Articles