Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is the entry file used by vue-cli-service?

Got a project using vue, webpack, babel, npm.
Could start it via npm run server, when trying to figure out how this command work, I saw vue-cli-service serve from package.json.

But, how does vue-cli-service start the program? I saw main.js which in turn render Vue.vue, both of which are under src/.

Didn't see anywhere config the entry file, so is main.js the default entry for vue-cli-service?


Code

package.json:

{
  "name": "quizer-ui",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve --port 3000",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "core-js": "^2.6.5",
    "element-ui": "^2.10.1",
    "vue": "^2.6.10",
    "vue-router": "^3.0.7"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "^3.9.0",
    "@vue/cli-plugin-eslint": "^3.9.0",
    "@vue/cli-service": "^3.9.0",
    "babel-eslint": "^10.0.1",
    "eslint": "^5.16.0",
    "eslint-plugin-vue": "^5.0.0",
    "stylus": "^0.54.5",
    "stylus-loader": "^3.0.1",
    "vue-cli-plugin-element": "^1.0.1",
    "vue-template-compiler": "^2.6.10"
  },
  "eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/essential",
      "eslint:recommended"
    ],
    "rules": {},
    "parserOptions": {
      "parser": "babel-eslint"
    }
  },
  "postcss": {
    "plugins": {
      "autoprefixer": {}
    }
  },
  "browserslist": [
    "> 1%",
    "last 2 versions"
  ]
}
like image 938
user218867 Avatar asked Jul 26 '19 01:07

user218867


People also ask

What is vue-CLI-service?

The CLI ( @vue/cli ) is a globally installed npm package and provides the vue command in your terminal. It provides the ability to quickly scaffold a new project via vue create . You can also manage your projects using a graphical user interface via vue ui .

What is vue config file?

vue. config. js is an optional config file that will be automatically loaded by @vue/cli-service if it's present in your project root (next to package. json ). You can also use the vue field in package.

Does vue CLI use Vite?

Vite isn't specific to Vue, but instead is a way to develop JavaScript/TypeScript applications. Let's look at the how the Vue CLI works and how Vite is different. Evan You is at it again. He developed a new tool called Vite (French for fast).

What is vue CLI plugin?

Vue CLI uses a plugin-based architecture. If you inspect a newly created project's package. json , you will find dependencies that start with @vue/cli-plugin- . Plugins can modify the internal webpack configuration and inject commands to vue-cli-service .


2 Answers

vue-cli-service uses Webpack with a default configuration of

entry: {
  app: [
    './src/main.js'
  ]
}

This can be altered in vue.config.js if you wish. See https://cli.vuejs.org/guide/webpack.html#simple-configuration

Webpack will build a JS bundle, starting at the entry then inject that into the index.html file and that's how your app starts.

You can see the entire configuration for your app using

vue inspect

See https://cli.vuejs.org/guide/webpack.html#inspecting-the-project-s-webpack-config

like image 122
Phil Avatar answered Oct 16 '22 09:10

Phil


It is hardcoded in @vue.

Relative Path: node_modules/@vue/cli-service/lib/config/base.js

Line 28-37:

    webpackConfig
      .mode('development')
      .context(api.service.context)
      .entry('app')
        .add('./src/main.js')
        .end()
      .output
        .path(api.resolve(options.outputDir))
        .filename(isLegacyBundle ? '[name]-legacy.js' : '[name].js')
        .publicPath(options.publicPath)
like image 37
Abby Chau Yu Hoi Avatar answered Oct 16 '22 11:10

Abby Chau Yu Hoi