-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
executable file
·121 lines (112 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
/**
* WEBPACK CONFIGURATION
*/
const path = require('path');
// include the js minification plugin
const uglifyJSPlugin = require('uglifyjs-webpack-plugin');
const webpackBuildNotifierPlugin = require('webpack-build-notifier');
// include the css extraction and minification plugins
const miniCssExtractPlugin = require("mini-css-extract-plugin");
const optimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
// include webpack variables
const webpackVariables = require('./webpack.variables');
module.exports = {
entry: webpackVariables.webpackParams['entryPath'],
output: {
filename: webpackVariables.webpackParams['jsOutputPath'],
path: path.resolve(__dirname),
},
module: {
rules: [
// perform js babelization on all .js files
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ['babel-preset-env']
}
}
},
// inject CSS to page
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
// compile all .scss files to plain old css
{
test: /\.(sass|scss)$/,
use: [
miniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
sourceMap: true,
},
},
{
loader: 'resolve-url-loader',
options: {
sourceMap: true,
},
},
{
loader: 'postcss-loader',
options: {
sourceMap: true,
config: {
path: 'postcss.config.js'
}
},
},
{
loader: 'sass-loader',
options: {
sourceMap: true
}
}
]
},
// Define fonts and images url from theme dir
{
test: /\.(png|svg|jpg|gif)$/,
loader: 'file-loader',
options: {
publicPath: '../../../',
name: '[path][name].[ext]',
}
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
loader: 'file-loader',
options: {
publicPath: '../../../',
name: '[path][name].[ext]',
}
},
]
},
plugins: [
// extract css into dedicated file
new miniCssExtractPlugin({
filename: webpackVariables.webpackParams['cssOutputPath'],
}),
// notifier plugin
new webpackBuildNotifierPlugin({
title: "My Project Webpack Build",
suppressSuccess: true
}),
],
optimization: {
minimizer: [
// enable the js minification plugin
new uglifyJSPlugin({
cache: true,
parallel: true
}),
// enable the css minification plugin
new optimizeCSSAssetsPlugin({})
]
}
};