Skip to content

Commit

Permalink
fix(ui): images urls while serving the ui (dev)
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Jun 14, 2018
1 parent 3994dac commit 4144efc
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 10 deletions.
1 change: 1 addition & 0 deletions packages/@vue/cli-ui/.env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VUE_APP_CLI_UI_DEV=true
2 changes: 1 addition & 1 deletion packages/@vue/cli-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"graphql-api": "cross-env VUE_CLI_DEBUG=true VUE_CLI_UI_DEV=true VUE_CLI_IPC=vue-cli-dev vue-cli-service graphql-api",
"graphql-api": "cross-env VUE_CLI_DEBUG=true VUE_APP_CLI_UI_DEV=true VUE_CLI_IPC=vue-cli-dev vue-cli-service graphql-api",
"run-graphql-api": "vue-cli-service run-graphql-api",
"test-graphql-api": "cross-env VUE_CLI_UI_TEST=true VUE_APP_GRAPHQL_PORT=4040 VUE_APP_CLI_UI_URL=ws://localhost:4040/graphql VUE_CLI_IPC=vue-cli-test yarn run graphql-api",
"prepublishOnly": "yarn run lint --no-fix && yarn run build",
Expand Down
12 changes: 10 additions & 2 deletions packages/@vue/cli-ui/src/components/ItemLogo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<img
v-else-if="displayImage"
class="image"
:src="image"
:key="image"
:src="imageUrl"
:key="imageUrl"
@load="loaded = true"
@error="error = true"
>
Expand Down Expand Up @@ -72,6 +72,14 @@ export default {
displayImage () {
return !this.isMaterialIcon && !this.error
},
imageUrl () {
// Fix images in development
if (process.env.VUE_APP_CLI_UI_DEV && this.image.charAt(0) === '/') {
return `http://localhost:4000${this.image}`
}
return this.image
}
},
Expand Down
11 changes: 10 additions & 1 deletion packages/@vue/cli-ui/src/components/ProjectNavButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
>
<img
v-if="imageIcon"
:src="view.icon"
:src="imageSrc(view.icon)"
class="image-icon"
>

Expand Down Expand Up @@ -72,6 +72,15 @@ export default {
imageIcon () {
return this.view.icon && this.view.icon.indexOf('.') !== -1
}
},
methods: {
imageSrc (url) {
if (process.env.VUE_APP_CLI_UI_DEV && url.charAt(0) === '/') {
return `http://localhost:4000${url}`
}
return url
}
}
}
</script>
Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli-ui/src/graphql-api/connectors/locales.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function _loadFolder (root, context) {

function loadFolder (root, context) {
const folder = path.join(root, './locales')
if (process.env.VUE_CLI_UI_DEV && !watchedTrees.get(root) && fs.existsSync(folder)) {
if (process.env.VUE_APP_CLI_UI_DEV && !watchedTrees.get(root) && fs.existsSync(folder)) {
watchedTrees.set(root, true)
const watch = require('watch')
watch.watchTree(folder, () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/@vue/cli-ui/src/graphql-api/utils/logger.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const chalk = require('chalk')

exports.log = (...args) => {
if (!process.env.VUE_CLI_UI_DEV) return
if (!process.env.VUE_APP_CLI_UI_DEV) return
const date = new Date()
const timestamp = `${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}.${date.getSeconds().toString().padStart(2, '0')}`
const first = args.shift()
Expand All @@ -15,7 +15,7 @@ const simpleTypes = [
]

exports.dumpObject = (obj) => {
if (!process.env.VUE_CLI_UI_DEV) return
if (!process.env.VUE_APP_CLI_UI_DEV) return
const result = {}
Object.keys(obj).forEach(key => {
const value = obj[key]
Expand Down
4 changes: 2 additions & 2 deletions packages/@vue/cli-ui/vue-cli-ui.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file will be loaded when the project is opened
module.exports = api => {
if (!process.env.VUE_CLI_UI_DEV) return
if (!process.env.VUE_APP_CLI_UI_DEV) return

console.log('has(eslint)', api.hasPlugin('eslint'))
console.log('has(typescript)', api.hasPlugin('typescript'))
Expand All @@ -16,7 +16,7 @@ module.exports = api => {
id: 'vue-webpack-test-view',
name: 'test-webpack-route',
// icon: 'pets',
icon: 'http://localhost:4000/public/webpack-logo.png',
icon: '/public/webpack-logo.png',
tooltip: 'Test view from webpack addon'
})

Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli/lib/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async function ui (options = {}, context = process.cwd()) {

// Dev mode
if (options.dev) {
process.env.VUE_CLI_UI_DEV = true
process.env.VUE_APP_CLI_UI_DEV = true
}

if (!process.env.VUE_CLI_IPC) {
Expand Down

0 comments on commit 4144efc

Please sign in to comment.