Getting css output using webpack ExtractTextPlugin

后端 未结 4 1379
轻奢々
轻奢々 2020-12-24 10:43

I am trying to get css requires to work in webpack using the ExtractTextPlugin but with no success

I want a separate css file rather than inlining any css.

4条回答
  •  感情败类
    2020-12-24 11:43

    I have modified your config filenames and how you include them in page

       var path = require('path');
       var webpack = require('webpack');
       var ExtractTextPlugin = require('extract-text-webpack-plugin');
    
    module.exports = {
      devtool: 'eval',
      entry: [
        'webpack-dev-server/client?http://localhost:3000',
        'webpack/hot/only-dev-server',
        './scripts/index'
      ],
      output: {
        path: path.join(__dirname, 'build'),
        filename: 'scripts/bundle.js',
        publicPath: '/scripts/'
      },
      plugins: [
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NoErrorsPlugin(),
        new ExtractTextPlugin('styles/styles.css', {
          publicPath: '/styles/',
          allChunks: true
        })
      ],
      resolve: {
        extensions: ['', '.js', '.jsx']
      },
      module: {
        loaders: [{
          test: /\.jsx?$/,
          loaders: ['react-hot', 'babel'],
          include: path.join(__dirname, 'scripts')
        },
        {
            test: /\.css$/,
            loader: ExtractTextPlugin.extract('style-loader', 'css-loader')
        }]
      }
    };
    

    Following is the html page

    
      
        
      
      
        

提交回复
热议问题