Last active
August 1, 2018 09:42
-
-
Save selbekk/80f6502d0ef534dae1b4145912b9b687 to your computer and use it in GitHub Desktop.
webpack and less -webpack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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