Skip to content

Commit 82b45df

Browse files
committed
update webpack
1 parent 4643626 commit 82b45df

File tree

11 files changed

+152
-110
lines changed

11 files changed

+152
-110
lines changed

.gitignore

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ build/Release
3636
node_modules/
3737
jspm_packages/
3838

39-
# Typescript v1 declaration files
39+
# TypeScript v1 declaration files
4040
typings/
4141

4242
# Optional npm cache directory
@@ -57,5 +57,20 @@ typings/
5757
# dotenv environment variables file
5858
.env
5959

60-
# build
61-
build/public
60+
# parcel-bundler cache (https://parceljs.org/)
61+
.cache
62+
63+
# next.js build output
64+
.next
65+
66+
# nuxt.js build output
67+
.nuxt
68+
69+
# vuepress build output
70+
.vuepress/dist
71+
72+
# Serverless directories
73+
.serverless
74+
75+
# webpack build output
76+
dist

package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
"src"
1313
],
1414
"scripts": {
15-
"dev": "webpack-dev-server --env.env=dev",
1615
"build": "webpack --env.env=prod",
17-
"lint": "eslint statik/**/*.js"
16+
"lint": "eslint statik/**/*.js",
17+
"start": "webpack-dev-server --env.env=dev"
1818
},
1919
"repository": {
2020
"type": "git",
@@ -35,10 +35,14 @@
3535
"eslint-config-prettier": "2.9.0",
3636
"eslint-plugin-prettier": "2.6.1",
3737
"file-loader": "1.1.11",
38-
"imagemin-webpack-plugin": "2.1.5",
38+
"html-loader": "0.5.5",
39+
"html-webpack-plugin": "3.2.0",
40+
"image-webpack-loader": "4.3.1",
3941
"mini-css-extract-plugin": "0.4.0",
42+
"optimize-css-assets-webpack-plugin": "4.0.2",
4043
"postcss-loader": "2.1.5",
4144
"prettier": "1.13.6",
45+
"style-loader": "0.21.0",
4246
"uglifyjs-webpack-plugin": "1.2.7",
4347
"webpack": "4.12.1",
4448
"webpack-cli": "3.0.8",

build/index.html renamed to statik/index.html

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,16 @@
88

99
<title>Statik Starter Kit</title>
1010

11-
<link rel="shortcut icon" type="image/x-icon" href="public/images/favicon.ico" />
12-
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700" rel="stylesheet">
11+
<link rel="shortcut icon" type="image/x-icon" href="images/favicon.ico" />
1312
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css" integrity="sha256-oSrCnRYXvHG31SBifqP2PM1uje7SJUyX0nTwO2RJV54="
1413
crossorigin="anonymous" />
15-
<link rel="stylesheet" href="public/vendor.bundle.css">
16-
<link rel="stylesheet" href="public/app.bundle.css">
1714
</head>
1815

1916
<body>
2017
<header class="header">
2118
<nav class="navbar">
2219
<a class="navbar__brand" href="/">
23-
<img src="public/images/logo.png" alt="Statik Logo">
20+
<img src="images/logo.png" alt="Statik Logo">
2421
<span>Statik</span>
2522
</a>
2623
<ul class="navbar__social">
@@ -83,9 +80,6 @@ <h2>Features</h2>
8380
</p>
8481
</section>
8582
</main>
86-
87-
<script src="public/vendor.bundle.js"></script>
88-
<script src="public/app.bundle.js"></script>
8983
</body>
9084

9185
</html>

statik/scripts/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ import '../styles/app.css';
33
import '../images/logo.png';
44
import '../images/favicon.ico';
55

6-
console.log('JavaScript is running...');
6+
console.log('App is running...');

statik/scripts/vendor.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
import '../styles/vendor.css';
2+
3+
console.log('Vendor is running...');
Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
const CleanWebpackPlugin = require('clean-webpack-plugin');
2+
const HtmlWebpackPlugin = require('html-webpack-plugin');
23
const path = require('path');
34

45
module.exports = {
56
entry: {
6-
vendor: path.resolve('statik', 'scripts', 'vendor.js'),
7-
app: path.resolve('statik', 'scripts', 'app.js')
7+
app: './statik/scripts/app.js',
8+
vendor: './statik/scripts/vendor.js'
89
},
910
output: {
1011
filename: '[name].bundle.js',
11-
path: path.resolve('build', 'public')
12+
path: path.resolve('dist')
1213
},
1314
module: {
1415
rules: [
@@ -34,26 +35,13 @@ module.exports = {
3435
}
3536
}
3637
]
37-
},
38-
{
39-
test: /\.(gif|jpg|png|svg|ico)$/,
40-
use: [
41-
{
42-
loader: 'file-loader',
43-
options: {
44-
name: '[name].[ext]',
45-
useRelativePath: true
46-
}
47-
}
48-
]
4938
}
5039
]
5140
},
52-
optimization: {
53-
splitChunks: {
54-
chunks: 'all',
55-
name: true
56-
}
57-
},
58-
plugins: [new CleanWebpackPlugin([path.resolve('build', 'public')])]
41+
plugins: [
42+
new CleanWebpackPlugin(['dist']),
43+
new HtmlWebpackPlugin({
44+
template: './statik/index.html'
45+
})
46+
]
5947
};

webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = (env) => {
2-
const config = require(`./webpack/webpack.${env.env}`);
2+
const config = require(`./webpack.${env.env}`);
33

44
return config;
55
};

webpack.dev.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const merge = require('webpack-merge');
2+
const path = require('path');
3+
4+
const common = require('./webpack.common');
5+
6+
module.exports = merge(common, {
7+
mode: 'development',
8+
devtool: 'eval',
9+
module: {
10+
rules: [
11+
{
12+
test: /\.html$/,
13+
use: 'html-loader'
14+
},
15+
{
16+
test: /\.css$/,
17+
use: ['style-loader', 'css-loader']
18+
},
19+
{
20+
test: /\.(gif|jpg|png|svg|ico)$/,
21+
include: path.resolve(__dirname, 'statik/images'),
22+
use: ['file-loader']
23+
}
24+
]
25+
},
26+
devServer: {
27+
contentBase: path.resolve(__dirname, 'dist'),
28+
open: true,
29+
port: 8080
30+
}
31+
});

webpack.prod.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
const autoprefixer = require('autoprefixer');
2+
const merge = require('webpack-merge');
3+
const path = require('path');
4+
const webpack = require('webpack');
5+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
6+
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
7+
const UglifyJsWebpackPlugin = require('uglifyjs-webpack-plugin');
8+
9+
const common = require('./webpack.common');
10+
11+
module.exports = merge(common, {
12+
mode: 'production',
13+
devtool: 'source-map',
14+
module: {
15+
rules: [
16+
{
17+
test: /\.html$/,
18+
use: {
19+
loader: 'html-loader',
20+
options: {
21+
minimize: true
22+
}
23+
}
24+
},
25+
{
26+
test: /\.css$/,
27+
use: [
28+
MiniCssExtractPlugin.loader,
29+
{
30+
loader: 'css-loader',
31+
options: { importLoaders: 1 }
32+
},
33+
{
34+
loader: 'postcss-loader',
35+
options: {
36+
plugins: () => [autoprefixer()]
37+
}
38+
}
39+
]
40+
},
41+
{
42+
test: /\.(gif|jpg|png|svg|ico)$/,
43+
include: path.resolve(__dirname, 'statik/images'),
44+
use: [
45+
{
46+
loader: 'file-loader',
47+
options: {
48+
name: '[name].[ext]',
49+
useRelativePath: true
50+
}
51+
},
52+
'image-webpack-loader'
53+
]
54+
}
55+
]
56+
},
57+
optimization: {
58+
splitChunks: {
59+
chunks: 'all',
60+
name: true
61+
},
62+
minimizer: [
63+
new OptimizeCSSAssetsPlugin({
64+
cssProcessorOptions: { discardUnused: false }
65+
})
66+
]
67+
},
68+
plugins: [
69+
new MiniCssExtractPlugin({
70+
filename: '[name].bundle.css',
71+
chunkFilename: '[id].css'
72+
}),
73+
new UglifyJsWebpackPlugin({
74+
sourceMap: true
75+
}),
76+
new webpack.DefinePlugin({
77+
'process.env.NODE_ENV': JSON.stringify('production')
78+
})
79+
]
80+
});

webpack/webpack.dev.js

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

0 commit comments

Comments
 (0)