I have a very simple set up that uses Webpack (1.14.0) with Extract Text Webpack Plugin (1.0.1) to generate a CSS file. The problem is that upon running webpack, no CSS artifact is produced.
Here is my webpack.config.js
:
var ExtractTextPlugin = require('extract-text-webpack-plugin')
var path = require('path')
module.exports = {
entry: [
path.resolve(__dirname, 'src') + '/index.js'
],
module: {
loaders: [
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader')
}
]
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/'
},
plugins: [
new ExtractTextPlugin(path.resolve(__dirname, 'dist') + '/style.css')
]
}
As you can see this is a very simple setup. I have a folder called src
which contains a file called index.js
(that is currently blank) and style.css
(which only contains a single body style). The expectation is that the relative dist
folder contains an artifact called style.css
(which should basically be just a carbon copy of the original). The actual result is that only dist/bundle.js
is ever produced. As far as I can tell the version of Webpack and Extract Text Webpack Plugin should be compatible (the peerDependency
of Extract Text Webpack Plugin is ^1.9.11
).
What am I missing here?
I was able to get it to generate an artifact, but I'm not really comfortable with this solutions.
Here's my updated
webpack.config.js
:The solution was to add the stylesheet (in this case
path.resolve(__dirname, 'src') + '/style.scss'
) as an entry point. You have to do this if your JavaScript files do not reference the stylesheet in anyway. I changed the stylesheet to Sass in order to prove that the loader was handling the file and not simply copying an unprocessed file.This solution doesn't seem to jive with existing documentation on the topic, but I think the entry point property is implied with most tutorials and examples. Therefore, I probably just didn't realize the way this had to be specified.
Adding to the problem was that I was passing in the full path to the
new ExtractTextPlugin()
constructor. That wasn't the reason a file wasn't being generated, but I was doing that wrong as well. It only needs to be the file name. The output property path is referenced automatically.