Webpack - dont output a bundle for a certain entry point
Asked Answered
P

1

9

Im using a file-loader to automatically render a bunch of pug templates to static html files, but webpack is also outputting a pointless file based on the entry point

Eg this is in my webpack.config.js:

entry: {
    'js/build/bundle.js': './js/app.js',
    'this-shouldnt-emit': './pug/.pug.js' //pug entry point
},

output: {
    path: path.join(__dirname, '../'),
    filename: '[name]'
},

...
// pug loading module rule
        {
            test: /\.pug$/,
            include: path.resolve(__dirname, "../pug"),
            use: [
                "file-loader?name=[path][name].html&context=./pug",
                "pug-html-loader?pretty&exports=false"
            ]
        }

and Im getting a this-shouldnt-emit bundle file in the root build directory, which I dont want.

How can I stop the file-loader from emitting an output bundle, but not interfere with it generating all the static html files it currently is. Is there a plugin or some kind of null loader I can put at the end of the loader chain to kill the bundle emitting?

Planoconvex answered 21/2, 2017 at 19:23 Comment(1)
simple way is to remove it after build)Granulite
F
1

I am not sure of what you are really asking but if you want it include multiple files in one bundle, use an array. The whole point of using [name] in filename: '[name].bundle.js is for multiple entries. It is not necessary (but optional) for one entry key.

This will create two bundle files.

entry: {
   BUNDLE_KEY_ONE: 'path/file.js',
   BUNDLE_KEY_TWO: 'path/otherFile.js',
}

This is how you have multiple files one bundle.

entry: {
   SINGLE_BUNDLE_NAME: ['file/one.js', 'file/two.js']
}
Fabrienne answered 27/8, 2017 at 1:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.