-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
149 lines (143 loc) · 3.55 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
const path = require('path');
const fs = require('fs');
// const webpack = require('webpack');
const fm = require('front-matter');
const marked = require('marked');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const moment = require('moment');
const IS_PROD = process.env.NODE_ENV === 'production';
// POST GENERATION SECTION
const posts = fs.readdirSync('./posts/');
const postsData = posts
.map(post => ({
...fm(fs.readFileSync(`./posts/${post}`, 'utf8')),
filename: post.split('.')[0],
template: 'post',
lang: 'en',
}))
.map(post => ({
...post,
content: marked(post.body),
short: marked(post.body.split('\n', 3).join('\n')),
}))
.sort((a, b) => {
const dateA = moment(a.attributes.date, 'D-M-Y');
const dateB = moment(b.attributes.date, 'D-M-Y');
return dateA.diff(dateB);
});
// CONFIG
const config = {
entry: './src/main.js',
output: {
path: path.resolve(__dirname, './dist'),
publicPath: '/',
filename: 'build.js',
},
module: {
rules: [
{
enforce: 'post',
test: /\.css$/,
loader: IS_PROD ? ExtractTextPlugin.extract({
fallback: 'style-loader',
use: 'css-loader',
}) : 'style-loader!css-loader?sourceMap',
}, {
enforce: 'pre',
test: /\.(js)$/,
loader: 'eslint-loader',
options: {
emitWarning: true,
failOnError: false,
failOnWarning: false,
},
exclude: /node_modules/,
}, {
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
}, {
test: /\.(png|jpg|gif|otf|svg)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]?[hash]',
},
}, {
test: /\.(html)$/,
use: {
loader: 'html-loader',
options: {
interpolate: true,
},
},
},
],
},
resolve: {
modules: ['node_modules', 'src'],
extensions: ['*', '.js', '.json'],
},
devServer: {
historyApiFallback: true,
noInfo: true,
overlay: true,
},
performance: {
hints: false,
},
devtool: '#eval-source-map',
plugins: [
new CopyWebpackPlugin([{ from: 'public' }]),
new FaviconsWebpackPlugin('./src/assets/logo.svg'),
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'src/index.ejs',
templateParameters: {
lang: 'en',
template: 'about',
postsData,
},
}),
new HtmlWebpackPlugin({
filename: 'token/index.html',
template: 'src/index.ejs',
templateParameters: {
lang: 'en',
template: 'token',
postsData,
},
}),
new HtmlWebpackPlugin({
filename: 'solutions/index.html',
template: 'src/index.ejs',
templateParameters: {
lang: 'en',
template: 'solutions',
postsData,
},
}),
new HtmlWebpackPlugin({
filename: 'posts/index.html',
template: 'src/posts.ejs',
templateParameters: {
lang: 'en',
template: 'posts',
postsData,
},
}),
...postsData.map(post => new HtmlWebpackPlugin({
filename: `posts/${post.filename}/index.html`,
template: 'src/post.ejs',
templateParameters: post,
})),
],
};
if (IS_PROD) {
config.plugins.push(
new ExtractTextPlugin('bundle.css'),
);
}
module.exports = config;