source

파일명이 아닌 부모 디렉토리 이름만 언급하여 index.vue를 Import하는 방법

goodcode 2022. 7. 23. 14:16
반응형

파일명이 아닌 부모 디렉토리 이름만 언급하여 index.vue를 Import하는 방법

저는 Vue CLI 3을 사용하여 Vue 애플리케이션을 구축하고 있습니다.

Import가 필요한 경우index.js이름이 붙은 디렉토리에 있습니다.Dir1, 를 사용하여 Import 할 수 있습니다.import file1 from '@/components/Dir1/근데 왜 그런지 잘 안 돼.vue확장 파일

다음과 같은 파일 이름을 명시적으로 언급해야 합니다.import Title from @/components/Title/index.vue.

를 Import 하려면 , 설정에 어떠한 변경을 가할 필요가 있습니까..vue파일 이름을 언급하지 않고 확장 파일을 사용할 수 있습니까?

이게 Vue랑 같이 하는 방법이에요.

개발 환경의 요구에 맞게 구성을 약간 조정해야 할 수 있습니다.이것은 완전한 설정은 아니지만, NPM 디렉토리명 Web pack-plugin 매뉴얼에 근거해 실시할 필요가 있는 작업에 관한 가이드 라인에 주의해 주세요.

webpack.config.js 에는 다음 항목이 있습니다(Webpack 3).

const DirectoryNamedWebpackPlugin = require('directory-named-webpack-plugin');
// ...
let config = {
  // ...
  module: {
    rules: [
      {
        test: /\.(js|vue)$/,
        exclude: /node_modules/,
        use: 'babel-loader'
      }
    ]
  },
  resolve: {
    modules: ['components', 'node_modules'],
    extensions: ['.js', '.vue'],
    plugins: [
      new DirectoryNamedWebpackPlugin(true)
    ]
  }
  // ...
}
modules.exports = config;

Vue에 대해 가져오고 수정됨: React에서 웹 팩을 사용하여 구성 요소를 재귀적으로 가져옵니다.

언급URL : https://stackoverflow.com/questions/54379465/how-to-import-index-vue-by-just-mentioning-the-parent-directory-name-rather-than

반응형