Webpack ExtractTextPlugin不生成css文件

时间:2016-12-27 22:20:32

标签: css reactjs webpack react-boilerplate extract-text-plugin

我目前正在尝试将CS​​S样式恢复为React Boilerplate,并且能够在开发环境中成功加载css样式。当我尝试捆绑项目进行部署时,webpack& ExtractTextPlugin。

版本:

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

有人可以看看下面的webpack文件,看看为什么没有创建css文件的原因?

相关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"),

    }),
  ],
});

相关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 个答案:

没有答案