Webpack ExtractTextPlugin not generating css files

217 views Asked by At

I am currently trying to restore CSS styles to React Boilerplate, and was able to get the css styles to load successfully in a dev environment. When I try to bundle the project for deployment, the css files are not being created by webpack & ExtractTextPlugin.

Versions:

    "webpack": "2.1.0-beta.25",
    "extract-text-webpack-plugin": "^2.0.0-beta.4",

Could someone please take a look at my webpack files below to see what might be the reason why the css files aren't being created?

Relevant webpack.prod.babel.js:

const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const OfflinePlugin = require('offline-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = require('./webpack.base.babel')({

  entry: [
    path.join(process.cwd(), 'app/app.js'),
  ],
  output: {
    filename: '[name].[chunkhash].js',
    chunkFilename: '[name].[chunkhash].chunk.js',
  },
  cssLoaders: ExtractTextPlugin.extract({
                fallbackLoader: "style-loader",
                loader: "css-loader?modules&-autoprefixer&importLoaders=1!postcss-loader"
            }),
  plugins: [
    // Minify and optimize the index.html
    new HtmlWebpackPlugin({
      template: 'app/index.html',
      minify: {
        removeComments: true,
        collapseWhitespace: true,
        removeRedundantAttributes: true,
        useShortDoctype: true,
        removeEmptyAttributes: true,
        removeStyleLinkTypeAttributes: true,
        keepClosingSlash: true,
        minifyJS: true,
        minifyCSS: true,
        minifyURLs: true,
      },
      inject: true,
    }),
    new ExtractTextPlugin("styles.css"),

    }),
  ],
});

relevant webpack.base.babel.js:

const path = require('path');
const webpack = require('webpack');
const cssnext = require('postcss-cssnext');
const postcssFocus = require('postcss-focus');
const postcssReporter = require('postcss-reporter');

module.exports = (options) => ({
  entry: options.entry,
  output: Object.assign({ // Compile into js/build.js
    path: path.resolve(process.cwd(), 'build'),
    publicPath: '/',
  }, options.output), // Merge with env dependent settings
  module: {
    loaders: [{
      // Transform our own .css files with PostCSS and CSS-modules
      test: /\.css$/,
      exclude: [
        /node_modules/,
      ],
      loader: options.cssLoaders,
    },{
      test: /\.css$/,
      include: /node_modules/,
      loaders: ['style-loader', 'css-loader'],
    }, {
      test: /\.(eot|svg|ttf|woff|woff2)$/,
      loader: 'file-loader',
    }],
  },
  plugins: options.plugins.concat([
    new webpack.ProvidePlugin({
      // make fetch available
      fetch: 'exports?self.fetch!whatwg-fetch',
    }),
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: JSON.stringify(process.env.NODE_ENV),
      },
    }),
    new webpack.NamedModulesPlugin(),
    new webpack.LoaderOptionsPlugin({
     options: {
       context: path.resolve(process.cwd()),
       postcss: [
         postcssFocus(), // Add a :focus to every :hover
         cssnext({ // Allow future CSS features to be used, also auto-prefixes the CSS...
           browsers: ['last 2 versions', 'IE > 10'], // ...based on this browser list
         }),
         postcssReporter({ // Posts messages from plugins to the terminal
           clearMessages: true,
         }),
       ],
     },
   }),
  ]),
  resolve: {
    modules: ['app', 'node_modules'],
    extensions: [
      '.js',
      '.jsx',
      '.react.js',
    ],
    mainFields: [
      'browser',
      'jsnext:main',
      'main',
    ],
  },
  devtool: options.devtool,
  target: 'web', // Make web variables accessible to webpack, e.g. window
});
0

There are 0 answers