forked from dprgarner/tech-radar-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
128 lines (115 loc) · 2.92 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
'use strict'
const path = require('path')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const postcssPresetEnv = require('postcss-preset-env')
const cssnano = require('cssnano')
const r = f => path.resolve(__dirname, f)
let main = [r('src/site.js')]
let common = [r('./src/common.js')]
let devtool
let plugins = [
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({ filename: '[name].[hash].css' }),
new HtmlWebpackPlugin({
template: r('./src/index.html'),
chunks: ['main'],
inject: 'body'
}),
new HtmlWebpackPlugin({
template: r('./src/error.html'),
chunks: ['common'],
inject: 'body',
filename: 'error.html'
})
]
module.exports = {
context: process.cwd(),
entry: {
'main': main,
'common': common
},
node: {
fs: 'empty',
net: 'empty',
tls: 'empty',
child_process: 'empty'
},
output: {
// Output path is set in main.js
filename: '[name].[hash].js'
},
module: {
rules: [
{
test: /\.js$/,
include: r('./src'),
use: [{ loader: require.resolve('babel-loader') }]
},
{
test: /\.scss$/,
include: r('./src'),
use: [
require.resolve('style-loader'),
MiniCssExtractPlugin.loader, {
loader: require.resolve('css-loader'),
options: { importLoaders: 1 }
},
{
loader: require.resolve('postcss-loader'),
options: {
ident: 'postcss',
plugins: () => [
postcssPresetEnv({ browsers: 'last 2 versions' }),
cssnano({ preset: ['default', { discardComments: { removeAll: true } }] })
]
}
},
require.resolve('sass-loader')
]
},
{
test: /\.(eot|svg|ttf|woff|woff2)$/,
loader: require.resolve('file-loader'),
options: {
name: 'images/[name].[ext]'
}
},
{
test: /\.(png|jpg|ico)$/,
include: r('./src'),
use: [{
loader: require.resolve('file-loader'),
options: {
name: 'images/[name].[ext]',
context: r('./src/images')
}
}]
},
{
test: require.resolve('jquery'),
use: [
{ loader: require.resolve('expose-loader'), options: 'jQuery' },
{ loader: require.resolve('expose-loader'), options: '$' }
]
},
{
test: r('./src/data'),
use: {
loader: require.resolve('val-loader'),
options: {
// This is only used by webpack-dev-server, and is overridden in index.js
data: require('./example-data.json')
}
}
}
]
},
plugins: plugins,
devtool: devtool,
devServer: {
host: '0.0.0.0',
port: 8080
}
}