Skip to content

Commit

Permalink
fix: 🔧 Make webpack use the postcss config
Browse files Browse the repository at this point in the history
  • Loading branch information
nono committed Feb 7, 2019
1 parent db1d702 commit 1aec8a2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 26 deletions.
10 changes: 7 additions & 3 deletions config/webpack.config.extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const webpack = require('webpack')
const path = require('path')

module.exports = ({ filename }) => ({
module.exports = ({ filename, production }) => ({
resolve: {
extensions: ['.styl']
},
Expand All @@ -23,7 +23,9 @@ module.exports = ({ filename }) => ({
loader: 'postcss-loader',
options: {
config: {
path: path.join(__dirname, '../postcss.config.js')
ctx: {
env: production ? 'production' : 'development'
}
},
sourceMap: true
}
Expand Down Expand Up @@ -51,7 +53,9 @@ module.exports = ({ filename }) => ({
loader: 'postcss-loader',
options: {
config: {
path: path.join(__dirname, '../postcss.config.js')
ctx: {
env: production ? 'production' : 'development'
}
},
sourceMap: true
}
Expand Down
8 changes: 5 additions & 3 deletions config/webpack.config.inline-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const webpack = require('webpack')
const path = require('path')

module.exports = {
module.exports = ({ production }) => ({
resolve: {
extensions: ['.styl']
},
Expand All @@ -24,7 +24,9 @@ module.exports = {
loader: 'postcss-loader',
options: {
config: {
path: path.join(__dirname, '../postcss.config.js')
ctx: {
env: production ? 'production' : 'development'
}
},
sourceMap: true
}
Expand All @@ -45,4 +47,4 @@ module.exports = {
}
})
]
}
})
4 changes: 2 additions & 2 deletions config/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const vars = require('./webpack.vars')

const cssConfig = vars => {
if (vars.mobile) {
return require('./webpack.config.inline-styles.js')
return require('./webpack.config.inline-styles.js')(vars)
} else {
return require('./webpack.config.extract')(vars)
}
Expand All @@ -21,7 +21,7 @@ module.exports = (env = {}) => {
addAnalyzer ? require('./webpack.config.analyzer.js') : {},
require('./webpack.config.jsx.js'),
require(production ? './webpack.config.prod' : './webpack.config.dev'),
cssConfig({ filename, mobile }),
cssConfig({ filename, mobile, production }),
{
output: {
filename: filename('js', mobile ? 'mobile' : ''),
Expand Down
36 changes: 18 additions & 18 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
const path = require('path')

const { production } = require('./config/webpack.vars')
module.exports = ({ options }) => {
let plugins = [
require('postcss-import')({
path: [path.resolve(__dirname, 'src/styles/')]
}),
require('autoprefixer')(['last 2 versions', 'not dead', 'not ie <= 11'])
]

const commons = [
require('postcss-import')({
path: [path.resolve(__dirname, 'src/styles/')],
plugins: production ? [
require('autoprefixer')(['last 2 versions']),
require('postcss-discard-empty')
] : []
})
]
if (options.env === 'production') {
plugins = plugins.concat([
require('postcss-discard-empty'),
require('postcss-discard-duplicates'),
require('css-mqpacker'),
require('csswring')({
removeAllComments: true
})
])
}

module.exports = {
plugins: production ? commons.concat([
require('postcss-discard-duplicates'),
require('css-mqpacker'),
require('csswring')({
removeAllComments: true
})
]) : commons
return { plugins }
}

0 comments on commit 1aec8a2

Please sign in to comment.