question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Output CSS to different directory with ExtractTextPlugin

See original GitHub issue

I’m using the ExtractTextPlugin to build a separate CSS file. It works great but I’d really like to output the CSS into a different directory than the JS:

module.exports = {
  entry: {
    module: "./source/javascripts/app.js",
  },
  output: {
    path: './source/built/',
    filename: 'app.js'
  },
  module: {
    loaders:[
      {
        test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader'
      },
      {
        test: /\.css$/,
        loader: ExtractTextPlugin.extract('style-loader', 'css-loader!postcss-loader')
      }
    ]
  },
  plugins: [
    new ExtractTextPlugin('app.css')
  ]
};

Currently both files go into ./source/built, is there a way to change this?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:21 (2 by maintainers)

github_iconTop GitHub Comments

28reactions
iDVBcommented, Sep 11, 2015

This worked for me…

webpack: { // grunt-webpack
  options: {
    module: {
      loaders: [
        { test: /\.jsx?$/, exclude: /(node_modules|bower_components)/, loader: 'babel' }, // REACTJS FILES
        { test: /\.json?$/, exclude: /(node_modules|bower_components)/, loader: 'json' }, // JSON FILES
        { test: /\.scss$/, loader: ExtractTextPlugin.extract('css!sass?includePaths[]=' + bourbon, { publicPath: '../'}) }, // SASS & CSS FILES
        { test: /\.(jpe?g|png|gif|svg)$/i, exclude: /(node_modules|bower_components)/, loader: 'url?limit=1000&name=images/[hash].[ext]' } // IMAGES
      ]
    } 
  },
  dev: {
    entry: './<%= project.path.voter.assets %>/app/app.js',
    output: {
      path: './<%= project.path.voter.dist %>/',
      filename: 'js/voter.bundle.js'
    },
    plugins: [
      new ExtractTextPlugin('css/voter.bundle.css', {
        allChunks: true
      })
    ]
  }
}
26reactions
nerdgrasscommented, May 3, 2015

This actually was a similar problem I was facing and andreypopp’s answer solved it for me. Specifically, what worked for me was:

plugins: [
    new ExtractTextPlugin("./css/[name].css"),
  ],
Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack output files to different directories - Stack Overflow
css $/, loader: ExtractTextPlugin.extract("style-loader", "css-loader") }, { test: /\.
Read more >
Webpack Separate CSS - Medium
How to separate CSS from JS using Webpack (CSS bundle). ... ExtractTextPlugin: Extract text from a bundle, or bundles, into a separate file....
Read more >
MiniCssExtractPlugin - webpack
In the example below, we'll use filename to output the generated css into a different directory. webpack.config.js const MiniCssExtractPlugin = require("mini- ...
Read more >
mini-css-extract-plugin - npm
Compared to the extract-text-webpack-plugin: Async loading; No duplicate compilation (performance); Easier to use; Specific to CSS ...
Read more >
Angular Data Grid: Angular Webpack 2 - AG Grid
helpers'); var path = require('path'); var ExtractTextPlugin ... [ext]' }, { // site wide css (excluding all css under the app dir) test:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found