-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.js
96 lines (86 loc) · 2.39 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
const path = require('path');
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const common = {
mode: 'development',
module: {
rules: [{
test: /\.js$/,
include: [
path.resolve(__dirname, 'src'),
path.resolve(__dirname, 'test')
],
exclude: /node_modules/,
use: ['babel-loader']
}, {test: /\.(woff2?|svg)$/, loader: 'url-loader?limit=10000'},
{test: /\.(ttf|eot)$/, loader: 'file-loader'},
{test: /\.css$/, use: ['style-loader', 'css-loader']},
{
test: /\.html$/,
include: path.join(__dirname, 'web'),
use: ['html-loader']
}
]
},
resolve: {
modules: [
"node_modules",
path.resolve('./src'),
path.resolve('./web')
]
},
devServer: {
contentBase: "./dist",
headers: {
'Access-Control-Allow-Origin': '*'
}
}
};
const frontend = {
entry: ['./src/frontend.js'],
plugins: [
new CopyWebpackPlugin([{
from: path.resolve('./web')
}]),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
Popper: ['popper.js', 'default'],
})
],
output: {
filename: 'frontend.js',
path: __dirname + '/dist'
}
};
const fs = require('fs');
const nodeModules = {};
fs.readdirSync(path.resolve(__dirname, 'node_modules'))
.filter(x => ['.bin'].indexOf(x) === -1)
.forEach(mod => { nodeModules[mod] = `commonjs ${mod}`; });
const backend = {
entry: {
backend: ['./src/backend.js']
},
target: 'node',
node: {
__dirname: false,
__filename: false,
},
externals: nodeModules,
output: {
filename: 'backend.js',
path: path.resolve(__dirname, 'dist')
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
koa: 'koa'
})
]
};
module.exports = [
Object.assign({}, common, frontend),
Object.assign({}, common, backend)
];