Skip to content

Commit

Permalink
Take care css and js caching
Browse files Browse the repository at this point in the history
  • Loading branch information
genkio committed Mar 31, 2017
1 parent a55ed80 commit a8263b6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
15 changes: 15 additions & 0 deletions index-template.html
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Webpack Zero to Hero</title>
</head>

<body>
<div id="app"></div>
</body>

</html>
4 changes: 2 additions & 2 deletions index.html
Expand Up @@ -6,10 +6,10 @@
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Webpack Zero to Hero</title>

<link rel="stylesheet" href="dist/styles.css">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div id="app"></div>
<script src="dist/bundle.js"></script>
<script src="bundle.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -27,6 +27,7 @@
"css-loader": "^0.28.0",
"extract-text-webpack-plugin": "2.1.0",
"file-loader": "^0.10.1",
"html-webpack-plugin": "^2.28.0",
"rimraf": "^2.6.1",
"style-loader": "^0.16.1",
"url-loader": "^0.5.8",
Expand Down
10 changes: 7 additions & 3 deletions webpack.config.js
@@ -1,6 +1,7 @@
var path = require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var HTMLWebpackPlugin = require('html-webpack-plugin');

var DEVELOPMENT = process.env.NODE_ENV === 'development';
var PRODUCTION = process.env.NODE_ENV === 'production';
Expand All @@ -14,7 +15,10 @@ var entry = PRODUCTION ? ['./src/index.js'] :
var plugins = PRODUCTION ?
[
new webpack.optimize.UglifyJsPlugin(),
new ExtractTextPlugin('styles.css')
new ExtractTextPlugin('styles-[contenthash:10].css'),
new HTMLWebpackPlugin({
template: 'index-template.html'
})
]
:
[ new webpack.HotModuleReplacementPlugin() ];
Expand Down Expand Up @@ -60,7 +64,7 @@ module.exports = {
},
output: {
path: path.join(__dirname, 'dist'),
publicPath: '/dist/',
filename: 'bundle.js'
publicPath: PRODUCTION ? '/' : '/dist/',
filename: PRODUCTION ? 'bundle.[hash:12].min.js' : 'bundle.js'
}
};

0 comments on commit a8263b6

Please sign in to comment.