Skip to content

Commit

Permalink
refactor(webpack): update webpack configs
Browse files Browse the repository at this point in the history
  • Loading branch information
stefankeil committed Jun 22, 2018
1 parent 4b700cb commit 6a0db0d
Show file tree
Hide file tree
Showing 13 changed files with 273 additions and 114 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
*.log
npm-debug.log*
dist
node_modules
node_modules
.DS_Store
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ A lightweight foundation for your next webpack based frontend project.
npm install
```

### Start Dev Server
### Start Dev Server

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

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.
122 changes: 122 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"version": "1.0.0",
"description": "A light foundation for your next frontend project based on webpack.",
"scripts": {
"build": "webpack --config webpack-prod.config.js --colors",
"dev": "webpack-dev-server --open --config webpack-dev.config.js --watch --colors"
"build": "webpack --config webpack/webpack.config.prod.js --colors",
"dev": "webpack-dev-server --open --config webpack/webpack.config.dev.js"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -36,24 +36,31 @@
"semi": 2
}
},
"babel": {
"presets": [
"es2015"
]
},
"homepage": "https://github.com/wbkd/yet-another-webpack-es6-starterkit#readme",
"devDependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-preset-es2015": "^6.24.1",
"clean-webpack-plugin": "^0.1.19",
"copy-webpack-plugin": "^4.5.1",
"css-loader": "^0.28.11",
"eslint": "^4.19.1",
"eslint-loader": "^2.0.0",
"extract-text-webpack-plugin": "^4.0.0-beta.0",
"file-loader": "^1.1.11",
"html-webpack-plugin": "^3.2.0",
"node-sass": "^4.9.0",
"sass-loader": "^6.0.7",
"style-loader": "^0.18.2",
"uglifyjs-webpack-plugin": "^1.2.5",
"webpack": "^4.12.0",
"webpack-cli": "^2.1.5",
"webpack-dev-server": "^3.1.4"
"webpack-dev-server": "^3.1.4",
"webpack-merge": "^4.1.3"
},
"dependencies": {
"babel-polyfill": "^6.9.0"
Expand Down
Empty file added public/.gitkeep
Empty file.
5 changes: 0 additions & 5 deletions src/scripts/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
'use strict';

if (module.hot) {
module.hot.accept();
}

import '../styles/index.scss';
6 changes: 0 additions & 6 deletions webpack-dev.config.js

This file was deleted.

5 changes: 0 additions & 5 deletions webpack-prod.config.js

This file was deleted.

91 changes: 0 additions & 91 deletions webpack.config-helper.js

This file was deleted.

1 change: 1 addition & 0 deletions webpack/polyfills.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'babel-polyfill';
47 changes: 47 additions & 0 deletions webpack/webpack.common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict';

const Path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const Webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');

const dest = Path.join(__dirname, '../dist');

module.exports = {
entry: [
Path.resolve(__dirname, './polyfills'),
Path.resolve(__dirname, '../src/scripts/index')
],
output: {
path: dest,
filename: 'bundle.[hash].js'
},
plugins: [
new CleanWebpackPlugin([dest]),
new CopyWebpackPlugin([
{ from: Path.resolve(__dirname, '../public'), to: 'public' }
]),
new HtmlWebpackPlugin({
template: Path.resolve(__dirname, '../src/index.html')
})
],
resolve: {
alias: {
'~': Path.resolve(__dirname, '../src')
}
},
module: {
rules: [
{
test: /\.(ico|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2)(\?.*)?$/,
use: {
loader: 'file-loader',
options: {
name: '[path][name].[ext]'
}
}
}
]
}
};
Loading

0 comments on commit 6a0db0d

Please sign in to comment.