다음과 같은 기능이 예상대로 작동하지 않는 이유에 대한 간략한 설명을 얻기를 바랍니다. 바라건대 쉽게 간과 할 수 있습니다. Webpack이 없으면 현재 구현이 예상대로 작동합니다.Webpack 2 및 Angular 1 : 모듈 내보내기 및 가져 오기
이상적으로는 현재 구현을 유지하고 싶습니다. 구성 요소/컨트롤러/등을 등록하는 것이 자체 파일에서 수행되어야하며 상대 모듈을 가리켜 야합니다. 그러나 이것이 최선의 방법이 아니라면 또 다른 제안을보고 싶습니다.
파일 root.module은 루트 모듈을 정의한 다음 root.component 파일에서 해당 모듈의 구성 요소를 압정합니다.
모듈을 가져 오지 않습니다현재 구현 :
//root.component.js
'use strict';
var root = {
template: require('./root.html')
};
module.exports = angular
.module('root')
.component('root', root);
'use strict';
//root.module.js
module.exports = angular
.module('root', [
require('./common').name,
require('./components').name
]);
내가 할 경우, 다음 작품과로드 예상대로 모듈 :
//root.component.js
'use strict';
var root = {
template: require('./root.html')
};
module.exports = root;
//root.module.js
'use strict';
module.exports = angular
.module('root', [
require('./common').name,
require('./components').name
])
.component('root', require('./root.component'));
현재 디렉토리 트리 :
├── ./src
│ ├── ./src/app
│ │ ├── ./src/app/app.less
│ │ ├── ./src/app/app.spec.js
│ │ ├── ./src/app/common
│ │ │ ├── ./src/app/common/app.component.js
│ │ │ ├── ./src/app/common/app.controller.js
│ │ │ ├── ./src/app/common/app.html
│ │ │ ├── ./src/app/common/footer
│ │ │ │ ├── ./src/app/common/footer/app-footer.component.js
│ │ │ │ ├── ./src/app/common/footer/app-footer.controller.js
│ │ │ │ ├── ./src/app/common/footer/app-footer.html
│ │ │ │ └── ./src/app/common/footer/index.js
│ │ │ ├── ./src/app/common/header
│ │ │ │ ├── ./src/app/common/header/app-nav.component.js
│ │ │ │ ├── ./src/app/common/header/app-nav.controller.js
│ │ │ │ ├── ./src/app/common/header/app-nav.html
│ │ │ │ └── ./src/app/common/header/index.js
│ │ │ ├── ./src/app/common/index.js
│ │ │ └── ./src/app/common/sideBar
│ │ │ ├── ./src/app/common/sideBar/app-sidebar.component.js
│ │ │ ├── ./src/app/common/sideBar/app-sidebar.controller.js
│ │ │ ├── ./src/app/common/sideBar/app-sidebar.html
│ │ │ └── ./src/app/common/sideBar/index.js
│ │ ├── ./src/app/components
│ │ │ ├── ./src/app/components/auth
│ │ │ │ ├── ./src/app/components/auth/auth-form
│ │ │ │ │ ├── ./src/app/components/auth/auth-form/auth-form.component.js
│ │ │ │ │ ├── ./src/app/components/auth/auth-form/auth-form.controller.js
│ │ │ │ │ ├── ./src/app/components/auth/auth-form/auth-form.html
│ │ │ │ │ └── ./src/app/components/auth/auth-form/index.js
│ │ │ │ ├── ./src/app/components/auth/auth.service.js
│ │ │ │ ├── ./src/app/components/auth/auth.user.js
│ │ │ │ ├── ./src/app/components/auth/index.js
│ │ │ │ ├── ./src/app/components/auth/login
│ │ │ │ │ ├── ./src/app/components/auth/login/index.js
│ │ │ │ │ ├── ./src/app/components/auth/login/login.component.js
│ │ │ │ │ ├── ./src/app/components/auth/login/login.controller.js
│ │ │ │ │ └── ./src/app/components/auth/login/login.html
│ │ │ │ └── ./src/app/components/auth/register
│ │ │ │ ├── ./src/app/components/auth/register/index.js
│ │ │ │ ├── ./src/app/components/auth/register/register.component.js
│ │ │ │ ├── ./src/app/components/auth/register/register.controller.js
│ │ │ │ └── ./src/app/components/auth/register/register.html
│ │ │ └── ./src/app/components/index.js
│ │ ├── ./src/app/root.component.js
│ │ ├── ./src/app/root.html
│ │ └── ./src/app/root.module.js
│ └── ./src/index.ejs
└── ./webpack.config.js
두 번째 발췌 문장에서 require ('./ root.component')가 필요합니다. 처음에는 그렇지 않습니다. 그것은 명백한 문제입니다. – estus
@estus이므로 등록하고 첫 번째 방법으로 모듈을 요구할 방법이 없습니까? – alphapilgrim
무슨 뜻인가요? 내용을 실행하려면 파일을'require '해야합니다. 만약 당신이 그것을 요구하지 않는다면, 실행되지 않을 것입니다. 이것은 매우 간단합니다. 실제로 require ('./ root.component')가 없다면이 줄을 추가해야합니다. – estus