-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathwebpack.common.js
More file actions
174 lines (163 loc) · 4.56 KB
/
webpack.common.js
File metadata and controls
174 lines (163 loc) · 4.56 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
const path = require('path');
const webpack = require('webpack');
const SpritesmithPlugin = require('webpack-spritesmith');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
const { version } = require('./package.json');
const { title } = require('./package.json');
const config = require('./configs/config.dev');
// extend config
config.logo.title = title;
config.logo.emitStats = false;
config.logo.persistentCache = false;
module.exports = {
entry: {
game: ['./src/main.js']
},
resolve: {
modules: ['node_modules'],
extensions: ['.js', '.css', '.png', '.jpg', '.gif', '.jpeg', '.json'],
alias: {
Plugins: path.resolve(__dirname, 'plugins'),
Src: path.resolve(__dirname, 'src'),
Objects: path.resolve(__dirname, 'src/objects'),
Utils: path.resolve(__dirname, 'src/utils'),
phaserMin$: path.resolve(__dirname, './node_modules/phaser/dist/phaser.min.js'),
phaserArcade$: path.resolve(
__dirname,
'./node_modules/phaser/dist/phaser-arcade-physics.min.js'
)
}
},
output: {
path: path.resolve(__dirname, './build/web'),
filename: '[name].js'
},
module: {
rules: [
{
test: [/\.vert$/, /\.frag$/],
use: 'raw-loader'
},
{
test: /\.js$/,
exclude: /node_modules/,
use: ['babel-loader']
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader',
enforce: 'pre',
options: {
fix: true
}
},
{
test: require.resolve('./src/utils/customs'),
use: [
{
loader: 'expose-loader',
options: 'Customs'
}
]
},
{
test: /\.png$/,
use: ['file-loader?name=i/[hash].[ext]']
}
]
},
plugins: [
new webpack.DefinePlugin({
// Enable both canvas and WebGL for better support
'typeof CANVAS_RENDERER': JSON.stringify(true),
'typeof WEBGL_RENDERER': JSON.stringify(true),
// Development env
_DEV_: JSON.stringify(true),
_VERSION_: JSON.stringify(version)
}),
new HtmlWebpackPlugin({
template: 'index.html',
title,
inject: 'body'
})
],
optimization: {
splitChunks: {
chunks: 'all'
}
}
};
const copyFolders = [];
for (let i = 0; i < config.autoImportFolders.length; i++) {
const folderName = config.autoImportFolders[i];
copyFolders.push({
from: `./assets/${folderName}`,
to: 'assets'
});
}
copyFolders.push({
from: `src/assets`,
to: 'assets'
});
module.exports.plugins.push(new CopyWebpackPlugin(copyFolders));
if (config.plugins.build) {
Object.keys(config.plugins).forEach(key => {
if (key !== 'build') {
// module.exports.entry[config.plugins[key].name] = `./plugins/${config.plugins[key].name}`;
}
});
}
if (config.includeCustomPhaser) {
Object.keys(config.customPhaserBuild).forEach(key => {
module.exports.resolve.alias[`${key}$`] = `${config.customPhaserBuild[key]}`;
});
}
if (config.logo.make) {
module.exports.plugins.push(new FaviconsWebpackPlugin(config.logo));
}
if (config.spritesmeeth) {
const spritesheetsFolder = 'spritesheets';
module.exports.plugins.push(new CleanWebpackPlugin([`src/assets/${spritesheetsFolder}`]));
for (let i = 0; i < config.spritesheetFolders.length; i++) {
module.exports.plugins.push(
new SpritesmithPlugin({
src: {
cwd: path.resolve(__dirname, `assets/${config.spritesheetFolders[i]}`),
glob: '*.png'
},
target: {
image: path.resolve(
__dirname,
`src/assets/${spritesheetsFolder}/${config.spritesheetFolders[i]}.png`
),
css: [
// path.resolve(__dirname, 'src/assets/spritesheets/sprite.css'),
[
path.resolve(
__dirname,
`src/assets/spritesheets/${config.spritesheetFolders[i]}.json`
),
{
format: 'json_texture'
}
]
]
},
apiOptions: {
generateSpriteName: image => {
const spriteName = image.split('\\');
return spriteName[spriteName.length - 1].replace('.png', '');
},
cssImageRef: `~${config.spritesheetFolders[i]}.png`
},
spritesmithOptions: {
algorithm: 'binary-tree'
}
})
);
}
}