Skip to content

Commit 2c91879

Browse files
authored
Merge pull request #35 from SoldierCorp/webpack-5
Webpack 5 is now supported! #20
2 parents 4fe4f8d + ba7b4f4 commit 2c91879

File tree

12 files changed

+3944
-3429
lines changed

12 files changed

+3944
-3429
lines changed

.babelrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"presets": [
3-
"env"
3+
"@babel/preset-env"
44
],
55
"plugins": [
66
[

.nvmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
12.22.1
1+
14.17.0

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
Webpack project starter with Pug, Sass/Stylus, jQuery, VanillaJS, Babel and Yarn
2-
===================
2+
3+
---
4+
5+
## Now working with Webpack 5 🎉
6+
You can still use Webpack 4 by downloading [this branch](https://github.com/SoldierCorp/webpack-starter-pug-sass-es6-jquery/tree/webpack-4)
7+
8+
---
39

410
The purpose of this Webpack Starter is to allow people to create websites without any framework/library like React, Angular, Vue but only using simple but powerful technologies to build quality websites.
511

build/utils.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ exports.pages = function (env, folder = '') {
33
const HtmlWebpackPlugin = require('html-webpack-plugin')
44
const fs = require('fs')
55
const path = require('path')
6-
const viewsFolder = path.resolve(__dirname, `../src/views/${rootPagesFolderName}/${folder}`)
6+
const viewsFolder = path.join(__dirname, `../src/views/${rootPagesFolderName}/${folder}`)
77

88
var pages = []
99

@@ -14,6 +14,7 @@ exports.pages = function (env, folder = '') {
1414
const viewName = view.split('.')[0];
1515
const fileName = folder === '' ? `${viewName}/index.html` : `${folder}/${viewName}/index.html`;
1616
const options = {
17+
minify: !env === 'development',
1718
filename: fileName,
1819
template: `views/${rootPagesFolderName}/${folder}/${view}`,
1920
inject: true

build/webpack.config.js

+42-30
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,45 @@
11
// Libraries
2+
require('../postcss.config');
3+
24
const path = require('path');
35
const webpack = require('webpack');
46
const HtmlWebpackPlugin = require('html-webpack-plugin');
57
const WebpackNotifierPlugin = require('webpack-notifier');
68
const CopyWebpackPlugin = require('copy-webpack-plugin');
79
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
810
const TerserPlugin = require('terser-webpack-plugin');
11+
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
12+
13+
const ASSET_PATH = process.env.ASSET_PATH || '/';
14+
915

1016
// Files
1117
const utils = require('./utils')
12-
const plugins = require('../postcss.config');
1318

1419
// Configuration
1520
module.exports = env => {
1621

1722
return {
18-
context: path.resolve(__dirname, '../src'),
23+
context: path.join(__dirname, '../src'),
1924
entry: {
20-
app: './app.js'
25+
app: path.join(__dirname, '../src/app.js'),
2126
},
2227
output: {
23-
path: path.resolve(__dirname, '../dist'),
24-
filename: 'assets/js/[name].[hash:7].bundle.js'
28+
publicPath: ASSET_PATH,
29+
path: path.join(__dirname, '../dist'),
30+
filename: 'assets/js/[name].[contenthash:7].bundle.js'
2531
},
2632
devServer: {
27-
contentBase: path.resolve(__dirname, '../src'),
33+
contentBase: path.join(__dirname, '../src'),
34+
compress: true,
35+
open: true
2836
},
2937
resolve: {
3038
extensions: ['.js'],
3139
alias: {
32-
source: path.resolve(__dirname, '../src'), // Relative path of src
33-
images: path.resolve(__dirname, '../src/assets/images'), // Relative path of images
34-
fonts: path.resolve(__dirname, '../src/assets/fonts'), // Relative path of fonts
40+
source: path.join(__dirname, '../src'), // Relative path of src
41+
images: path.join(__dirname, '../src/assets/images'), // Relative path of images
42+
fonts: path.join(__dirname, '../src/assets/fonts'), // Relative path of fonts
3543
}
3644
},
3745

@@ -41,12 +49,12 @@ module.exports = env => {
4149
module: {
4250
rules: [
4351
{
44-
test: /\.js$/,
52+
test: /\.m?js$/,
4553
exclude: [/node_modules/],
4654
use: [
4755
{
4856
loader: 'babel-loader',
49-
options: { presets: ['es2015'] }
57+
options: { presets: ['@babel/preset-env'] }
5058
}
5159
]
5260
},
@@ -69,7 +77,7 @@ module.exports = env => {
6977
test: /\.scss$/,
7078
use: [
7179
env === 'development' ? 'style-loader' : MiniCssExtractPlugin.loader, // creates style nodes from JS strings
72-
{ loader: 'css-loader', options: { importLoaders: 1, minimize: true, sourceMap: true, colormin: false } }, // translates CSS into CommonJS
80+
{ loader: 'css-loader', options: { importLoaders: 1, sourceMap: true } }, // translates CSS into CommonJS
7381
'postcss-loader',
7482
'sass-loader', // compiles Sass to CSS
7583
],
@@ -87,41 +95,42 @@ module.exports = env => {
8795
loader: 'url-loader',
8896
options: {
8997
limit: 3000,
90-
name: 'assets/images/[name].[hash:7].[ext]'
98+
name: 'assets/images/[name].[contenthash:7].[ext]'
9199
}
92100
},
93101
{
94102
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
95103
loader: 'url-loader',
96104
options: {
97-
name: 'assets/fonts/[name].[hash:7].[ext]'
105+
limit: 5000,
106+
name: 'assets/fonts/[name].[contenthash:7].[ext]'
98107
}
99108
},
100-
{
109+
/* {
101110
test: /\.(mp4)(\?.*)?$/,
102111
loader: 'url-loader',
103112
options: {
104113
limit: 10000,
105-
name: 'assets/videos/[name].[hash:7].[ext]'
114+
name: 'assets/videos/[name].[contenthash:7].[ext]'
106115
}
107-
}
116+
} */
108117
]
109118
},
110119
optimization: {
120+
minimize: true,
111121
minimizer: [
112122
new TerserPlugin({
113-
cache: true,
114123
parallel: true,
115-
sourceMap: true,
116124
}),
125+
new OptimizeCSSAssetsPlugin({})
117126
],
118127
splitChunks: {
119128
cacheGroups: {
120129
default: false,
121130
vendors: false,
122131
// vendor chunk
123132
vendor: {
124-
filename: 'assets/js/vendor.[hash:7].bundle.js',
133+
filename: 'assets/js/vendor.[chunkhash:7].bundle.js',
125134
// sync + async chunks
126135
chunks: 'all',
127136
// import file path containing node_modules
@@ -132,30 +141,33 @@ module.exports = env => {
132141
},
133142

134143
plugins: [
135-
new CopyWebpackPlugin([
136-
{ from: '../manifest.json', to: 'manifest.json' },
137-
{ from: '../browserconfig.xml', to: 'browserconfig.xml' },
138-
{ from: 'assets/images/favicons/android-chrome-192x192.png', to: 'assets/images/android-chrome-192x192.png' },
139-
{ from: 'assets/images/favicons/android-chrome-256x256.png', to: 'assets/images/android-chrome-256x256.png' },
140-
{ from: 'assets/images/favicons/mstile-150x150.png', to: 'assets/images/mstile-150x150.png' }
141-
]),
144+
new CopyWebpackPlugin({
145+
patterns: [
146+
{ from: '../manifest.json', to: 'manifest.json' },
147+
{ from: '../browserconfig.xml', to: 'browserconfig.xml' },
148+
{ from: 'assets/images/favicons/android-chrome-192x192.png', to: 'assets/images/android-chrome-192x192.png' },
149+
{ from: 'assets/images/favicons/android-chrome-256x256.png', to: 'assets/images/android-chrome-256x256.png' },
150+
{ from: 'assets/images/favicons/mstile-150x150.png', to: 'assets/images/mstile-150x150.png' }
151+
]
152+
}),
142153
new MiniCssExtractPlugin({
143-
filename: 'assets/css/[name].[hash:7].bundle.css',
154+
filename: 'assets/css/[name].[chunkhash:7].bundle.css',
144155
chunkFilename: '[id].css',
145156
}),
146157

147158
/*
148159
Pages
149160
*/
150161

151-
// // Desktop page
162+
// Desktop page
152163
new HtmlWebpackPlugin({
164+
minify: !env === 'development',
153165
filename: 'index.html',
154166
template: 'views/index.pug',
155167
inject: true
156168
}),
157169

158-
...utils.pages(env),
170+
...utils.pages(env), // env, public path, parent folder
159171
...utils.pages(env, 'blog'),
160172

161173
new webpack.ProvidePlugin({

package.json

+38-37
Original file line numberDiff line numberDiff line change
@@ -12,51 +12,52 @@
1212
"license": "MIT",
1313
"scripts": {
1414
"test": "echo \"Error: no test specified\" && exit 1",
15-
"build": "rimraf dist && webpack --config ./build/webpack.config.js --env.NODE_ENV=development --mode=development --progress",
16-
"dev-network": "webpack-dev-server --config ./build/webpack.config.js --env.NODE_ENV=development --mode=development --progress --open --host 0.0.0.0",
17-
"dev": "webpack-dev-server --config ./build/webpack.config.js -env.NODE_ENV=development --mode=development --progress --open",
18-
"prod": "rimraf dist && webpack --config ./build/webpack.config.js --env.NODE_ENV=production --mode=production -p --progress "
15+
"build": "rimraf dist && webpack --config ./build/webpack.config.js --mode development --progress",
16+
"dev-network": "webpack server --config ./build/webpack.config.js --mode=development --progress --open --host 0.0.0.0",
17+
"dev": "webpack serve --config ./build/webpack.config.js --mode development --progress",
18+
"prod": "rimraf dist && webpack --config ./build/webpack.config.js --mode production --progress "
1919
},
2020
"resolutions": {
21-
"upath": "1.1.0"
21+
"upath": "1.1.1"
2222
},
2323
"devDependencies": {
24-
"autoprefixer": "^8.2.0",
25-
"babel-core": "^6.26.0",
26-
"babel-loader": "^7.1.4",
27-
"babel-plugin-module-resolver": "^3.1.0",
28-
"babel-preset-env": "^1.6.1",
24+
"@babel/core": "^7.14.3",
25+
"@babel/preset-env": "^7.14.4",
26+
"autoprefixer": "^10.2.6",
27+
"babel-loader": "^8.2.2",
28+
"babel-plugin-module-resolver": "^4.1.0",
2929
"babel-preset-es2015": "^6.24.1",
30-
"copy-webpack-plugin": "^4.5.1",
31-
"css-loader": "^0.28.11",
32-
"eslint": "^4.19.1",
30+
"copy-webpack-plugin": "^9.0.0",
31+
"css-loader": "^5.2.6",
32+
"eslint": "^7.27.0",
3333
"extract-text-webpack-plugin": "^3.0.2",
34-
"file-loader": "^1.1.11",
35-
"html-webpack-plugin": "^3.1.0",
36-
"mini-css-extract-plugin": "^0.5.0",
37-
"node-sass": "^4.13.1",
38-
"postcss": "^6.0.21",
34+
"file-loader": "^6.2.0",
35+
"html-webpack-plugin": "^5.3.1",
36+
"mini-css-extract-plugin": "^1.6.0",
37+
"node-sass": "^6.0.0",
38+
"optimize-css-assets-webpack-plugin": "^6.0.0",
39+
"postcss": "^8.3.0",
3940
"postcss-cssnext": "^3.1.0",
40-
"postcss-import": "^11.1.0",
41-
"postcss-loader": "^2.1.3",
42-
"postcss-modules": "^1.1.0",
43-
"pug": "^3.0.1",
41+
"postcss-import": "^14.0.2",
42+
"postcss-loader": "^5.3.0",
43+
"postcss-modules": "^4.0.0",
44+
"pug": "^3.0.2",
4445
"pug-loader": "^2.4.0",
45-
"rimraf": "^2.6.3",
46-
"sass-loader": "^6.0.7",
47-
"style-loader": "^0.20.3",
48-
"terser-webpack-plugin": "^1.2.2",
49-
"tslib": "^1.9.0",
50-
"url-loader": "^1.0.1",
51-
"webpack": "^4.29.5",
52-
"webpack-cli": "^3.2.3",
53-
"webpack-dev-server": "^3.2.0",
54-
"webpack-notifier": "^1.6.0"
46+
"rimraf": "^3.0.2",
47+
"sass-loader": "^12.0.0",
48+
"style-loader": "^2.0.0",
49+
"terser-webpack-plugin": "^5.1.3",
50+
"url-loader": "^4.1.1",
51+
"webpack": "^5.38.1",
52+
"webpack-cli": "^4.7.0",
53+
"webpack-dev-server": "^3.11.2",
54+
"webpack-notifier": "^1.13.0"
5555
},
5656
"dependencies": {
57-
"gsap": "^3.6.0",
58-
"jquery": "^3.5.0",
59-
"normalize.css": "^8.0.0",
60-
"scrollmagic": "^2.0.5"
61-
}
57+
"jquery": "^3.6.0",
58+
"normalize.css": "^8.0.1"
59+
},
60+
"browserslist": [
61+
"defaults"
62+
]
6263
}

src/views/index.pug

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ block content
1212
// Menu
1313
+menu('home')
1414

15-
//- Desktop page
15+
//- Index page
1616
section.page.home__page
1717
h1.page__title # Index page

src/views/layouts/master.pug

+8-8
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ html(lang='en')
3535

3636

3737
//- Favicons
38-
link(rel='apple-touch-icon', sizes='180x180', href=require('images/favicons/apple-touch-icon.png'))
39-
link(rel='icon', type='image/png', sizes='32x32', href=require('images/favicons/favicon-32x32.png'))
40-
link(rel='icon', type='image/png', sizes='16x16', href=require('images/favicons/favicon-16x16.png'))
41-
link(rel='shortcut icon', href=require('images/favicons/favicon.ico'))
38+
link(rel='apple-touch-icon', sizes='180x180', href=require('images/favicons/apple-touch-icon.png').default)
39+
link(rel='icon', type='image/png', sizes='32x32', href=require('images/favicons/favicon-32x32.png').default)
40+
link(rel='icon', type='image/png', sizes='16x16', href=require('images/favicons/favicon-16x16.png').default)
41+
link(rel='shortcut icon', href=require('images/favicons/favicon.ico').default)
4242

4343
//- Preload fonts
44-
link(type='font/woff', href=require('source/assets/fonts/Quicksand-Bold.woff'), rel='prefetch', as='font', crossorigin)
45-
link(type='font/woff', href=require('source/assets/fonts/Quicksand-Medium.woff'), rel='prefetch', as='font', crossorigin)
46-
link(type='font/woff', href=require('source/assets/fonts/Quicksand-Regular.woff'), rel='prefetch', as='font', crossorigin)
47-
link(type='font/woff', href=require('source/assets/fonts/Quicksand-Light.woff'), rel='prefetch', as='font', crossorigin)
44+
link(type='font/woff', href=require('source/assets/fonts/Quicksand-Bold.woff').default, rel='preload', as='font', crossorigin)
45+
link(type='font/woff', href=require('source/assets/fonts/Quicksand-Medium.woff').default, rel='preload', as='font', crossorigin)
46+
link(type='font/woff', href=require('source/assets/fonts/Quicksand-Regular.woff').default, rel='preload', as='font', crossorigin)
47+
link(type='font/woff', href=require('source/assets/fonts/Quicksand-Light.woff').default, rel='preload', as='font', crossorigin)
4848

4949
//- Title
5050
block title

src/views/pages/blog.pug

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ block content
1717
// Menu
1818
+menu('blog')
1919

20-
//- Desktop page
20+
//- BLog page
2121
section.page.blog__page
2222
h1.page__title # Blog page
2323

src/views/pages/blog/example-post.pug

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ block content
1717
// Menu
1818
+menu('blog-post')
1919

20-
//- Desktop page
20+
//- BLog post page
2121
section.page.blogpost__page
2222
h1.page__title # Blog post page

src/views/pages/contact.pug

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ block content
1717
// Menu
1818
+menu('contact')
1919

20-
//- Desktop page
20+
//- Contact page
2121
section.page.contact__page
2222
h1.page__title # Contact page

0 commit comments

Comments
 (0)