Skip to content

Commit 163d9ce

Browse files
committed
Revert "Make dev builds faster (#227)"
This reverts commit 8c88ec6. Fix #240
1 parent ead3527 commit 163d9ce

File tree

3 files changed

+28
-77
lines changed

3 files changed

+28
-77
lines changed

webpack.common.js

+26-27
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const webpack = require('webpack')
22
const path = require('path')
3+
const CopyPlugin = require('copy-webpack-plugin')
34
const HtmlWebpackPlugin = require('html-webpack-plugin')
5+
const WorkboxPlugin = require('workbox-webpack-plugin')
46
// https://webpack.js.org/guides/production/
57

68
const config = {
@@ -18,9 +20,11 @@ const config = {
1820
), // Hack to allow creating the client in a browser
1921
express: false,
2022
net: 'net-browserify',
21-
fs: 'memfs'
23+
fs: 'memfs',
24+
jose: false
2225
},
2326
fallback: {
27+
jose: false,
2428
zlib: require.resolve('browserify-zlib'),
2529
stream: require.resolve('stream-browserify'),
2630
buffer: require.resolve('buffer/'),
@@ -55,32 +59,27 @@ const config = {
5559
new webpack.NormalModuleReplacementPlugin(
5660
/prismarine-viewer[/|\\]viewer[/|\\]lib[/|\\]utils/,
5761
'./utils.web.js'
58-
)
59-
],
60-
// The directories that can be optionally symlinked
61-
[Symbol.for('webpack_directories')]: [
62-
{ from: path.join(__dirname, '/node_modules/prismarine-viewer/public/blocksStates/'), to: './blocksStates/' },
63-
{ from: path.join(__dirname, '/node_modules/prismarine-viewer/public/textures/'), to: './textures/' },
64-
{ from: path.join(__dirname, 'extra-textures/'), to: './extra-textures/' }
65-
],
66-
// The files that will be copied
67-
[Symbol.for('webpack_files')]: [
68-
{ from: path.join(__dirname, '/styles.css'), to: './styles.css' },
69-
{ from: path.join(__dirname, '/node_modules/prismarine-viewer/public/worker.js'), to: './' },
70-
{ from: path.join(__dirname, '/node_modules/prismarine-viewer/public/supportedVersions.json'), to: './' },
71-
{ from: path.join(__dirname, 'assets/'), to: './' },
72-
{ from: path.join(__dirname, 'config.json'), to: './config.json' }
73-
],
74-
module: {
75-
rules: [
76-
{
77-
test: /\.m?js/,
78-
resolve: {
79-
fullySpecified: false
80-
}
81-
}
82-
]
83-
}
62+
),
63+
new WorkboxPlugin.GenerateSW({
64+
// these options encourage the ServiceWorkers to get in there fast
65+
// and not allow any straggling "old" SWs to hang around
66+
clientsClaim: true,
67+
skipWaiting: true,
68+
include: ['index.html', 'manifest.json'] // not caching a lot as anyway this works only online
69+
}),
70+
new CopyPlugin({
71+
patterns: [
72+
{ from: path.join(__dirname, '/styles.css'), to: './styles.css' },
73+
{ from: path.join(__dirname, '/node_modules/prismarine-viewer/public/blocksStates/'), to: './blocksStates/' },
74+
{ from: path.join(__dirname, '/node_modules/prismarine-viewer/public/textures/'), to: './textures/' },
75+
{ from: path.join(__dirname, '/node_modules/prismarine-viewer/public/worker.js'), to: './' },
76+
{ from: path.join(__dirname, '/node_modules/prismarine-viewer/public/supportedVersions.json'), to: './' },
77+
{ from: path.join(__dirname, 'assets/'), to: './' },
78+
{ from: path.join(__dirname, 'extra-textures/'), to: './extra-textures/' },
79+
{ from: path.join(__dirname, 'config.json'), to: './config.json' }
80+
]
81+
})
82+
]
8483
}
8584

8685
module.exports = config

webpack.dev.js

+1-34
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,7 @@
11
const { merge } = require('webpack-merge')
22
const common = require('./webpack.common.js')
3-
const CopyPlugin = require('copy-webpack-plugin')
4-
const fs = require('fs')
53
const path = require('path')
64

7-
class SymlinkPlugin {
8-
constructor (options) {
9-
this.directories = options.directories ?? []
10-
}
11-
12-
apply (compiler) {
13-
compiler.hooks.afterEmit.tap(SymlinkPlugin.name, this.afterEmitHook.bind(this))
14-
}
15-
16-
afterEmitHook (compilation) {
17-
const dir = compilation.options.context
18-
const output = compilation.outputOptions.path
19-
for (const { from: _from, to: _to } of this.directories) {
20-
const to = path.resolve(output, _to)
21-
if (fs.existsSync(to)) {
22-
try {
23-
fs.unlinkSync(to)
24-
} catch (e) {
25-
continue
26-
}
27-
}
28-
const from = path.resolve(dir, _from)
29-
fs.symlinkSync(from, to, 'junction')
30-
}
31-
}
32-
}
33-
345
module.exports = merge(common, {
356
mode: 'development',
367
devtool: 'inline-source-map',
@@ -41,9 +12,5 @@ module.exports = merge(common, {
4112
inline: true,
4213
// open: true,
4314
hot: true
44-
},
45-
plugins: [
46-
new CopyPlugin({ patterns: common[Symbol.for('webpack_files')] }),
47-
new SymlinkPlugin({ directories: common[Symbol.for('webpack_directories')] })
48-
]
15+
}
4916
})

webpack.prod.js

+1-16
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,15 @@
11
const { merge } = require('webpack-merge')
22
const common = require('./webpack.common.js')
33

4-
const CopyPlugin = require('copy-webpack-plugin')
54
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin')
65
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
76
const webpack = require('webpack')
8-
const WorkboxPlugin = require('workbox-webpack-plugin')
97

108
module.exports = merge(common, {
119
mode: 'production',
1210
plugins: [
1311
new CleanWebpackPlugin(),
1412
new webpack.optimize.ModuleConcatenationPlugin(),
15-
new LodashModuleReplacementPlugin(),
16-
new CopyPlugin({
17-
patterns: [
18-
...common[Symbol.for('webpack_directories')],
19-
...common[Symbol.for('webpack_files')]
20-
]
21-
}),
22-
new WorkboxPlugin.GenerateSW({
23-
// these options encourage the ServiceWorkers to get in there fast
24-
// and not allow any straggling "old" SWs to hang around
25-
clientsClaim: true,
26-
skipWaiting: true,
27-
include: ['index.html', 'manifest.json'] // not caching a lot as anyway this works only online
28-
})
13+
new LodashModuleReplacementPlugin()
2914
]
3015
})

0 commit comments

Comments
 (0)