Skip to content

Commit 6a0db0d

Browse files
committed
refactor(webpack): update webpack configs
1 parent 4b700cb commit 6a0db0d

13 files changed

+273
-114
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
*.log
33
npm-debug.log*
44
dist
5-
node_modules
5+
node_modules
6+
.DS_Store

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ A lightweight foundation for your next webpack based frontend project.
99
npm install
1010
```
1111

12-
### Start Dev Server
12+
### Start Dev Server
1313

1414
```
1515
npm run dev
@@ -26,6 +26,5 @@ npm run build
2626
* ES6 Support via [babel-loader](https://github.com/babel/babel-loader)
2727
* SASS Support via [sass-loader](https://github.com/jtangelder/sass-loader)
2828
* Linting via [eslint-loader](https://github.com/MoOx/eslint-loader)
29-
* Hot Module Replacement
3029

3130
When you run `npm run build` we use the [extract-text-webpack-plugin](https://github.com/webpack/extract-text-webpack-plugin) to move the css to a separate file and included in the head of your `index.html`, so that the styles are applied before any javascript gets loaded. We disabled this function for the dev version, because the loader doesn't support hot module replacement.

package-lock.json

+122
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+11-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"version": "1.0.0",
44
"description": "A light foundation for your next frontend project based on webpack.",
55
"scripts": {
6-
"build": "webpack --config webpack-prod.config.js --colors",
7-
"dev": "webpack-dev-server --open --config webpack-dev.config.js --watch --colors"
6+
"build": "webpack --config webpack/webpack.config.prod.js --colors",
7+
"dev": "webpack-dev-server --open --config webpack/webpack.config.dev.js"
88
},
99
"repository": {
1010
"type": "git",
@@ -36,24 +36,31 @@
3636
"semi": 2
3737
}
3838
},
39+
"babel": {
40+
"presets": [
41+
"es2015"
42+
]
43+
},
3944
"homepage": "https://github.com/wbkd/yet-another-webpack-es6-starterkit#readme",
4045
"devDependencies": {
4146
"babel-core": "^6.26.3",
4247
"babel-loader": "^7.1.4",
4348
"babel-preset-es2015": "^6.24.1",
4449
"clean-webpack-plugin": "^0.1.19",
50+
"copy-webpack-plugin": "^4.5.1",
4551
"css-loader": "^0.28.11",
4652
"eslint": "^4.19.1",
4753
"eslint-loader": "^2.0.0",
4854
"extract-text-webpack-plugin": "^4.0.0-beta.0",
55+
"file-loader": "^1.1.11",
4956
"html-webpack-plugin": "^3.2.0",
5057
"node-sass": "^4.9.0",
5158
"sass-loader": "^6.0.7",
5259
"style-loader": "^0.18.2",
53-
"uglifyjs-webpack-plugin": "^1.2.5",
5460
"webpack": "^4.12.0",
5561
"webpack-cli": "^2.1.5",
56-
"webpack-dev-server": "^3.1.4"
62+
"webpack-dev-server": "^3.1.4",
63+
"webpack-merge": "^4.1.3"
5764
},
5865
"dependencies": {
5966
"babel-polyfill": "^6.9.0"

public/.gitkeep

Whitespace-only changes.

src/scripts/index.js

-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
11
'use strict';
2-
3-
if (module.hot) {
4-
module.hot.accept();
5-
}
6-
72
import '../styles/index.scss';

webpack-dev.config.js

-6
This file was deleted.

webpack-prod.config.js

-5
This file was deleted.

webpack.config-helper.js

-91
This file was deleted.

webpack/polyfills.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import 'babel-polyfill';

webpack/webpack.common.js

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
'use strict';
2+
3+
const Path = require('path');
4+
const CleanWebpackPlugin = require('clean-webpack-plugin');
5+
const CopyWebpackPlugin = require('copy-webpack-plugin');
6+
const Webpack = require('webpack');
7+
const HtmlWebpackPlugin = require('html-webpack-plugin');
8+
9+
const dest = Path.join(__dirname, '../dist');
10+
11+
module.exports = {
12+
entry: [
13+
Path.resolve(__dirname, './polyfills'),
14+
Path.resolve(__dirname, '../src/scripts/index')
15+
],
16+
output: {
17+
path: dest,
18+
filename: 'bundle.[hash].js'
19+
},
20+
plugins: [
21+
new CleanWebpackPlugin([dest]),
22+
new CopyWebpackPlugin([
23+
{ from: Path.resolve(__dirname, '../public'), to: 'public' }
24+
]),
25+
new HtmlWebpackPlugin({
26+
template: Path.resolve(__dirname, '../src/index.html')
27+
})
28+
],
29+
resolve: {
30+
alias: {
31+
'~': Path.resolve(__dirname, '../src')
32+
}
33+
},
34+
module: {
35+
rules: [
36+
{
37+
test: /\.(ico|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2)(\?.*)?$/,
38+
use: {
39+
loader: 'file-loader',
40+
options: {
41+
name: '[path][name].[ext]'
42+
}
43+
}
44+
}
45+
]
46+
}
47+
};

0 commit comments

Comments
 (0)