vuejs3vue-cli-3

Vue/Cli Build custom Js


When I build with Vue/Cli, can I extract the files I want with the name I want?

main.js;

import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import global from '../global.js';

createApp(App).use(store).use(router).mount('#app')

I already get an error when I open the commented field below. How can I take the appropriate action

vue.config.js;

const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  transpileDependencies: true,
  productionSourceMap: false,
  //output: {
    //chunkFilename: (pathData) => {
      //return pathData.chunk.name === 'global' ? 'globalprivate.js' : '[chunkhash].js';
    //},
  //},
})

Solution

  • its works for me;

    vue.config.js

    const { defineConfig } = require("@vue/cli-service");
    module.exports = defineConfig({
      transpileDependencies: true,
      productionSourceMap: false,
      configureWebpack: {
        entry: {
          global: ["./global.js"],
        },
        output: {
          filename: (pathData) => {
            return pathData.chunk.name === 'global' ? 'global.js' : '[name]_[id].js';
          },
        },
      },
    });
    

    and my dist folder;

    enter image description here