I am trying to setup a Webpack configuration for a website I want to build. I want to compile SASS to CSS and place it into the dist folder. When I run npm run build
it works fine but when I run npm run watch
to trigger the Webpack-dev-server it does not compile the index.js to bundle.js and it won't appear in the dist folder. Is there something wrong with my webpack.config.js?
index.html
<html>
<head>
<title>Getting Started</title>
<link rel="stylesheet" href="dist/css/main.min.css">
</head>
<body>
test
<script src="dist/scripts/bundle.js"></script>
</body>
</html>
webpack.config.js
const path = require('path');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const extractSass = new ExtractTextPlugin({
filename: "../css/main.min.css",
disable: process.env.NODE_ENV === "development"
});
module.exports = {
entry: './src/scripts/index.js',
output: {
path: path.resolve(__dirname, 'dist/scripts'),
filename: 'bundle.js',
publicPath: 'dist/scripts'
},
module: {
rules: [
{
test: /\.scss$/,
use: extractSass.extract({
use: [{
loader: "css-loader"
}, {
loader: "sass-loader"
}],
fallback: "style-loader"
})
}
]
},
plugins: [
extractSass
]
};
package.json
{
"name": "project1",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack --optimize-minimize",
"watch": "webpack-dev-server"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"css-loader": "^0.28.9",
"extract-text-webpack-plugin": "^3.0.2",
"node-sass": "^4.7.2",
"sass-loader": "^6.0.6",
"style-loader": "^0.20.2",
"webpack": "^3.11.0",
"webpack-dev-server": "^2.11.1"
},
"dependencies": {}
}