Skip to content

Commit 473982d

Browse files
author
vinogradov
committed
Add hashes to assets, clean dist folder, autogenerate index.html, add favicon support
1 parent 0c4800d commit 473982d

File tree

8 files changed

+38
-28
lines changed

8 files changed

+38
-28
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
.idea
33
node_modules
44
bower_components
5-
dist/app.js
6-
dist/app.css
5+
dist
76
npm-debug.log

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@ Starter Kit for a modern SPA application. Includes only the latest and greatest
1515

1616
# TODO
1717

18-
* add hashes for assets
1918
* Redux
2019
* Redux Form 3.0
2120
* ESLint configure rules: duplicate cases etc
2221
* JSCS
2322
* Rollbar?
24-
* clean dist directory before build
25-
* webpack-dev-server auto reload
2623

2724
### Tests:
2825

dist/index.html

Lines changed: 0 additions & 14 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919
"babel-loader": "*",
2020
"babel-preset-es2015": "*",
2121
"babel-preset-react": "*",
22+
"clean-webpack-plugin": "*",
2223
"css-loader": "*",
2324
"eslint": "*",
2425
"eslint-loader": "*",
2526
"eslint-plugin-react": "*",
2627
"extract-text-webpack-plugin": "*",
28+
"html-webpack-plugin": "*",
2729
"node-sass": "*",
2830
"sass-loader": "*",
2931
"style-loader": "*",

src/entry.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require('file?name=[name].[ext]!./favicon.ico');
2+
13
var reactHelloWorld = require('./helloWorldComponent/component');
24

35
reactHelloWorld();

src/favicon.ico

932 Bytes
Binary file not shown.

src/index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>App</title>
6+
</head>
7+
8+
<body>
9+
<div id="app"></div>
10+
</body>
11+
</html>

webpack.config.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
var path = require('path');
22
var ExtractTextPlugin = require("extract-text-webpack-plugin");
3+
var Clean = require('clean-webpack-plugin');
4+
var HtmlWebpackPlugin = require('html-webpack-plugin')
35

4-
var SRC_PATH = path.join(__dirname, 'src');
5-
var APPLICATION_BUNDLE_FILENAME = 'app.js';
6-
var CSS_BUNDLE_FILENAME = 'app.css';
6+
var SRC_PATH = 'src';
7+
var SRC_ABSOLUTE_PATH = path.join(__dirname, SRC_PATH);
8+
var INDEX_HTML_TEMPLATE_ABSOLUTE_PATH = path.join(SRC_ABSOLUTE_PATH, 'index.html');
9+
10+
var DIST_PATH = 'dist';
11+
var DIST_ABSOLUTE_PATH = path.join(__dirname, DIST_PATH);
12+
13+
var APPLICATION_BUNDLE_FILENAME = 'app-[hash].js';
14+
var CSS_BUNDLE_FILENAME = 'app-[hash].css';
715

816
var plugins = [
9-
new ExtractTextPlugin(CSS_BUNDLE_FILENAME)
17+
new ExtractTextPlugin(CSS_BUNDLE_FILENAME),
18+
new Clean([DIST_PATH]),
19+
new HtmlWebpackPlugin({
20+
template: INDEX_HTML_TEMPLATE_ABSOLUTE_PATH,
21+
inject: 'body'
22+
})
1023
];
1124

1225
var isDist = process.argv[2] === '--dist';
@@ -23,18 +36,18 @@ if (isDist) {
2336
}
2437

2538
module.exports = {
26-
context: SRC_PATH,
39+
context: SRC_ABSOLUTE_PATH,
2740
entry: "./entry",
2841
output: {
29-
path: path.join(__dirname, 'dist'),
42+
path: DIST_ABSOLUTE_PATH,
3043
filename: APPLICATION_BUNDLE_FILENAME
3144
},
3245
module: {
3346
// loaders are loaded from bottom to top
3447
loaders: [{
3548
loader: 'babel',
3649
test: /\.js|jsx$/,
37-
include: SRC_PATH, // other paths are ignored
50+
include: SRC_ABSOLUTE_PATH, // other paths are ignored
3851
query: {
3952
presets: ['es2015', 'react']
4053
}
@@ -43,11 +56,11 @@ module.exports = {
4356
// Or use preLoaders section to check source files, not modified by other loaders (like babel-loader)
4457
loader: 'eslint',
4558
test: /\.js|jsx$/,
46-
include: SRC_PATH
59+
include: SRC_ABSOLUTE_PATH
4760
},{
4861
loader: ExtractTextPlugin.extract('style', 'css!sass'),
4962
test: /\.scss$/,
50-
include: SRC_PATH
63+
include: SRC_ABSOLUTE_PATH
5164
}],
5265
},
5366
plugins: plugins

0 commit comments

Comments
 (0)