Skip to content

Instantly share code, notes, and snippets.

@selbekk
Last active August 1, 2018 09:42
Show Gist options
  • Save selbekk/80f6502d0ef534dae1b4145912b9b687 to your computer and use it in GitHub Desktop.
Save selbekk/80f6502d0ef534dae1b4145912b9b687 to your computer and use it in GitHub Desktop.
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