Let me start off by saying this is my first time using Webpack and cobbling together my own config, so there might be some obvious mistake I am overlooking.
The Problem
Right now, I am trying to use autoprefixer and even though I am not getting any errors, the prefixes are not appearing on my compiled CSS.
My test styles:
styles/main.scss
:
body {
background-color: blue;
display: flex;
flex-direction: column;
transition: all 300ms ease-in;
}
My package.json
file:
{
"name": "react-webpack-boilerplate",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "NODE_ENV=development webpack-dev-server --mode development --open --hot",
"build": "NODE_ENV=production webpack --mode production"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"prop-types": "^15.6.2",
"react": "^16.4.1",
"react-dom": "^16.4.1"
},
"devDependencies": {
"autoprefixer": "^9.0.1",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.5",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"clean-webpack-plugin": "^0.1.19",
"css-loader": "^1.0.0",
"html-webpack-plugin": "^3.2.0",
"mini-css-extract-plugin": "^0.4.1",
"node-sass": "^4.9.2",
"optimize-css-assets-webpack-plugin": "^5.0.0",
"postcss-loader": "^2.1.6",
"sass-loader": "^7.0.3",
"style-loader": "^0.21.0",
"webpack": "^4.16.3",
"webpack-cli": "^3.1.0",
"webpack-dev-server": "^3.1.5"
}
}
My postcss.config.js
file:
module.exports = {
plugins: [require('autoprefixer')]
};
My webpack.config.js
file:
const path = require('path');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const inDevMode = process.env.NODE_ENV === 'development';
const port = process.env.PORT || 4200;
module.exports = {
devtool: 'source-map',
entry: './src/js/index.js',
output: {
filename: 'bundle.[hash].js',
path: path.resolve(__dirname, 'dist')
},
devServer: {
port
},
optimization: {
minimizer: [
new UglifyJsPlugin({
test: /\.js$/,
exclude: /node_modules/,
cache: true,
sourceMap: true,
uglifyOptions: {
warnings: false,
output: { comments: false }
}
}),
new OptimizeCSSAssetsPlugin({})
]
},
plugins: [
new CleanWebpackPlugin('./dist', {
verbose: true,
beforeEmit: true
}),
new HtmlWebpackPlugin({
template: './src/index.html',
title: 'Testing!'
}),
new MiniCssExtractPlugin({
filename: '[name].[hash].css',
chunkFilename: '[id].[hash].css'
})
],
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.scss$/,
use: [
inDevMode ? 'style-loader' : MiniCssExtractPlugin.loader,
{ loader: 'css-loader', options: { sourceMap: true } },
{ loader: 'postcss-loader', options: { sourceMap: true } },
{ loader: 'sass-loader', options: { sourceMap: true } }
]
}
]
}
};
And my output CSS file when I’ve run my build
script:
body{background-color:#00f;color:#fff;display:flex;flex-direction:column;transition:all .3s ease-in}
I would really appreciate any help. This has had me stuck for hours. I can’t seem to find where I’m going wrong.