forked from associatedpress/harvester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack-dev.config.js
120 lines (117 loc) · 2.7 KB
/
webpack-dev.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
const webpack = require('webpack')
const path = require('path')
const portfinder = require('portfinder')
const glob = require('glob')
const args = require('yargs')
.default('proxy', '3000')
.default('port', '8080')
.argv
portfinder.basePort = args.port
const config = (env, argv, port) => ({
mode: 'development',
devtool: 'cheap-module-source-map',
resolve: {
modules: [
'node_modules',
'src',
],
extensions: ['.js', '.jsx'],
},
entry: glob.sync(`${path.resolve(__dirname, './src/js')}/*-app.js`).reduce((entry, file) => {
const name = path.basename(file).slice(0, -1 * '-app.js'.length)
return { ...entry, [name]: file }
}, {}),
output: {
path: path.resolve(__dirname, 'public'),
filename: '[name].js',
publicPath: '/',
},
devServer: {
index: '',
compress: true,
port,
open: true,
hot: true,
contentBase: path.join(__dirname, 'public'),
overlay: {
errors: true,
warnings: false,
},
proxy: {
context: () => true,
target: `http://localhost:${args.proxy}`,
},
},
module: {
rules: [
{
test: /\.jsx?$/,
enforce: 'pre',
loader: 'eslint-loader',
exclude: /node_modules/,
options: {
emitWarning: true,
}
},
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
['@babel/env', {
useBuiltIns: 'usage',
corejs: 3,
targets: {
browsers: 'last 2 versions',
},
}],
'@babel/react',
],
plugins: [
'@babel/proposal-class-properties',
'@babel/plugin-proposal-object-rest-spread',
],
},
},
},
{
test: /.*\.s?css$/,
sideEffects: true,
use: [
'style-loader',
'css-loader',
'resolve-url-loader',
'sass-loader',
],
},
{
test: /\.(woff|eot)$/,
use: {
loader: 'file-loader',
options: {
name: '[name].[contenthash].[ext]',
outputPath: 'fonts',
publicPath: '/fonts/',
},
},
},
{
test: /\.(png|svg|jpg|gif)$/,
use: [{
loader: 'file-loader',
options: {
name: '[name].[contenthash].[ext]',
outputPath: 'images',
publicPath: '/images/',
},
}],
},
],
},
plugins: [],
})
module.exports = (env, argv) =>
portfinder.getPortPromise()
.then(port => config(env, argv, port))