-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
139 lines (127 loc) · 3.54 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
/* eslint-disable */
var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var root_dir = path.resolve(__dirname);
var phaser_modules = path.join(
root_dir,
'node_modules',
'phaser-ce',
'build',
'custom',
);
var paths = {
static: path.join(root_dir, 'static'),
source: path.join(root_dir, 'src'),
content: path.join(root_dir, 'dist'), // is_server ? 'static' : 'dist');
pixi: path.join(phaser_modules, 'pixi.js'),
phaser: path.join(phaser_modules, 'phaser-arcade-physics.js'),
};
var entries = [
{
name: 'test-1',
path: path.join(paths.source, 'test-1', 'main.js'),
commons: ['phaser_and_pixi'],
},
{
name: 'test-2',
path: path.join(paths.source, 'test-2.js'),
commons: ['phaser_and_pixi', 'tilemap_plus'],
},
{
name: 'test-3',
path: path.join(paths.source, 'test-3.js'),
commons: ['phaser_and_pixi', 'tilemap_plus', 'rot_js'],
},
{
name: 'test-4',
path: path.join(paths.source, 'test-4.js'),
commons: ['rot_js'],
},
},
];
// NOTE: `entry` is an Object of { 'test-1': "test-1.js", 'test-2': "test-2.js" }
var entry = entries.reduce((obj, e) => {
obj[e.name] = e.path;
return obj;
}, {});
// NOTE: gathers each unique common and pushes each entry that needs it onto it:
var commons = {};
entries.forEach(function(e) {
e.commons.forEach(function(common) {
commons[common] = commons[common] || [];
commons[common].push(e.name);
});
});
module.exports = {
entry,
output: {
path: paths.content,
filename: '[name].min.js',
sourceMapFilename: '[name].js.map',
},
devtool: 'source-map',
resolve: {
alias: {
pixi: paths.pixi,
phaser: paths.phaser,
},
},
module: {
rules: [
// exposing pixi and correct phaser into global scope
{
test: paths.pixi,
use: {
loader: 'expose-loader',
options: 'PIXI',
},
},
{
test: paths.phaser,
use: {
loader: 'expose-loader',
options: 'Phaser',
},
},
// pass source through babel
{
test: /\.js$/,
include: path.join(paths.source),
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['env'],
},
},
],
},
devServer: {
contentBase: paths.content,
publicPath: '/',
},
plugins: [
new webpack.LoaderOptionsPlugin({ debug: true }),
new CopyWebpackPlugin([
{
from: path.join(paths.static),
to: path.join(paths.content),
},
]),
].concat(
Object.keys(commons).map(function(common) {
return new webpack.optimize.CommonsChunkPlugin({
name: common,
chunks: ['common'].concat(commons[common]),
});
}),
entries.map(function(e) {
return new HtmlWebpackPlugin({
chunks: [e.name].concat(e.commons),
template: path.resolve(paths.source, 'index.html'),
filename: e.name + '.html',
});
}),
),
};