Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create two separate bundles with vue-cli 3?

I want to build two separate vue apps that will be served on two different routes in an express application: a ‘public’ vue app and an ‘admin’ vue app. These two apps have their own router and store but they share a lot of custom components. How can I edit the default webpack template to make it output two separate bundles based of my two different entry points (‘public’ and ‘admin’)? The goal would be to end up with a setup more or less like this:

my-app/ +- ... +- dist/ |  +- admin/         Admin bundle and files |  +- public/        Public bundle and files +- src/ |  +- components/    Shared components |  +- admin/         Entry point, router, store... for the admin app |  +- public/        Entry point, router, store... for the public app +- ... 

Must by available 2 dev servers http://localhost:8080/admin and http://localhost:8080/public Each project must be in own folder in dist, and own public

What i have today: created file vue.config.js in root directory With:

module.exports = {   // tweak internal webpack configuration.   // see https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md   chainWebpack: config => {     // If you wish to remove the standard entry point     config.entryPoints.delete('app')      // then add your own     config.entry('admin')       .add('./src/admin/index.js')       .end()     .entry('public')       .add('./src/public/index.js')       .end()   } } 
like image 727
Alexander Savenko Avatar asked Mar 23 '18 16:03

Alexander Savenko


People also ask

What is code splitting in Vue?

If there is a single entry point in your Vue app, webpack will create a single bundle comprised of the entire application code. The goal of code splitting is to let webpack create smaller separate bundles with separate entry points (essentially code-splitting points) on the dependency graph.

Is it possible to have multiple configs in Vue JS?

It is also possible to have multiple vue.config.js configs and switch them over using the VUE_CLI_SERVICE_CONFIG_PATH environment variable. For example, we can have a default vue.config.js and an additional vue.public.config.js and run the build like this:

What is a component in Vue framework?

Vue is a powerful JavaScript framework, which is designed by the component-based approach. Vue provides the tools to build scalable Single Page Applications and simplifies the process. Component in our context is an independent building block, which can be easily reused across one or many apps.

How do I start a VUE project?

Start by installing @vue/cli — this will help us scaffold our vue project: Next, run the following command: For our needs, we will choose “Manually select features”; immediately after, make sure to choose the following: Typescript (Class-style component syntax), CSS Pre-processors (Scss), Unit testing (Jest).

Do you need Webpack knowledge to manage a Vue JS project?

As I spend more and more time in the Vue.js ecosystem, I’m developing an a much greater appreciation for the time the core team has spent developing tools that make managing the project configuration. That said, a big part of managing a Vue.js project still requires a lot of Webpack knowledge… More than I have, unfortunately.


1 Answers

Assuming you need completely separate builds, with some shared scripts guided by your entries, you can add separate build commands.

In your package.json "scripts" section:

"scripts": {     "build:admin": "vue-cli-service build --dest dist/admin src/admin/index.js,     "build:public": "vue-cli-service build --dest dist/public src/public/index.js } 

For admin builds, you may run:

npm run build:admin 

and for public builds:

npm run build:public 

For more information, view the build target docs.

like image 76
Kamal Khan Avatar answered Oct 11 '22 01:10

Kamal Khan