Skip to content

Instantly share code, notes, and snippets.

@selbekk

selbekk/webpack.config.js

Last active Aug 1, 2018
Embed
What would you like to do?
webpack and less -webpack.config.js
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const isProduction = process.env.NODE_ENV === 'production';
const config = {
// First, let's define an entry point for webpack to start its crawling.
entry: './src/index.js',
// Second, we define where the files webpack produce, are placed
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
},
module: {
rules: [
{
test: /\.less$/, // .less and .css
use: [
isProduction ? MiniCssExtractPlugin.loader : 'style-loader',
'css-loader',
'less-loader'
],
},
]
},
// Add an instance of the MiniCssExtractPlugin to the plugins list
// But remember - only for production!
plugins: isProduction ? [new MiniCssExtractPlugin()] : []
};
module.exports = config;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.