I have read tons of tutorials and looked at more Github repos than I care to remember but I'm really struggling to setup Webpack 3 to do the following:
- Compile SASS into CSS
- Create a CSS file within a dist directory
- Run Autoprefixer on CSS
Below is my webpack.config.js:
const path = require('path')
const webpack = require('webpack')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
module.exports = {
context: path.resolve(__dirname, 'src'),
entry: {
app: './js/index.js',
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/dist', // New
},
devServer: {
contentBase: path.resolve(__dirname, 'src'), // New
},
module: {
rules: [
{
test: /\.js$/i,
exclude: [/node_modules/],
use: [{
loader: 'babel-loader',
options: { presets: ['env'] },
}],
},
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: "css-loader"
})
},
{
test: /\.(sass|scss)$/i,
use: [
'style-loader',
'css-loader',
'sass-loader',
]
}
]
},
plugins: [
new ExtractTextPlugin({
filename: 'css/styles.css',
allChunks: true,
}),
]
};
At the moment:
- the webpack dev server is running.
- Styles are copied from src/scss/styles.scss to an inline style block within the HTML file served from src/index.html.
I would like a dist directory to be created with a styles.css file within it which I could then link to from within my HTML.
Thanks