Last active
March 4, 2017 21:14
-
-
Save nikrou/44300eb4798581d7d41791b711019921 to your computer and use it in GitHub Desktop.
webpack angular hmr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "webpack-hmr", | |
"version": "0.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"build": "webpack --bail --progress --profile -p", | |
"dev": "webpack-dev-server --port 9100 --progress --colors --hot --inline" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"angular": "1.3.20", | |
"angular-animate": "1.3.20", | |
"angular-cookies": "1.3.20", | |
"angular-resource": "1.3.20", | |
"angular-route": "1.3.20", | |
"babel-core": "^6.23.1", | |
"babel-loader": "^6.3.2", | |
"babel-preset-es2015": "^6.22.0", | |
"clean-webpack-plugin": "^0.1.15", | |
"css-loader": "^0.26.2", | |
"html-webpack-plugin": "^2.28.0", | |
"node-sass": "^4.5.0", | |
"sass-loader": "^6.0.2", | |
"style-loader": "^0.13.2", | |
"webpack": "^2.2.1", | |
"webpack-dev-server": "^2.4.1" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var path = require('path'); | |
var webpack = require('webpack'); | |
var HtmlWebpackPlugin = require('html-webpack-plugin'); | |
var CleanWebpackPlugin = require('clean-webpack-plugin'); | |
var ENV = process.env.npm_lifecycle_event; | |
var isProd = (ENV==='build'); | |
module.exports = makeWebpackConfig(); | |
function makeWebpackConfig() { | |
var config = {}; | |
if (isProd) { | |
config.devtool = 'source-map'; | |
} else { | |
config.devtool = 'eval-source-map'; | |
} | |
config.entry = path.join(__dirname, 'src/index.js'); | |
config.output = { | |
filename: isProd ? '[name].[hash].js' : '[name].bundle.js', | |
path: path.join(__dirname, 'dist'), | |
chunkFilename: isProd ? '[name].[hash].js' : '[name].bundle.js' | |
}; | |
config.module = { | |
rules: [ | |
{ | |
test: /\.js$/, | |
loader: 'babel-loader', | |
exclude: /node_modules/, | |
options: { | |
presets: ['es2015'] | |
} | |
}, | |
{ | |
test: /\.scss/, | |
use: [ | |
{ | |
loader: 'style-loader' | |
}, | |
{ | |
loader: 'css-loader' | |
}, | |
{ | |
loader: 'sass-loader' | |
} | |
] | |
} | |
] | |
}; | |
config.plugins = [ | |
new CleanWebpackPlugin( | |
[path.join(__dirname, 'dist')], | |
{ | |
verbose: true, | |
dry: false | |
} | |
), | |
new HtmlWebpackPlugin({ | |
filename: 'index.html', | |
template: path.join(__dirname, 'src/index.html') | |
}), | |
new webpack.NamedModulesPlugin() | |
]; | |
return config; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment