Skip to content

Instantly share code, notes, and snippets.

@praveenpuglia
Last active April 11, 2018 17:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save praveenpuglia/8015828e4d3ec5a981cc4ecd5e1e70a4 to your computer and use it in GitHub Desktop.
Save praveenpuglia/8015828e4d3ec5a981cc4ecd5e1e70a4 to your computer and use it in GitHub Desktop.
Simplest webpack 4 configuration to work with vuejs & scss
// Require things!
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
// The configuration starts here!
module.exports = {
// The entry point for webpack to start generating a dependency graph.
entry: { index: './src/index.js' },
// I have set the mode to development here. But in real world
// this would probably be provided by CMD or a simple env
// change to process.ENV
mode: 'development',
// I want the bundle to have the name [name](index.js)
// with its [hash]. Every time I make changes to
// index.js or one of its dependencies, it should create
// a new version of it.
output: {
filename: '[name].[hash].js',
path: path.join(__dirname, 'build')
},
// Rules to apply to modules
module: {
rules: [
// Pass .vue files through the vue-loader
{
test: /\.vue$/,
use: 'vue-loader'
},
// Pass the JS files through the babel-loader
// for all the latest ES goodies.
{
test: /\.js$/,
use: 'babel-loader',
exclude: path.join(__dirname, 'node_modules')
},
// You wanna use sass don't you?
// Works in reverse order.
// sass-loader transforms the sass to css
// css-loader then returns all the css and invokes
// any references to urls and imports as another
// module to be tested by webpack. Also makes it
// js compatible.
// style-loader actually puts the code that puts that
// css into browsers.
{
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader']
}
]
},
// So, we wanna make sure that every time a new version of bundle
// is generated, we have that new version in our index.html.
// HTMLWebpackPlugin, very simply, dynamically puts links
// to the newly geneated bundle in index.html.
plugins: [new HtmlWebpackPlugin({ template: './index.html' })]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment