Skip to content

Commit

Permalink
fix: make serve compatible with multiple template roots
Browse files Browse the repository at this point in the history
  • Loading branch information
cossssmin committed Apr 7, 2020
1 parent 39a1e26 commit 844a195
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,29 @@ const self = module.exports = {
.getMerged('local')
.then(config => {
const watchPaths = getPropValue(config, 'browsersync.watch') || []
const templatesRoot = getPropValue(config, 'build.templates.root')
const baseDir = getPropValue(config, 'build.destination.path') || 'build_local'
const bsOptions = getPropValue(config, 'browsersync') || {}

if (Array.isArray(templatesRoot)) {
templatesRoot.forEach(root => watchPaths.push(root))
} else if (typeof templatesRoot === 'string') {
watchPaths.push(templatesRoot)
}

bs.create()
bs.init({
server: {
baseDir: getPropValue(config, 'build.destination.path') || 'build_local',
directory: getPropValue(config, 'browsersync.directory') || true
baseDir: baseDir,
directory: bsOptions.directory || true
},
ui: getPropValue(config, 'browsersync.ui') || { port: 3001 },
port: getPropValue(config, 'browsersync.port') || 3000,
notify: getPropValue(config, 'browsersync.notify') || false,
tunnel: getPropValue(config, 'browsersync.tunnel') || false,
open: getPropValue(config, 'browsersync.open') || false
ui: bsOptions.ui || { port: 3001 },
port: bsOptions.port || 3000,
notify: bsOptions.notify || false,
tunnel: bsOptions.tunnel || false,
open: bsOptions.open || false
})
.watch(
[
`./${getPropValue(config, 'build.templates.root') || 'src/templates'}/**/*.*`,
`./${getPropValue(config, 'build.assets.source') || 'src/assets/images'}/**/*.*`,
'./tailwind.config.js',
...watchPaths
]
)
.watch(watchPaths)
.on('change', async () => {
await self.build()
.then(() => bs.reload())
Expand Down

0 comments on commit 844a195

Please sign in to comment.