VUE.js:从相对路径而非根目录将组件导入另一个组件

时间:2019-02-14 14:12:43

标签: vue.js vue-component

也许有人可以提供帮助?

我的应用结构

appContainer
– appName
— appVersion
---- node_modules
---- src
------ compnents
------- home.vue
– components
— home.vue

在appContainer / appName / appVersion / src / components / home.vue中导入时出现错误

[Vue警告]:无法解析异步组件:函数appHome(){返回 webpack_require .e(/ *!import()/ 2).then( webpack_require > .bind(null,/!…/…/…/ components / home.vue * /“…/ components / home.vue”))); }原因:错误:找不到模块“ vue” vue.esm.js:628

[WDS]启用热模块更换。 client:77

[WDS]编译时出错。禁止重新加载。 client:162

…/ components / home.vue找不到模块:错误:无法解析“ C:\ xampp \ htdocs \ www \ intervue \ ankiety \ components”中的“ vue”

 <template>
    <app-home></app-home>
</template>
<script>
    export default {
        name: 'home',
        components:{
            'app-home': () => import('../../../components/home.vue')
        }
    }
</script>

//我的webpack.config.js

var path = require('path')
var webpack = require('webpack')
const VueLoaderPlugin = require('vue-loader/lib/plugin')

module.exports = {
  entry: [
    "core-js/modules/es6.promise",
    "core-js/modules/es6.array.iterator",
    path.resolve(__dirname, "src/main.js"),
  ],
  output: {
    path: path.resolve(__dirname, './dist'),
    publicPath: '/dist/',
    filename: 'build.js'
  },
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          'vue-style-loader',
          'css-loader'
        ],
      },      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          loaders: {
          },
          failOnWarning: true
          // other vue-loader options go here
        }
      },
      {
        test: /\.js$/,
        use: [ 'babel-loader'],
        exclude: /node_modules/
      },
      {
        test: /\.(png|jpg|gif|svg)$/,
        loader: 'file-loader',
        options: {
          name: '[name].[ext]?[hash]'
        }
      }
    ]
  },
  resolve: {
    alias: {
      'vue$': 'vue/dist/vue.esm.js'
    },
    extensions: ['*', '.js', '.vue', '.json']
  },
  devServer: {
    historyApiFallback: true,
    noInfo: true,
    overlay: true
  },
  performance: {
    hints: false
  },
  plugins:[
    new VueLoaderPlugin()
  ],
  devtool: '#eval-source-map'
}

if (process.env.NODE_ENV === 'production') {
  module.exports.devtool = '#source-map'
  // http://vue-loader.vuejs.org/en/workflow/production.html
  module.exports.plugins = (module.exports.plugins || []).concat([
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: '"production"'
      }
    }),

    new webpack.optimize.UglifyJsPlugin({
      sourceMap: true,
      compress: {
        warnings: false
      }
    }),
    new webpack.LoaderOptionsPlugin({
      minimize: true
    })
  ])
}

//。babelrc

{
  "presets": ["@babel/preset-env","@babel/preset-react"],
  "plugins": ["@babel/plugin-syntax-dynamic-import"]
}

0 个答案:

没有答案