2021-02-27 17:12:11 -05:00
|
|
|
const webpack = require('webpack')
|
|
|
|
const path = require('path')
|
|
|
|
const CopyPlugin = require('copy-webpack-plugin')
|
2021-03-13 13:48:53 -05:00
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin')
|
2021-03-20 21:54:10 -04:00
|
|
|
const WorkboxPlugin = require('workbox-webpack-plugin')
|
2021-03-05 19:29:28 -05:00
|
|
|
// https://webpack.js.org/guides/production/
|
2021-02-27 17:12:11 -05:00
|
|
|
|
|
|
|
const config = {
|
|
|
|
entry: path.resolve(__dirname, './index.js'),
|
|
|
|
output: {
|
|
|
|
path: path.resolve(__dirname, './public'),
|
2021-03-05 19:29:28 -05:00
|
|
|
filename: './index.js',
|
|
|
|
publicPath: '/'
|
2021-02-27 17:12:11 -05:00
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
'minecraft-protocol': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
'node_modules/minecraft-protocol/src/index.js'
|
|
|
|
), // Hack to allow creating the client in a browser
|
|
|
|
express: false,
|
|
|
|
net: 'net-browserify',
|
2021-03-27 14:47:55 -04:00
|
|
|
fs: 'memfs',
|
|
|
|
'node-fetch': 'cross-fetch'
|
2021-02-27 17:12:11 -05:00
|
|
|
},
|
|
|
|
fallback: {
|
2021-03-27 14:47:55 -04:00
|
|
|
'node-fetch': require.resolve('cross-fetch'),
|
2021-02-27 17:12:11 -05:00
|
|
|
zlib: require.resolve('browserify-zlib'),
|
|
|
|
stream: require.resolve('stream-browserify'),
|
|
|
|
buffer: require.resolve('buffer/'),
|
|
|
|
events: require.resolve('events/'),
|
|
|
|
assert: require.resolve('assert/'),
|
|
|
|
crypto: require.resolve('crypto-browserify'),
|
|
|
|
path: require.resolve('path-browserify'),
|
|
|
|
constants: require.resolve('constants-browserify'),
|
|
|
|
os: require.resolve('os-browserify/browser'),
|
|
|
|
http: require.resolve('http-browserify'),
|
|
|
|
https: require.resolve('https-browserify'),
|
|
|
|
timers: require.resolve('timers-browserify'),
|
|
|
|
// fs: require.resolve("fs-memory/singleton"),
|
|
|
|
child_process: false,
|
2021-02-27 18:18:58 -05:00
|
|
|
perf_hooks: path.resolve(__dirname, 'lib/perf_hooks_replacement.js'),
|
|
|
|
dns: path.resolve(__dirname, 'lib/dns.js')
|
2021-02-27 17:12:11 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
plugins: [
|
2021-03-13 13:48:53 -05:00
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: 'index.html',
|
2021-03-13 16:29:58 -05:00
|
|
|
hash: true,
|
|
|
|
minify: false
|
2021-03-13 13:48:53 -05:00
|
|
|
}),
|
2021-02-27 17:12:11 -05:00
|
|
|
// fix "process is not defined" error:
|
|
|
|
new webpack.ProvidePlugin({
|
|
|
|
process: 'process/browser'
|
|
|
|
}),
|
|
|
|
new webpack.ProvidePlugin({
|
|
|
|
Buffer: ['buffer', 'Buffer']
|
|
|
|
}),
|
|
|
|
new webpack.NormalModuleReplacementPlugin(
|
|
|
|
/prismarine-viewer[/|\\]viewer[/|\\]lib[/|\\]utils/,
|
|
|
|
'./utils.web.js'
|
|
|
|
),
|
2021-03-20 21:54:10 -04:00
|
|
|
new WorkboxPlugin.GenerateSW({
|
|
|
|
// these options encourage the ServiceWorkers to get in there fast
|
|
|
|
// and not allow any straggling "old" SWs to hang around
|
|
|
|
clientsClaim: true,
|
|
|
|
skipWaiting: true,
|
|
|
|
include: ['index.html', 'manifest.json'] // not caching a lot as anyway this works only online
|
|
|
|
}),
|
2021-02-27 17:12:11 -05:00
|
|
|
new CopyPlugin({
|
|
|
|
patterns: [
|
2021-03-03 23:07:07 -05:00
|
|
|
{ from: path.join(__dirname, '/styles.css'), to: './styles.css' },
|
2021-02-27 17:28:08 -05:00
|
|
|
{ from: path.join(__dirname, '/node_modules/prismarine-viewer/public/blocksStates/'), to: './blocksStates/' },
|
|
|
|
{ from: path.join(__dirname, '/node_modules/prismarine-viewer/public/textures/'), to: './textures/' },
|
|
|
|
{ from: path.join(__dirname, '/node_modules/prismarine-viewer/public/worker.js'), to: './' },
|
2021-02-27 18:58:21 -05:00
|
|
|
{ from: path.join(__dirname, '/node_modules/prismarine-viewer/public/supportedVersions.json'), to: './' },
|
2021-03-14 14:56:54 -04:00
|
|
|
{ from: path.join(__dirname, 'assets/'), to: './' },
|
2021-03-21 12:14:14 -04:00
|
|
|
{ from: path.join(__dirname, 'extra-textures/'), to: './extra-textures/' },
|
|
|
|
{ from: path.join(__dirname, 'config.json'), to: './config.json' }
|
2021-02-27 17:12:11 -05:00
|
|
|
]
|
2021-03-05 19:29:28 -05:00
|
|
|
})
|
|
|
|
]
|
2021-02-27 17:12:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = config
|