Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

AlexP11223's avatar

How to create multiple entry points and use CommonsChunkPlugin in Ellixir webpack?

Is it possible to create multiple entry points (such as news.js, login.js) in Ellixir webpack? Or do I need to create webpack config file?

And CommonsChunkPlugin? (to nnt iinclude some common code, webpack code, etc. in all entry points)

0 likes
1 reply
AlexP11223's avatar

I created a simple webpack.config.js

    var path = require("path");
    var CommonsChunkPlugin = require("webpack/lib/optimize/CommonsChunkPlugin");
    
    module.exports = {
        context: path.join(__dirname, "resources/assets"),
    
        entry: {
            login: "./js/login.js",
            post: "./js/post.js",
            common: "./js/common.js"
        },
        output: {
            path: path.join(__dirname, "public/js"),
            filename: "[name].js"
        },
        plugins: [
            new CommonsChunkPlugin({
                filename: "common.js",
                name: "common"
            })
        ]
    };

but what is the correct way to make Elixir use it?

Looks like it still needs a file path, that is mix.webpack() throws error.

mix.webpack('') seems to work but looks weird, not sure if it is the correct way.

UPD: also it fails during production build

Starting 'webpack'...

Hmm, not sure how to compress this type of file. Stick with CSS or JavaScript files!

mix.webpack(['post.js', 'login.js', 'common.js']) and mix.webpack('*.js') seem to work but looks like it was not intended to be used like this because destination output looks weird: public\js\all.js (though all.js is not created)

Please or to participate in this conversation.