#How do I bundle vue with esbuild?

65 messages · Page 1 of 1 (latest)

hidden torrent
#

also tried

<script type="module">
    import { Vue } from 'vue';
    console.log(Vue)
</script>```

results in:
```Uncaught TypeError: The specifier “vue” was a bare specifier, but was not remapped to anything. Relative module specifiers must start with “./”, “../” or “/”.```
long roost
#

Why not use the official vue installation guide
It uses vite which is based on esbuild

hidden torrent
# long roost Why not use the official vue installation guide It uses vite which is based on e...

through using an import map?

<script type="importmap">
  {
    "imports": {
      "vue": "LINK TO MY OWN MIN.JS"
    }
  }
</script>

<div id="app">{{ message }}</div>

<script type="module">
  import { createApp, ref } from 'vue'

  createApp({
    setup() {
      const message = ref('Hello Vue!')
      return {
        message
      }
    }
  }).mount('#app')
</script>

If I have multiple imports in my min.js how do I show that in imports?

"imports": {
      "vue": "LINK TO MY OWN MIN.JS",
      "another_library": "LINK TO MY OWN MIN.JS",
      "a_third_library": "LINK TO MY OWN MIN.JS",
}

Is this what you mean by using the offical guide?

long roost
#

no import map

#

it bundles your whole code including vue and any other libraries

hidden torrent
#

Where in the guide should I be looking?

#

all I see is
import { createApp } from 'vue' which is what I'm doing

#

I don't get why they don't give an example

#

I don't even understand vite, it's insane I've been 4 days trying to install vue. Working with a cdn is fine, vue gets added to the global scope no problem, minimizing my own js file with esbuild and requiring it has had me banging my head against a wall for 4 days

#
// vite.config.js
import { resolve } from 'path'
import { defineConfig } from 'vite'

export default defineConfig({
  build: {
    lib: {
      // Could also be a dictionary or array of multiple entry points
      entry: resolve(__dirname, 'lib/main.js'),
      name: 'MyLib',
      // the proper extensions will be added
      fileName: 'my-lib',
    },
    rollupOptions: {
      // make sure to externalize deps that shouldn't be bundled
      // into your library
      external: ['vue'],
      output: {
        // Provide global variables to use in the UMD build
        // for externalized deps
        globals: {
          vue: 'Vue',
        },
      },
    },
  },
})```

How am I meant to work this out this is insane
#

I want to install 1 library. add 1 library to global scope. use libary. that's it. And I get hit with "just read 50 thousand words on the vite website bro" "just read 60 thousand words on vue website"

#

Projects scaffolded via create-vue (based on Vite) or Vue CLI (based on webpack) are pre-configured for production builds.

If using a custom setup, make sure that:

    vue resolves to vue.runtime.esm-bundler.js.
    The compile time feature flags are properly configured.
    process.env.NODE_ENV is replaced with "production" during build.```

Wow, this is useless
long roost
#

why does it have to be global

hidden torrent
#

i don't know

#

I asked this question on another page and someone was saying

Because you never provide vue on the global scope

#

🤪

#

🤪

#

🤪

long roost
#

you either use a cdn and its globally available
or a bundler handles the imports for you and its not global

#

rn ur doing some weird mix of the 2

hidden torrent
#

how does a bundler handle the imports?

#

where should I be looking in vite documentation

#

Building for production just says:

// vite.config.js
export default defineConfig({
  build: {
    rollupOptions: {
      // https://rollupjs.org/configuration-options/
    },
  },
})```

is this the most useless example I've ever seen in my life
long roost
hidden torrent
long roost
#

?

hidden torrent
#

a backend and a front end server?

long roost
#

thats just frontend

hidden torrent
#

well I have a backend already

long roost
#

you can host it on the same or separate server as the backend

hidden torrent
#

my understanding

#

you have a backend like rails

#

rails bundles a front end framework like vue

#

rails serves vue to the client

#

the client uses vue

#

Now some people are saying no

#

You have a backend that is pure api

long roost
#

rails doesnt bundle

hidden torrent
#

it does something

long roost
#

you bundle once and it serves these files

hidden torrent
#

yeah

#

Ok I think it's vite but it's a rails command

#

now that's my understanding

#

that makes sense to me

#

but now you're saying run two servers, run npm run dev

long roost
#

thats only for development

#

for prod you run npm run build and the only server is rails

hidden torrent
#

ok

#

well at least that makes sense

#
//app.jsx
import * as Vue from 'vue'
console.log(Vue)

So should I put all my vue code in here and bundle it when ready for production?

long roost
#

yes

hidden torrent
#

ok

#

ok

#

my mistake is thinking I'd bundle all my libraries

#

and then import those bundled libraries into my own script and start front end development

#

but I should develop in a npm front end server and bundle everything when ready for production, libraries and my code

#

If I didn't want to develop in a front end server, let's say I have a database and rails backend all ready and want to develop using these routes and data, could I just require vue directly from node_modules/vue instead of the vue cdn?

#

I think that's how it's done if I want to develop front end code with the backend server

#

require directly from node_modules

long roost
#

so for development there are basically these ways:

  1. (awful): rebuild frontend after each edit and let the backend serve it
  2. https://vitejs.dev/config/server-options.html#server-proxy and run npm run dev to get hot reloading etc. all requests starting with e.g. /api/ will be sent to the backend (running on a different url)
hidden torrent
#

Sorry to ressurect a dead thread