Skip to content

Instantly share code, notes, and snippets.

@anareyna
Last active December 31, 2019 13:25
Show Gist options
  • Save anareyna/8b552e16f4d7608cee5f3ea18ce4666f to your computer and use it in GitHub Desktop.
Save anareyna/8b552e16f4d7608cee5f3ea18ce4666f to your computer and use it in GitHub Desktop.
webpack 4: Webpack dev server + proxy + hot reloading working
{
"name": "webpack-4-quickstart",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"precommit": "lint-staged",
"dev": "webpack-dev-server --mode development ./src/scripts/index.js --open",
"build": "webpack --mode production ./src/scripts/index.js"
},
"lint-staged": {
"src/**/*.{js,json,css,md}": [
"eslint",
"prettier --write",
"git add"
]
},
"keywords": [],
"devDependencies": {
"babel-core": "^6.26.0",
"babel-eslint": "^8.2.2",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.1",
"breakpoint-sass": "^2.7.1",
"breakpoint-slicer": "^2.0.0",
"css-loader": "^0.28.10",
"eslint": "^4.18.2",
"eslint-loader": "^2.0.0",
"extract-text-webpack-plugin": "^4.0.0-beta.0",
"file-loader": "^1.1.11",
"html-loader": "^0.5.5",
"html-webpack-plugin": "^3.0.4",
"husky": "^0.14.3",
"image-webpack-loader": "^4.1.0",
"lint-staged": "^7.0.0",
"node-sass": "^4.7.2",
"prettier": "^1.11.1",
"pug": "^2.0.0-rc.4",
"pug-loader": "https://github.com/pugjs/pug-loader/tarball/master",
"sass-loader": "^6.0.7",
"style-loader": "^0.20.2",
"webpack": "^4.0.0",
"webpack-cli": "^2.0.10",
"webpack-dev-server": "^3.1.0",
"webpack-notifier": "^1.5.1"
},
"dependencies": {}
}
const HtmlWebPackPlugin = require('html-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const WebpackNotifierPlugin = require('webpack-notifier')
const path = require('path')
const appDirectory = path.resolve(__dirname, './../')
const localAppBackendUrl = 'http://localhost:48000/'
module.exports = {
output: {
path: `${appDirectory}landpages/static/`,
publicPath: `${localAppBackendUrl}static/`,
filename: 'js/[name].js'
},
module: {
rules: [
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
use: [
{
loader: 'css-loader',
options: {
minimize: true,
},
},
{
loader: 'sass-loader',
},
],
fallback: 'style-loader',
allChunks: true,
}),
},
{
test: /\.js$/,
exclude: /node_modules/,
use: ['babel-loader', 'eslint-loader'],
},
{
test: /\.html$/,
use: [
{
loader: 'html-loader',
options: { minimize: false },
},
],
},
{
test: /\.(gif|png|jpe?g|svg)$/i,
use: {
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'img/'
}
// {
// loader: 'image-webpack-loader',
// options: {
// mozjpeg: {
// progressive: true,
// quality: 65,
// },
// // optipng.enabled: false will disable optipng
// optipng: {
// enabled: false,
// },
// pngquant: {
// quality: '65-90',
// speed: 4,
// },
// gifsicle: {
// interlaced: false,
// },
// },
// },
},
},
{
test: /\.pug$/,
use: {
loader: 'pug-loader',
query: {}, // Can be empty
},
},
],
},
resolve: {
alias: {
assets: path.resolve(__dirname, 'src/assets/'),
},
},
devServer: {
openPage: 'home-alarm/',
historyApiFallback: true,
noInfo: true,
headers: { 'Access-Control-Allow-Origin': '*' },
port: 8020,
quiet: true,
proxy: {
'/': {
target: localAppBackendUrl,
changeOrigin: true
}
}
},
node: {
fs: 'empty'
},
plugins: [
new ExtractTextPlugin('css/[name].css'),
new WebpackNotifierPlugin({
alwaysNotify: true,
skipFirstNotification: true,
}),
],
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment