在这里构建一个现代的Angular应用程序。
我正在使用gulp-webpack进行快速开发构建。我需要webpack用于我的打字稿捆绑,因为我显然依赖于某些节点模块。但奇怪的是,gulp-webpack似乎并没有自动解析导入到我的node_modules目录!因此,它会抛出大约一百万个打字稿错误,说它无法找到模块,而我的捆绑包没有例如角度。
这是我的(缩写)gulpfile:
var gulp = require('gulp')
var path = require('path');
// var concat = require('gulp-concat')
var expect = require('gulp-expect-file')
var plumber = require('gulp-plumber')
var sourcemaps = require('gulp-sourcemaps')
// var uglify = require('gulp-uglify')
var webpack = require('gulp-webpack')
var sass = require('gulp-sass')
var nodemon = require('gulp-nodemon')
var ts = require('gulp-typescript')
var del = require('del')
var rename = require('gulp-rename')
var inject = require('gulp-inject-string')
// Client-side javascript to single js file
gulp.task('js', function ()
{
gulp.safeSrc('src/app/main.ts')
.pipe(sourcemaps.init())
.pipe(webpack({
context: __dirname,
entry: ['./src/app/main'],
resolve: {
modulesDirectories: ["./node_modules"],
extensions: ['.ts', '.js']
},
resolveLoader: {
root: path.resolve(__dirname, 'node_modules')
},
output: {
filename: "bundle.js"
},
module: {
loaders: [
{
test: /\.js$/,
loader: 'babel-loader'
},
{
test: /\.ts$/,
loader: 'ts-loader'
}
],
},
}))
.pipe(sourcemaps.write())
.pipe(gulp.dest('public'))
})
这是我的app.component.ts - 我开始使用import 'zone.js'
> ./src/app/app.component.ts中的错误找不到模块:错误:不能 解决模块' zone.js'在C:\ appdir \ src \ app @ ./src/app/app.component.ts 12:0-18
import 'zone.js';
import 'reflect-metadata';
import { Component } from '@angular/core';
import { Observable } from 'rxjs/Rx';
import { Store } from '@ngrx/store';
import { AppStore } from '../models/application-store';
import { AuthSvc } from './auth/auth.svc';
import { Action } from './actions'
@Component({
selector: 'my-app',
template: `
<div class="app">
<main-header>
</main-header>
<router-outlet></router-outlet>
</div>`
})
export class AppComponent {
error: any;
showNgFor = false;
constructor ()
{
}
}
发生了什么?
答案 0 :(得分:0)
gulp-webpack是一个绝对古老的npm包。
这里的解决方案是使用webpack-stream
,这是与webpack 3.0最新的</ p>