forked from thoughtworks/build-your-own-radar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.dev.js
92 lines (86 loc) · 2.43 KB
/
webpack.dev.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
const { merge } = require('webpack-merge')
const webpack = require('webpack')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const postcssPresetEnv = require('postcss-preset-env')
const cssnano = require('cssnano')
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const common = require('./webpack.common.js')
const config = require('./src/config')
const { graphConfig, uiConfig } = require('./src/graphing/config')
const featureToggles = config().development.featureToggles
const main = ['./src/site.js']
const scssVariables = []
Object.entries(graphConfig).forEach(function ([key, value]) {
scssVariables.push(`$${key}: ${value}px;`)
})
Object.entries(uiConfig).forEach(function ([key, value]) {
scssVariables.push(`$${key}: ${value}px;`)
})
Object.entries(featureToggles).forEach(function ([key, value]) {
scssVariables.push(`$${key}: ${value};`)
})
module.exports = merge(common, {
mode: 'development',
entry: { main: main },
performance: {
hints: false,
},
module: {
rules: [
{
test: /\.scss$/,
exclude: /node_modules/,
use: [
'style-loader',
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: { importLoaders: 1, modules: 'global', url: false },
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
postcssPresetEnv({ browsers: 'last 2 versions' }),
cssnano({
preset: ['default', { discardComments: { removeAll: true } }],
}),
],
},
},
},
{
loader: 'sass-loader',
options: {
additionalData: scssVariables.join('\n'),
},
},
],
},
],
},
plugins: [
new webpack.DefinePlugin({
'process.env.ENVIRONMENT': JSON.stringify('development'),
}),
// new HtmlWebpackPlugin({
// template: './src/index.html',
// }),
],
devtool: 'source-map',
devServer: {
static: {
directory: path.join(__dirname, 'src'),
},
compress: true,
port: 8080,
open: true,
onBeforeSetupMiddleware: (devServer) => {
devServer.app.get('/data/radar.csv', (req, res) => {
res.sendFile(path.join(__dirname, 'src/data/radar.csv'));
});
},
},
})