forked from FreezingMoon/AncientBeast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
114 lines (103 loc) · 2.84 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
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const variables = require('./webpack.var');
const merge = require('webpack-merge');
const CopyPlugin = require('copy-webpack-plugin');
// Phaser webpack config
const phaserModule = path.join(__dirname, '/node_modules/phaser-ce/');
const phaser = path.join(phaserModule, 'build/custom/phaser-split.js');
const pixi = path.join(phaserModule, 'build/custom/pixi.js');
const p2 = path.join(phaserModule, 'build/custom/p2.js');
// Expose mode argument to unify our config options.
module.exports = (env, argv) => {
// Common settings for all environments.
let common = {
entry: path.resolve(__dirname, 'src', 'script.js'),
output: {
path: path.resolve(__dirname, 'deploy/'),
filename: 'ancientbeast.js',
// chunkFilename: '[id].chunk.js',
publicPath: '/'
},
devtool: 'inline-source-map',
optimization: {
splitChunks: {
cacheGroups: {}
}
},
module: {
rules: [
{ test: /pixi\.js/, use: ['expose-loader?PIXI'] },
{ test: /phaser-split\.js$/, use: ['expose-loader?Phaser'] },
{ test: /p2\.js/, use: ['expose-loader?p2'] },
{
test: /\.less$/,
use: ['style-loader', 'css-loader', 'less-loader']
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.(png|jpg|gif|svg|ogg|ico|cur|woff|woff2)$/,
use: ['file-loader']
}
]
},
resolve: {
alias: {
pixi: pixi,
p2: p2,
phaser: phaser,
assets: path.resolve(__dirname, 'assets/'),
modules: path.join(__dirname, 'node_modules')
}
},
// Eventually we want to use a version of this.
// optimization: {
// splitChunks: {
// cacheGroups: {
// vendor: {
// test: /[\\/]node_modules[\\/]/,
// name: "vendors",
// enforce: true
// },
// assets: {
// test: /[\\/]assets[\\/]/,
// name: "assets",
// enforce: true
// },
// }
// }
// },
plugins: [
new CopyPlugin([{ from: 'static' }]),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'src', 'index.html'),
favicon: path.resolve(__dirname, 'assets', 'favicon.png'),
worker: variables.worker,
analytics: ''
})
]
};
let production = {
plugins: [
new CopyPlugin([{ from: 'static' }]),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'src', 'index.html'),
favicon: path.resolve(__dirname, 'assets', 'favicon.png'),
worker: variables.worker,
analytics: variables.analytics
})
]
};
let settings;
// argv is passed in when ran via `webpack --mode` and process.env.NODE_ENV is used when
// `npm start` commands are used.
if ((argv && argv.mode === 'production') || process.env.NODE_ENV === 'production') {
settings = merge.strategy({ plugins: 'replace' })(common, production);
} else {
settings = common;
}
return settings;
};