尝试将我的 angular2 应用程序与 webpack2 和 angular2-template-loader 捆绑在一起,但出现此错误:
ERROR in ./~/@angular/compiler/src/compile_metadata.js
Module not found: Error: Can't resolve './' in 'C:\Users\eagor\Documents\work\node_modules\@angular\compiler\src'
@ ./~/@angular/compiler/src/compile_metadata.js 393:22-35
@ ./~/@angular/compiler/index.js
@ ./~/@angular/platform-browser-dynamic/src/platform-browser-dynamic.js
@ ./~/@angular/platform-browser-dynamic/index.js
@ ./src/login/index.js
没有angular2-template-loader
它的bunldes就好了。
src/login/index.js:
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { LoginModule } from './src/login.module';
document.addEventListener('DOMContentLoaded', function() {
platformBrowserDynamic()
.bootstrapModule(LoginModule);
});
src/login/src/login.module.js
export class LoginModule {
// make empty for example.
}
webpack.config.js:
var path = require("path");
module.exports = {
entry: {
login: "./src/login/index.js"
},
output: {
path: path.resolve(__dirname, "wwwroot/bundles"),
filename: "[name].min.js"
},
module: {
loaders: [
{
test: /\.js$/, exclude: /node_modules/,
loader: "babel-loader"
},
// adding this loader breaks
{
test: /\.js$/,
loaders: ['angular2-template-loader'],
exclude: [/\.(spec)\.js$/]
},
{
test: /\.(html|css)$/,
loader: 'raw-loader'
}
]
}
};