I want to bundle several standard libraries into two files bundle.js and bundle.css with webpack 3.8
This is my webpack.config.js:
const webpack = require('webpack');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const path = require("path");
module.exports = {
entry: {
'vendor': [
'jquery',
'popper.js',
'bootstrap',
],
},
output: {
path: path.resolve(__dirname, 'public/js'),
filename: 'bundle.js'
},
module: {
rules:[
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: "css-loader"
})
}
],
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
uglifyOptions: {
compress: true
}
}),
new ExtractTextPlugin("styles.css"),
]
};
After running webpack, I get only bundle.js file:
Asset Size Chunks Chunk Names
bundle.js 264 kB 0 [emitted] [big] vendor
How should I config webpack to produce bundle.css ?
Code splitting is one of the most compelling features of webpack. This feature allows you to split your code into various bundles which can then be loaded on demand or in parallel.
webpack.config.jsWe can also pass an array of file paths to the entry property which creates what is known as a "multi-main entry". This is useful when you would like to inject multiple dependent files together and graph their dependencies into one "chunk".
purgecss-webpack-plugin allows you to eliminate most of the CSS as ideally we would bundle only the CSS classes we are using.
Loaders are the node-based utilities built for webpack to help webpack to compile and/or transform a given type of resource that can be bundled as a javascript module. css-loader is the npm module that would help webpack to collect CSS from all the css files referenced in your application and put it into a string.
There are two ways to do it.
First
You can import your .css
files in the files provided at entry point.
for eg.
if entry: index.js
in index.js
you have to import your css files
import './*.css' // all css files in root
Second
you can provide it in your entry point.
entry: {
{
'vendor': [
'jquery',
'popper.js',
'bootstrap',
],
'styles': '/*.css'
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With