Skip to content

Commit

Permalink
add custom worker directory config
Browse files Browse the repository at this point in the history
  • Loading branch information
TimoWilhelm committed Oct 1, 2021
1 parent 54bbba6 commit 7c5f33a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 5 additions & 5 deletions build-custom-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ const webpack = require('webpack')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const TerserPlugin = require('terser-webpack-plugin')

const buildCustomWorker = ({ id, basedir, destdir, plugins, success, minify }) => {
const buildCustomWorker = ({ id, basedir, customWorkerDir, destdir, plugins, success, minify }) => {
let workerDir = undefined

if (fs.existsSync(path.join(basedir, 'worker'))) {
workerDir = path.join(basedir, 'worker')
} else if (fs.existsSync(path.join(basedir, 'src', 'worker'))) {
workerDir = path.join(basedir, 'src', 'worker')
if (fs.existsSync(path.join(basedir, customWorkerDir))) {
workerDir = path.join(basedir, customWorkerDir)
} else if (fs.existsSync(path.join(basedir, 'src', customWorkerDir))) {
workerDir = path.join(basedir, 'src', customWorkerDir)
}

if (!workerDir) return
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module.exports = (nextConfig = {}) => ({
cacheOnFrontEndNav = false,
reloadOnOnline = true,
scope = basePath,
customWorkerDir = 'worker',
subdomainPrefix, // deprecated, use basePath in next.config.js instead
...workbox
} = pwa
Expand Down Expand Up @@ -98,6 +99,7 @@ module.exports = (nextConfig = {}) => ({
buildCustomWorker({
id: buildId,
basedir: options.dir,
customWorkerDir,
destdir: _dest,
plugins: config.plugins.filter(plugin => plugin instanceof webpack.DefinePlugin),
success: ({name}) => importScripts.unshift(name),
Expand Down

0 comments on commit 7c5f33a

Please sign in to comment.