forked from code-troopers/code-troopers.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.conf.js
More file actions
157 lines (156 loc) · 4.33 KB
/
webpack.conf.js
File metadata and controls
157 lines (156 loc) · 4.33 KB
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
150
151
152
153
154
155
156
157
import webpack from 'webpack';
import glob from 'glob';
import path from 'path';
import postCSS from './config/postcss';
import cssNano from './config/cssnano';
import fs from 'fs-extra';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import ManifestPlugin from 'webpack-manifest-plugin';
import ManifestReplacePlugin from 'webpack-manifest-replace-plugin';
import EventHooksPlugin from 'event-hooks-webpack-plugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import SuppressChunksPlugin from 'suppress-chunks-webpack-plugin';
export default function() {
const optimizePlugins = [
new webpack.optimize.UglifyJsPlugin(),
new ExtractTextPlugin('styles.[hash:4].css'),
new ManifestPlugin(),
new ManifestReplacePlugin({
basedir: path.resolve(__dirname, 'dist'),
src: '**/*.html',
manifestFilename: 'manifest.json'
}),
new SuppressChunksPlugin(['img', 'html'])
];
const cssLoaders = [
{ loader: 'css-loader', options: Object.assign({ minimize: {discardComments: { removeAll: true }}, sourceMap: true }, cssNano) },
{ loader: 'postcss-loader', options: Object.assign({ sourceMap: true }, postCSS) },
{ loader: 'resolve-url-loader', options: { sourceMap: true } },
{ loader: 'sass-loader', options: { sourceMap: true } }
];
return {
devtool: 'source-map',
module: {
rules: [
{
test: /\.(gif|png|jpe?g)$/i,
use: [
{
loader: 'url-loader',
options: {
limit: 6144,
fallback: 'file-loader',
name: '[path][name].[hash:4].[ext]'
}
}
]
},
{
test: /\.((svg)|(mp4)|(webm))(\?v=\d+\.\d+\.\d+)?$/,
loader: 'file-loader?name=[path][name].[hash:4].[ext]'
},
{
test: /\.((eot)|(woff)|(woff2)|(ttf))(\?v=\d+\.\d+\.\d+)?$/,
loader: 'file-loader?name=[name].[hash:4].[ext]'
},
{
test: /\.json$/,
loader: 'json-loader'
},
{
test: /\.js?$/,
exclude: /node_modules\/(?!(dom7|swiper)\/).*/,
loaders: [
'babel-loader'
]
},
{
test: /\.html$/,
loader: 'file-loader?name=[path][name].[ext]!lozad-loader!extract-loader!html-loader?attrs[]=:data-src&attrs[]=img:src'
},
{
test: /\.(scss|sass)?$/,
use: ExtractTextPlugin.extract({ use: cssLoaders })
}
]
},
context: path.join(__dirname, '.tmp'),
entry: function() { //eslint-disable-line object-shorthand
const js = ['./js/app.js'];
const img = glob.sync('./img/**/*', {
absolute: true,
cwd: this.context,
matchBase: true,
nodir: true,
nosort: true
});
const postsImg = glob.sync('./images/**/*', {
absolute: true,
cwd: this.context,
matchBase: true,
nodir: true,
nosort: true
});
const html = glob.sync('./**/*.html', {
absolute: true,
cwd: this.context,
matchBase: true,
nodir: true,
nosort: true
});
return {
main: [...js],
img: [...img, ...postsImg],
html: [...html],
blog: './js/blog.js'
};
},
output: {
path: path.join(__dirname, './dist'),
publicPath: '/',
filename: '[name].[chunkhash:6].js',
},
plugins: [
new EventHooksPlugin({
'before-run': (compilation, done) => {
fs.copy('src', '.tmp', done);
}
}),
new CopyWebpackPlugin([
{
from: 'favicon.ico',
to: '../dist/favicon.ico'
},
{
from: '.nojekyll',
to: '../dist/'
},
{
from: 'audio',
to: '../dist/audio'
},
{
from: 'files',
to: '../dist/files'
},
{
from: 'videos',
to: '../dist/videos'
},
]),
new webpack.ProvidePlugin({
fetch: 'imports-loader?this=>global!exports-loader?global.fetch!whatwg-fetch'
}),
...optimizePlugins
],
resolve: {
modules: [
path.resolve('src'),
'node_modules'
]
},
resolveLoader: {
modules: ['node_modules', path.resolve(__dirname, 'loaders')]
}
};
}