Skip to content

Instantly share code, notes, and snippets.

@pavelruzicka
Created February 4, 2018 12:04
Show Gist options
  • Select an option

  • Save pavelruzicka/085bb8183f792ae52f3765efad1d8e26 to your computer and use it in GitHub Desktop.

Select an option

Save pavelruzicka/085bb8183f792ae52f3765efad1d8e26 to your computer and use it in GitHub Desktop.
Using Webpack to compile Sass
<!--
<script src="dist/bundle.js"></script>
-->
<link rel="stylesheet" href="dist/main.css">
<h1>Hello world!</h1>
require('./main.scss');
$test: tomato;
h1 {
font-style: italic;
color: $test;
}
{
"name": "",
"version": "1.0.0",
"description": "",
"main": "src/main.js",
"scripts": {
"start": "webpack-dev-server",
"build": "webpack -p"
},
"author": "",
"license": "ISC",
"devDependencies": {
"css-loader": "^0.28.4",
"extract-text-webpack-plugin": "^2.1.2",
"node-sass": "^4.5.3",
"sass-loader": "^6.0.6",
"webpack": "^3.0.0",
"webpack-dev-server": "^2.5.0"
}
}
project/
├── dist/
├── src/
│   ├── main.js
│   └── main.scss
└── index.html
var path = require('path');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var extractPlugin = new ExtractTextPlugin({
filename: 'main.css'
});
module.exports = {
entry: './src/main.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/dist'
},
module: {
rules: [
{
test: /\.scss$/,
use: extractPlugin.extract({
use: ['css-loader', 'sass-loader']
})
}
]
},
plugins: [
extractPlugin
]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment