-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
141 lines (133 loc) · 3.26 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
const path = require('path');
const webpack = require('webpack');
const ReloadPlugin = require('reload-html-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');
const extractSass = new ExtractTextPlugin({
filename: '[name].css',
});
const page = name => new HtmlWebpackPlugin({
template: `src/views/pages/${name}/${name}.pug`,
inject: 'body',
title: 'App',
filename: `${name}.html`,
});
const config = {
build: './public',
src: {
views: '/src/views/',
styles: '/src/styles/',
js: '/src/js/',
},
};
module.exports = {
entry: `${path.join(__dirname, config.src.js)}main.js`,
output: {
path: path.resolve(__dirname, config.build),
filename: 'bundle.js',
},
module: {
loaders: [
{
test: /\.js$/,
use: ['babel-loader', 'eslint-loader'],
exclude: /node_modules/,
},
{
test: /\.scss$/,
use: extractSass.extract({
use: [
{
loader: 'css-loader',
options: {
minimize: true,
sourceMap: true,
},
},
{
loader: 'resolve-url-loader',
},
{
loader: `sass-loader?sourceMap=${config.src.styles}main.scss`,
},
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: () => [
autoprefixer(),
cssnano(),
],
},
},
],
fallback: 'style-loader',
}),
},
{
test: /\.(jpe?g|png|woff|gif|woff2|eot|ttf|svg|otf)(\?[a-z0-9=.]+)?$/,
loaders: [
{
loader: 'file-loader',
options: {
name: 'assets/[path][name].[ext]',
context: 'src',
},
},
],
},
{
test: /\.(pug|jade)$/,
use: [
{
loader: 'html-loader?minimize=false',
query: {
minimize: false,
collapseWhitespace: false,
conservativeCollapse: false,
},
},
{
loader: 'pug-html-loader?minimize=false',
query: {
minimize: false,
collapseWhitespace: false,
conservativeCollapse: false,
},
},
],
},
],
},
devServer: {
historyApiFallback: true,
contentBase: [config.build],
hot: true,
watchContentBase: true,
inline: true,
stats: 'errors-only',
},
plugins: [
extractSass,
page('index'),
],
};
if (process.env.NODE_ENV === 'development') {
module.exports.devtool = '#source-map';
module.exports.plugins = (module.exports.plugins || []).concat([
new webpack.HotModuleReplacementPlugin(),
new ReloadPlugin(),
]);
}
if (process.env.NODE_ENV === 'production') {
module.exports.plugins = (module.exports.plugins || []).concat([
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compress: {
warnings: false,
},
}),
]);
}