Bau*_*umi 27 webpack angular2-modules angular
我正在尝试将我的angular2自定义库之一迁移到RC.6 + Webpack.我的目录结构是:
- src - source TS files
- lib - transpiled JS files + definition files
- dev - development app to test if it works / looks ok.
- myCustomLib.js - barrel
- myCustomLib.d.ts
Run Code Online (Sandbox Code Playgroud)
在dev文件夹内尝试运行应用程序.我引导我的模块:
app.module.ts
import { BrowserModule } from "@angular/platform-browser";
import { NgModule } from "@angular/core";
import { AppComponent } from "./app.component";
import { MyCustomModule } from "../../myCustomLib";
@NgModule({
imports: [
BrowserModule,
MyCustomModule
],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule {
}
Run Code Online (Sandbox Code Playgroud)
现在使用webpack我捆绑了我的开发应用程序.
webpack.config.js
module.exports = {
entry: "./app/boot",
output: {
path: __dirname,
filename: "./bundle.js",
},
resolve: {
extensions: ['', '.js', '.ts'],
modules: [
'node_modules'
]
},
devtool: 'source-map',
module: {
loaders: [{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
}, {
test: /\.ts$/,
loader: 'awesome-typescript-loader',
exclude: /node_modules/
}]
},
watch: true
};
Run Code Online (Sandbox Code Playgroud)
但是当我尝试加载应用程序时,我收到一条消息:
metadata_resolver.js:230
Uncaught Error: Unexpected value 'MyCustomModule' imported by the module 'AppModule'
Run Code Online (Sandbox Code Playgroud)
我导入的桶文件看起来像:
myCustomLib.js
export * from './lib/myCustomLib.module';
Run Code Online (Sandbox Code Playgroud)
export { MyCustomModule } from './lib/myCustomLib.module';
Run Code Online (Sandbox Code Playgroud)
没有帮助.我也尝试从src目录导入模块- 同样的错误.MyCustomModule应该没问题,因为之前它与systemJS工作正常.
myCustomLib.module.ts:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
@NgModule({
imports: [
BrowserModule
]
})
export class MyCustomModule {}
Run Code Online (Sandbox Code Playgroud)
知道这个错误的原因是什么?我在这里看过类似的主题,但没有回答或暗示有帮助.
编辑:为了使示例更简单我已从MyCustomModule中删除所有 - 同样的问题...
中myCustomLib.js,尝试在导出之前导入
import { MyCustomModule } from './lib/myCustomLib.module;
export MyCustomModule;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13518 次 |
| 最近记录: |