如何在 vue-cli 上更改 main.js 的路径?

Posted

技术标签:

【中文标题】如何在 vue-cli 上更改 main.js 的路径?【英文标题】:How to change path of main.js on vue-cli? 【发布时间】:2019-02-20 01:51:08 【问题描述】:

我使用 vue-cli

我想更改 main.js 和其他 vue 源文件的路径

所以,我尝试更改 build/webpack.base.conf.js

像这样。(它是 build/webpack.base.conf.js 的一部分

(之前)

module.exports = 
  entry: 
    app: './src/main.js'
  ,

(之后)

module.exports = 
  entry: 
    app: '../src/main.js'
  ,

我试着开始

npm run dev

但它不起作用

它打印出这个错误信息

These dependencies were not found:

* vue in ../src/main.js, ../src/store/index.js and 9 others
* vue-router in ../src/main.js
* vuex-router-sync in ../src/main.js
* es6-promise/auto in ../src/main.js
* vuex in ../src/store/index.js
* !!babel-loader!../../myVue/node_modules/vue-loader/lib/selector?type=script&index=0!./App.vue in ../src/components/App.vue
* !!babel-loader!../../myVue/node_modules/vue-loader/lib/selector?type=script&index=0!./Dash.vue in ../src/components/Dash.vue
* !!babel-loader!../../myVue/node_modules/vue-loader/lib/selector?type=script&index=0!./Login.vue in ../src/components/Login.vue
* !!babel-loader!../../myVue/node_modules/vue-loader/lib/selector?type=script&index=0!./404.vue in ../src/components/404.vue
* !!babel-loader!../../../myVue/node_modules/vue-loader/lib/selector?type=script&index=0!./Device.vue in ../src/components/views/Device.vue
* !!babel-loader!../../../myVue/node_modules/vue-loader/lib/selector?type=script&index=0!./Messagegt.vue in ../src/components/views/Messagegt.vue
* !!babel-loader!../../../myVue/node_modules/vue-loader/lib/selector?type=script&index=0!./Monitor.vue in ../src/components/views/Monitor.vue
* !!babel-loader!../../../myVue/node_modules/vue-loader/lib/selector?type=script&index=0!./Firewall.vue in ../src/components/views/Firewall.vue
* !!babel-loader!../../../myVue/node_modules/vue-loader/lib/selector?type=script&index=0!./Performance.vue in ../src/components/views/Performance.vue
* !!vue-style-loader!css-loader?"minimize":false,"sourceMap":false!../../myVue/node_modules/vue-loader/lib/style-compiler/index?"id":"data-v-44394314","scoped":false,"hasInlineConfig":false!../../myVue/node_modules/vue-loader/lib/selector?type=styles&index=0!./Dash.vue in ../src/components/Dash.vue
* !!vue-style-loader!css-loader?"minimize":false,"sourceMap":false!../../myVue/node_modules/vue-loader/lib/style-compiler/index?"id":"data-v-1db248d7","scoped":false,"hasInlineConfig":false!../../myVue/node_modules/vue-loader/lib/selector?type=styles&index=0!./Login.vue in ../src/components/Login.vue
* !!vue-style-loader!css-loader?"minimize":false,"sourceMap":false!../../myVue/node_modules/vue-loader/lib/style-compiler/index?"id":"data-v-808c2e74","scoped":false,"hasInlineConfig":false!../../myVue/node_modules/vue-loader/lib/selector?type=styles&index=0!./404.vue in ../src/components/404.vue
* vue-hot-reload-api in ../src/components/App.vue, ../src/components/Dash.vue and 16 others

To install them, you can run: npm install --save vue vue-router vuex-router-sync es6-promise/auto vuex !!babel-loader!../../myVue/node_modules/vue-loader/lib/selector?type=script&index=0!./App.vue !!babel-loader!../../myVue/node_modules/vue-loader/lib/selector?type=script&index=0!./Dash.vue !!babel-loader!../../myVue/node_modules/vue-loader/lib/selector?type=script&index=0!./Login.vue !!babel-loader!../../myVue/node_modules/vue-loader/lib/selector?type=script&index=0!./404.vue !!babel-loader!../../../myVue/node_modules/vue-loader/lib/selector?type=script&index=0!./Device.vue !!babel-loader!../../../myVue/node_modules/vue-loader/lib/selector?type=script&index=0!./Messagegt.vue !!babel-loader!../../../myVue/node_modules/vue-loader/lib/selector?type=script&index=0!./Monitor.vue !!babel-loader!../../../myVue/node_modules/vue-loader/lib/selector?type=script&index=0!./Firewall.vue !!babel-loader!../../../myVue/node_modules/vue-loader/lib/selector?type=script&index=0!./Performance.vue !!vue-style-loader!css-loader?"minimize":false,"sourceMap":false!../../myVue/node_modules/vue-loader/lib/style-compiler/index?"id":"data-v-44394314","scoped":false,"hasInlineConfig":false!../../myVue/node_modules/vue-loader/lib/selector?type=styles&index=0!./Dash.vue !!vue-style-loader!css-loader?"minimize":false,"sourceMap":false!../../myVue/node_modules/vue-loader/lib/style-compiler/index?"id":"data-v-1db248d7","scoped":false,"hasInlineConfig":false!../../myVue/node_modules/vue-loader/lib/selector?type=styles&index=0!./Login.vue !!vue-style-loader!css-loader?"minimize":false,"sourceMap":false!../../myVue/node_modules/vue-loader/lib/style-compiler/index?"id":"data-v-808c2e74","scoped":false,"hasInlineConfig":false!../../myVue/node_modules/vue-loader/lib/selector?type=styles&index=0!./404.vue vue-hot-reload-api
> Listening at http://localhost:8080

如何更改 vue 源路径?

请帮帮我

【问题讨论】:

【参考方案1】:

那条路径中有main.js吗?

以下目录结构相同:

- root direcotry
 - src
     - main.js
 - directory
     - package.json
      - other files..

如果vue 文件位于以下路径中。

- root direcotry
 - src
     - main.js
 - directory
     - src
          - App.vue
     - package.json
      - other files..

你必须从 main.js 加载为import App from '../directory/src/App.vue'

但如果vue 文件位于以下路径中。

- root direcotry
 - src
     - main.js
     - App.vue
 - directory
     - package.json
      - other files..

你必须从 main.js 加载为import App from './App.vue'

不就是移动 main.js 吗?

检查 main.js。

【讨论】:

以上是关于如何在 vue-cli 上更改 main.js 的路径?的主要内容,如果未能解决你的问题,请参考以下文章

将变量从main.js暴露给vue-cli项目中的其他脚本

vue如何在 Vue-cli 创建的项目中引入iView

vue-cli 如何使用vue-awesome?

在脚手架vue-cli上引入插件JQUERY

vue-cli 3.0 ./src/main.js in multi (webpack)-dev-server/client?http://10.0.68.112:8080/sockjs-node (

vue-cli中的main.js中 new Vue 中的template属性啥意思