question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support base option during dev

See original GitHub issue

Is your feature request related to a problem? Please describe.

Running multiple independent SPAs in subdirectories within the same domain like microservices for front-end is well supported for production builds by setting base. Example

https://domain.com/profile -> 'base':'/profile'
https://domain.com/admin -> 'base':'/admin'

Ok, but this seems impossible to set up for local dev because /vite/client, WebSocket, etc. will still load from the root path / instead of from base path, like /profile/vite/client.

Of course same applies to modules urls /src/App.vue instead of /profile/src/App.vue, etc.

Describe the solution you’d like

Assuming nginx (or similar) set up “in front” of some vite dev projects, like so:

location /profile {
  proxy_pass http://0.0.0.0:8081; 
}

location /admin {
  proxy_pass http://0.0.0.0:8082;
}

And running two local dev projects by a simple $ vite configured like:

// 1st vite.config.js
module.exports = {
  port: 8081,
  base: '/profile'
}

// 2nd vite.config.js
module.exports = {
  port: 8082,
  base: '/admin'
}

Describe alternatives you’ve considered

So far this was feasible with a little hacky setup in vue-cli (also see https://github.com/vuejs/vue-cli/issues/4400):

// vue.config.js
module.exports = {
  publicPath: '/profile/',

  devServer: {
    public: '0.0.0.0',
    port: '8081',
    sockPath: '/profile/websocket',
    disableHostCheck: true
  },

  configureWebpack: {
    plugins: [
      {
        // needed workaround for sockPath issues
        apply: compiler => {
          compiler.hooks.entryOption.tap('entry', () => {
            const clients = compiler.options.entry.app
            for (const index in clients) {
              if (clients[index].match(/sockjs-node/)) {
                clients[index] = clients[index].replace(
                  '0.0.0.0/sockjs-node',
                  '0.0.0.0&sockPath=/profile/websocket'
                )
              }
            }
          })
        }
      }
    ]
  }
}

Additional context

I didn’t find a solution yet within Github issues. Sorry if I missed one. There are some related PRs though to configure socket path for example. Still, there seems to be no workaround for /vite/... and /src/... URLs.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:7
  • Comments:19 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
lovetingyuancommented, Apr 19, 2021

Is full url base still not supported?

export default defineConfig({
  base: `http://localhost:4343/`,
  server: {
    port: 4343
  },
  plugins: [
    vue({
      template: {
        transformAssetUrls: {
          base: `http://localhost:4343/`
        }
      }
    }),
  ]
})

image

But I still get this: image

image

1reaction
bompuscommented, Jan 16, 2021

PR submitted

Read more comments on GitHub >

github_iconTop Results From Across the Web

Shared Options | Vite
Base public path when served in development or production. Valid values include: Absolute URL pathname, e.g. /foo/; Full URL, e.g. https://foo.com/ ...
Read more >
How to set vite.config.js base public path? - Stack Overflow
According to vitejs , you can set the base public path when served in development or production, in your config options.
Read more >
Configure on-device developer options - Android Developers
Before you can use the debugger and other tools, you need to enable USB debugging, which allows Android Studio and other SDK tools...
Read more >
Language Guide | Protocol Buffers - Google Developers
In all cases, setting values to a field will perform type checking to make ... should generate abstract service code based on services...
Read more >
DevServer - webpack
This option allows you to allowlist services that are allowed to access the dev server. webpack.config.js module.exports = { //... devServer: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found