-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.config.js
290 lines (243 loc) · 8.28 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
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
const path = require('path');
const webpack = require('webpack');
const ESLintPlugin = require('eslint-config-prettier');
let performanceOptions =
{
};
let devServerOptions =
{
//stats: {
// Enables disables colors on the console
// colors: true,
// Tells stats whether to display the --env information.
//env: true,
// Tells stats whether to display the errors.
//errors: true,
// Tells stats whether to add the details to the errors.
//errorDetails: true,
// Tells stats whether to show stack trace of errors.
//errorStack: true,
// Tells stats weather to add logging information
// 'info': 'none' | 'error' | 'warn' | 'info' | 'log' | 'verbose'
//logging: 'verbose',
// Tells stats to add information about the webpack version used.
//version: true
//},
// Tell the server where to serve content from (Static files only).
// It is recommended to use an absolute path.
// contentBase: path.join(__dirname, 'dist'),
// The bundled files will be available in the browser under this path.
// Make sure devServer.publicPath always starts and ends with a forward slash.
// publicPath: '/dist/',
// serves everything from our dist directory in the project root:
static: {
directory: path.join(__dirname, 'dist'),
watch: true
},
// The filename that is considered the index file.
//index: 'index.html',
// The server type( default is http)
server: 'http',
// Enable gzip compression for everything served:
compress: false,
// Specify a port number to listen for requests on.
port: 9000,
// Specify a host to use. If you want your server to be
// accessible externally, specify it like this:
// Default is 'localhost'.
host: 'localhost',
// This option allows you to whitelist services that are
// allowed to access the dev server.
//allowedHosts: [
// '192.168.2.*',
// '192.168.2.',
//],
// Enables/Disables colors on the console
// Available on cli only --color
// color: true,
// Tell dev-server to watch the files served by the devServer.contentBase option.
// It is disabled by default. When enabled, file changes will trigger a full page reload.
// Not in v4
//watchContentBase: true,
// Control options related to watching the files.
// webpack-dev-server uses the file system to get notified of file changes.
// Now on by default.
//watchOptions: {
// Set to 5 seconds
// poll: 5000
//},
// By default, the dev-server will reload/refresh the page when file changes are detected.
// devServer.hot option must be disabled or devServer.watchContentBase option must be enabled
// in order for liveReload to take effect.
liveReload: true,
// Enable webpack's Hot Module Replacement feature:
// Note: requires a lot of other stuff too in index.html ...
hot: false,
onListening: function(devServer)
{
if ( !devServer )
throw new Error( 'webpack-dev-server is not defined' );
const port = devServer.server.address().port;
console.log( 'Listening on port:', port );
},
devMiddleware: {
index: true,
mimeTypes: { phtml: 'text/html' },
publicPath: 'dist',
serverSideRender: true,
writeToDisk: true,
},
// Tells dev-server to open the browser after server had been started.
//open: { },
// Specify a page to navigate to when opening the browser.
// So that all the examples work.
//
// Note: We allow this to be changed via argv.openPage='<fn>'
// which is stupid because we can just use --openPage.
// However I confused it with devServer.index which
// cannot be set via cli. Why the two is beyond me?
//openPage: 'index.html'
open: [ "index.html" ]
};
let webpackOptions =
{
// Since this is processed as a command line option (because of argv...)
// the mode must be set so that it can be returned as part of the big
// config entry.
mode: "production",
performance: performanceOptions,
entry: './src/index.ts',
output: {
// Default in webpack V5
//path: path.resolve(__dirname, 'dist'),
filename: 'js/client/pixi_ui.js',
// The library name means you would access it via pixi-ui.button.
library: 'pixi_ui',
// Add vitual path for generating the bundle files
publicPath: 'dist',
// Turn off pathInfo, increasing build time
pathinfo: false,
},
devServer: devServerOptions,
plugins: [
// Too messy, deal with later
// new ESLintPlugin({
// files: ['./app/partKart/**/*.ts',
// './app/src/*.ts'
// ]
// }),
// Add a plugins section to your webpack.config.js to let
// know Webpack that the global PIXI variable make reference
// to pixi.js module. For instance:
new webpack.ProvidePlugin({
PIXI: 'pixi.js'
})
],
//Default
target: 'web',
externals: {"pixi.js": "PIXI",
"fs": "require('fs')" },
resolve: {
// Add '.ts' as resolvable extensions.
extensions: [".ts", ".js"],
alias: {
$: "jquery/src/jquery",
}
},
optimization: {
minimize: false,
},
// Enable sourcemaps for debugging webpack's output.
// // devtool: "source-map" // without any, there is no sourcemap
//devtool: "eval" // none
devtool: "source-map", // one big blob
//devtool: "eval-source-map" // none
module:
{
rules: [
{
test: /\.js$/,
include: [path.resolve(__dirname, "src")],
exclude: [
// This would be a regular expression
/node_modules/,
// This would be a path
// Omit stuff to be worked on
'/test/somepath/' // Omit all test/somepath
],
use: {
loader: 'babel-loader',
// Note. Do not put other compile options here !!!
// ts-loader or babel-loader may override them.
// i.e ts-loader listFiles: true or
// ts-loader outdir: 'js'
}
},
{
test: /\.ts$/,
include: [path.resolve(__dirname, "src"),
path.resolve(__dirname, "test/src")],
exclude: [
// This would be a regular expression
/node_modules/
// This would be a path
// Omit stuff to be worked on
],
use: {
loader: "ts-loader",
// Note. Do not other put compile options here !!!
// ts-loader or babel-loader may override them.
// i.e ts-loader listFiles: true or
// ts-loader outdir: 'js'
options: {
transpileOnly: true,
experimentalWatchApi: true,
},
}
}
]
}
};
module.exports = (env, argv) =>
{
console.log("Not bundling pixi.js");
webpackOptions.watchOptions = {
// Add a delay before rebuilding once the first file changed
aggregateTimeout: 600,
poll: 5000
};
// The default 'mode' to use.
webpackOptions.mode='production';
if ( argv )
{
//const r = Object.keys(argv);
//console.log("argv = " + r);
//console.log("argv.mode = " + argv.mode );
if ( argv.mode === undefined || argv.mode === 'development' )
{
// Since this is processed as a command line option
// (because of argv...) the mode must be set so that it
// can be returned as part of the big config entry.
webpackOptions.mode='development';
webpackOptions.performance = {
hints: false,
maxEntrypointSize: 512000,
maxAssetSize: 512000
};
}
else if ( argv.mode === 'production' )
{
// For now
// Will minify later ...
webpackOptions.performance = {
hints: false,
maxEntrypointSize: 512000,
maxAssetSize: 512000
};
} else
throw new Error('unhandled mode:' + argv.mode);
}
//const util = require('util')
//console.log(util.inspect(webpackOptions, {showHidden: false, depth: null, colors: true}));
return webpackOptions;
};