-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.prod.config.js
executable file
·131 lines (126 loc) · 3.14 KB
/
webpack.prod.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
const path = require('path');
const { DefinePlugin } = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const JavaScriptObfuscator = require('webpack-obfuscator');
const TerserPlugin = require('terser-webpack-plugin');
const phaserModule = path.join(__dirname, '/node_modules/phaser-ce/');
const phaser = path.join(phaserModule, 'build/custom/phaser-arcade-physics.js');
const pixi = path.join(phaserModule, 'build/custom/pixi.js');
const p2 = path.join(phaserModule, 'build/custom/p2.js');
module.exports = () => {
const PLATFORM = process.env.PLATFORM || 'web';
console.log('PLATFORM: ', PLATFORM);
return {
entry: {
app: [
path.resolve(pixi),
path.resolve(p2),
path.resolve(__dirname, 'src/global.ts'),
path.resolve(__dirname, 'src/app.ts'),
]
},
output: {
filename: '[name].bundle.js',
path: path.resolve(process.env.PLATFORM === 'mobile' ? 'www' : 'dist'),
publicPath: '/'
},
mode: 'production',
devtool: false,
plugins: [
new CopyWebpackPlugin({
patterns: [
{ from: './assets', to: './assets' },
],
options: {
concurrency: 100,
},
}),
new JavaScriptObfuscator({
rotateUnicodeArray: true
}, ['vendor.bundle.js']),
new HtmlWebpackPlugin({
template: './index.html',
inject: 'body',
}),
new DefinePlugin({
// Define your environment variables here
PLATFORM: JSON.stringify(PLATFORM),
}),
],
performance: {
hints: false,
maxEntrypointSize: 512000,
maxAssetSize: 512000
},
optimization: {
splitChunks: {
minSize: 10000,
maxSize: 250000,
cacheGroups: {
vendor: {
test: /node_modules/,
chunks: 'initial',
name: 'vendor',
priority: 10,
enforce: true
}
}
},
minimizer: [
new TerserPlugin({
parallel: true,
terserOptions: {
// https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
},
}),
],
},
module: {
rules: [
{
test: /\.(j|t)s$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader'
}
},
{
test: /pixi\.js/,
use: {
loader: 'expose-loader',
options: {
exposes: ['PIXI', pixi]
}
}
},
{
test: /p2\.js$/,
use: {
loader: 'expose-loader',
options: {
exposes: ['p2', p2]
}
}
},
{
test: /phaser-arcade-physics\.js/,
use: {
loader: 'expose-loader',
options: {
exposes: ['Phaser', phaser]
}
}
},
]
},
resolve: {
extensions: ['.js', '.ts'],
alias: {
'phaser-ce': phaser,
'pixi': pixi,
'p2': p2,
}
}
}
};