3

I'm really disheartened, because I can't find any useful resource on the subject.

I merely want to watch my .css files, use post css' plugins to transform them and finally export them to my /public folder as I already do with my .jsx files

Here's my web pack configuration

    const path = require('path');
const webpack = require('webpack');

var ExtractTextPlugin = require('extract-text-webpack-plugin');

module.exports = {
    entry: path.resolve('src/index.jsx'),
    output: {
        path: path.resolve('public'),
        filename: 'bundle.js'
    },
    resolve: {
        extensions: ['*', '.js', '.jsx']
    },
    devServer: {
        publicPath: "/",
        contentBase: "./public"
    },
    module: {
        rules: [
            {
                test: /\.css$/,
                exclude: /node_modules/,
                loader: ExtractTextPlugin.extract({
                    fallback: 'style-loader',
                    use: [
                        {
                            loader: 'css-loader',
                            options: {
                                modules: true,
                                localIdentName: '[name]__[local]___[hash:base64:5]'
                            }
                        }, {
                            loader: 'postcss-loader',
                            options: {
                                plugins: function() {
                                    return [require('lost'), require('postcss-cssnext'), require('postcss-import')]
                                }
                            }
                        }
                    ]
                })
            }, {
                test: /\.jsx?$/,
                use: [
                    {
                        loader: 'babel-loader',
                        options: {
                            presets: ['es2015', 'react']
                        }
                    }
                ],
                exclude: /(node_modules|bower_components)/
            }
        ]
    },
    plugins: [new ExtractTextPlugin("main.css")]
}
Rentonie
  • 477
  • 1
  • 10
  • 25

2 Answers2

4

I assume you are using webpack2

If you want your css file dumped out separately, you would need ExtractTextPlugin. Here is my css loader which works

I define the post css plugins right within the webpack config, because then it stays in one place. Hope this helps:

var ExtractTextPlugin = require('extract-text-webpack-plugin');
...
...
module.exports = {
...
...
    module: {
        rules: [
...
...
            {
                test: /\.css$/,
                exclude: /node_modules/,
                loader: ExtractTextPlugin.extract(
                    { fallback: 'style-loader',
                    use: [{
                        loader: 'css-loader',
                        options: {
                            modules: true,
                            localIdentName:'[name]__[local]___[hash:base64:5]'
                        }
                    },
                    {
                        loader: 'postcss-loader',
                        options: {
                            plugins: function() {
                                return [
                                    require('autoprefixer')
                                ]
                            }
                        }
                    },
                ]
            })
        },
}
vma
  • 1,606
  • 13
  • 14
0

Maybe your plugins are incorrectly created.

Try

return [require('lost')(), require('postcss-cssnext')(), require('postcss-import')()]

(Note the () to invoke the plugin creation).

Also are you actually using import/require() to include your css? If not you should, no magic stuff will glob your css :)

MoOx
  • 8,423
  • 5
  • 40
  • 39