Skip to content

Commit

Permalink
feat(ui): dev: auto reload locales
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Apr 30, 2018
1 parent c135782 commit 86c9674
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/@vue/cli-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
"lint-staged": "^6.0.0",
"stylus": "^0.54.5",
"stylus-loader": "^3.0.1",
"vue-template-compiler": "^2.5.16"
"vue-template-compiler": "^2.5.16",
"watch": "^1.0.2"
},
"browserslist": [
"> 1%",
Expand Down
14 changes: 13 additions & 1 deletion packages/@vue/cli-ui/src/graphql-api/connectors/locales.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function reset (context) {
loadFolder(folder, context)
}

function loadFolder (root, context) {
function _loadFolder (root, context) {
const paths = globby.sync([path.join(root, './locales/*.json')])
paths.forEach(file => {
const basename = path.basename(file)
Expand All @@ -43,6 +43,18 @@ function loadFolder (root, context) {
})
}

function loadFolder (root, context) {
if (process.env.NODE_ENV !== 'production') {
const watch = require('watch')
watch.watchTree(root, () => {
_loadFolder(root, context)
console.log(`Locales reloaded: ${root}`)
})
} else {
_loadFolder(root, context)
}
}

reset(getContext())

module.exports = {
Expand Down

0 comments on commit 86c9674

Please sign in to comment.