Can your webpack.config file serve multiple entry points?

Due to the training of Angular 2 during the development of the project, I did not include routing, as I should have. I have a main.js file that loads one component and another main2.js file that loads the second component (now I know that I had to route them from one page, but we are very far from the project that this will cause backup ((will do, if necessary, however)). I am trying to use webpack to bind code for "loadability" (sp?).

Here is my webpack.config.js file:

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

module.exports = {
    entry: "./main",
    output: {
        path: __dirname,
        filename: "./dist/bundle.js"
    },
    resolve: {
        extensions: ['.js', '.ts']
    },
    module: {
        loaders: [{
            test: /\.ts/, loaders: ['ts-loader'], exclude: /node_modules/
        }]
    }
};

Is it possible to define two entry points like this:

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

module.exports = {
    entry: "./main",
    output: {
        path: __dirname,
        filename: "./dist/bundle.js"
    },
    resolve: {
        extensions: ['.js', '.ts']
    },
    module: {
        loaders: [{
            test: /\.ts/, loaders: ['ts-loader'], exclude: /node_modules/
        }]
    }
};

module.exports = {
    entry: "./main2",
    output: {
        path: __dirname,
        filename: "./dist/bundle2.js"
    },
    resolve: {
        extensions: ['.js', '.ts']
    },
    module: {
        loaders: [{
            test: /\.ts/, loaders: ['ts-loader'], exclude: /node_modules/
        }]
    }
};

Or would I rather go back and restructure my project to use routing and have one entry point for me?

+4
1

, .

, .
entry , .

:

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

module.exports = {
    entry: {
        "main": "./main.ts",
        "main2": "./main2.ts",
    }
    output: {
        path: path.join(__dirname, './dist'),
        filename: "[name].js"
    },
    // Rest of your config ...
};

[name] "main" "main2" , "main.js" "main2.js"

docs ( webpack 1, webpack 2/3 ).

+4

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


All Articles