2017-12-07 1 views
1

나는 3 repos - client, backendinterfaces입니다.순수 TypeScript 라이브러리를 Webpack과의 종속성으로 사용하는 방법은 무엇입니까?

모두가 TypeScript로 작성되었습니다. 클라이언트 및 백엔드 repos는 빌드 단계에서 JavaScript로 컴파일 한 다음 서버에 배포합니다.

마지막 repo interfaces은 컴파일 될 예정이 아니지만 클라이언트와 백엔드 앱이 서로 통신하는 방식을 선언하는 클라이언트 및 백엔드 저장소에 대해 npm 종속성으로 사용됩니다.

interfaces repo를 도입하고 다른 repos에 종속성을 추가하기 전에 하드 코딩 된 메시지 유형 문자열을 사용했으며 모두 잘 컴파일되었습니다.

이제 interfaces 인 순수 TypeScript 종속성을 사용하여 client 또는 backend repos 코드에 유형을 삽입하고 올바르게 연결되어 있는지 확인할 수 있습니다.

하지만 Webpack에서는이 경우 제대로 설정되지 않은 문제가 있기 때문에 프로젝트를 컴파일 할 수 없습니다.

module: { 
    rules: [ 
     { 
      test: /\.js$/, 
      use: 'babel-loader', 
      // exclude: /node_modules/ 
     }, 
     { 
      test: /\.ts$/, 
      use: 'ts-loader', 
      exclude: /node_modules/ 
     } 
    ] 
}, 

웹팩과 구축을 위해 노력하는 동안 오류가 볼이 하나 : 나는 이것을 볼 나는 exclude: /node_modules/을 주석 경우

ERROR in ./node_modules/myapp_interfaces/interfaces/ClientRequestPayload.ts

Module parse failed: The keyword 'interface' is reserved (1:0)

You may need an appropriate loader to handle this file type.

여기

webpack.config.js의 관련 부분입니다 :

ERROR in ./node_modules/myapp_interfaces/index.ts

Module build failed: Error: Typescript emitted no output for /myapp/myapp_backend/node_modules/myapp_interfaces/index.ts.

You should not need to recompile .ts files in node_modules.

Please contact the package author to advise them to use --declaration --outDir.

이 인터페이스 코드는 내가 생각하는 프로젝트의 다른 폴더.

어떻게이 오류를 없애고 이것을 내 코드로 가져 와서 컴파일합니까?

답변

0

ts-loader에서/node_modules /를 제외하면이 폴더의 .ts 파일을 제대로 가져 오지 않을 것으로 예상하지 않습니까?

+0

나는 둘 다 시도했다 친절하게 위의 오류를 봐. –

+0

webpack "--display-error-details"옵션을 사용하여 webpack을 실행 했습니까? 어쩌면 당신은 더 많은 정보를 얻을 수 있습니다. – Kleioz

관련 문제