-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
166 lines (155 loc) · 4.08 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
'use strict';
const webpack = require('webpack');
const path = require('path');
// * * configuration/structure/folders * * //
const conf = require('./conf');
// running 'npm run build' makes this variable false
const IS_DEV = (process.env.NODE_ENV === 'dev');
// ** glob is a plugin to loop through multiple templates **//
const glob = require('glob');
// ** Sass Autoprefixer **//
const autoprefixer = require('autoprefixer');
//** HtmlWebpackPlugin compatible with latest webpack 4.4.1, for generating result html **//
const HtmlWebpackPlugin = require('html-webpack-plugin');
// * * ExtractText plugin compatible with latest webpack 4.4.1, to play with strings * * //
const ExtractTextPlugin = require('extract-text-webpack-plugin');
/* To Inject Inline Stylesheet into the Html if needed */
const StyleExtHtmlWebpackPlugin = require('style-ext-html-webpack-plugin');
// * * Transforms <img src="*.svg"> to inline <svg> (svgo options are present) * * //
const HtmlWebpackInlineSVGPlugin = require('html-webpack-inline-svg-plugin');
/**
* Helper function to get *.ejs filename when looping, which
* returns '[name].ejs' as string
**/
const getNameFromDir = (dir) => {
const lastSlash = dir.lastIndexOf('/');
return dir.slice(lastSlash + 1);
};
/**
* Function to loop through all templates/files (*.ejs)
*/
const generateHTMLPlugins = () =>
glob.sync('./src/*.ejs').map(function(dir) {
return new HtmlWebpackPlugin({
template: path.resolve(conf.dirSrc, getNameFromDir(dir)),
});
});
/**
* Webpack Configuration
*/
module.exports = {
target: 'web',
node: {
fs: 'empty',
},
entry: {
vendor: path.join(conf.dirSrc, 'scripts/vendor.js'),
common: path.join(conf.dirSrc, 'scripts/common.js'),
},
output: {
path: path.join(__dirname, 'dist'),
filename: '[name].js',
},
resolve: {
modules: [
conf.dirSrc,
conf.dirNode,
conf.dirImages,
conf.dirFonts,
],
alias: {
'@': path.resolve(__dirname, 'node_modules'),
'~': path.resolve(__dirname, 'node_modules'),
},
},
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules)/,
loader: 'babel-loader',
},
// SCSS
{
test: /\.scss$/,
exclude: /(node_modules)/,
use: ExtractTextPlugin.extract({
use: [
{
loader: 'css-loader',
options: {
sourceMap: IS_DEV,
},
},
{
loader: 'resolve-url-loader',
options: {
sourceMap: IS_DEV,
root: conf.dirSrc,
},
},
{
loader: 'postcss-loader',
options: {
sourceMap: IS_DEV,
plugins: [
autoprefixer({browsers: ['last 3 versions', 'iOS 9']}),
],
},
},
{
loader: 'sass-loader',
options: {
sourceMap: IS_DEV,
},
}],
// use style-loader in development
fallback: {
loader: 'style-loader',
},
publicPath: '/headers/denver/',
}),
},
// IMAGES
{
test: /\.(gif|png|jpe?g)/,
loader: 'file-loader',
exclude: /(node_modules)/,
options: {
name: '[name].[ext]',
outputPath: './images/',
},
},
// FONTS
{
test: /\.(ttf|eot|woff|woff2|svg)/,
loader: 'file-loader',
exclude: /(node_modules)/,
options: {
name: '[name].[ext]',
outputPath: './fonts/',
},
},
],
},
plugins: [
new webpack.DefinePlugin({
IS_DEV: IS_DEV,
}),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
}),
new ExtractTextPlugin({
filename: 'styles/[name].css',
disable: IS_DEV,
}),
...generateHTMLPlugins(),
new HtmlWebpackInlineSVGPlugin(),
],
stats: {
colors: true,
},
devtool: 'eval',
};