Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webpack - dont output a bundle for a certain entry point

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?

like image 865
Matthew Avatar asked Feb 21 '17 19:02

Matthew


People also ask

How do you define an entry point in webpack?

webpack.config.jsmodule. exports = { entry: { main: './path/to/my/entry/file. js', }, }; We can also pass an array of file paths to the entry property which creates what is known as a "multi-main entry".

Does webpack automatically minify?

Webpack v4+ will minify your code by default in production mode .

What is exclude in webpack?

Actually, those 'include' and 'exclude' properties are telling the loaders whether to include/exclude the files described (such as the contents of node_modules ), not webpack itself.

What is webpack chunking?

Chunk: This webpack-specific term is used internally to manage the bundling process. Bundles are composed out of chunks, of which there are several types (e.g. entry and child).


1 Answers

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']
}
like image 163
Michael Bruce Avatar answered Sep 29 '22 00:09

Michael Bruce