2017-03-15 150 views
1

我是新來angular2和的WebPack的WebPack,我已經安裝的WebPack和想用的WebPack,以儘量減少文件的大小,這裏是webpack.config.js放置在根文件夾無法實現angular2

var HtmlWebpackPlugin = require('html-webpack-plugin'); 


module.exports = { 
    entry: { 
    app: './src/main.ts' 
}, 
    output: { 
    filename: 'bundle.js' 
}, 
    module: { 
    rules: [ 
     { 
     test: /\.ts$/, 
     loaders: [ 
      { 
      loader: 'awesome-typescript-loader', 
      options: { configFileName: helpers.root('src', 'tsconfig.json') } 
      } , 'angular2-template-loader' 
     ] 
     }  
    ] 
    }, 
plugins: [ 
    new HtmlWebpackPlugin({ 
     template: 'src/index.html' 
    }) 
    ] 
}; 

,這裏是根據文檔我的package.json文件也放置在根文件夾

{ 
    "name": "angular-quickstart", 
    "version": "1.0.0", 
    "description": "QuickStart package.json from the documentation, supplemented with testing support", 
    "scripts": { 
    "build": "webpack --progress", 
    "build:watch": "tsc -p src/ -w", 
    "build:e2e": "tsc -p e2e/", 
    "serve": "lite-server -c=bs-config.json", 
    "serve:e2e": "lite-server -c=bs-config.e2e.json", 
    "prestart": "npm run build", 
    "start": "concurrently \"npm run build:watch\" \"npm run serve\"", 
    "pree2e": "npm run build:e2e", 
    "e2e": "concurrently \"npm run serve:e2e\" \"npm run protractor\" --kill-others --success first", 
    "preprotractor": "webdriver-manager update", 
    "protractor": "protractor protractor.config.js", 
    "pretest": "npm run build", 
    "test": "concurrently \"npm run build:watch\" \"karma start karma.conf.js\"", 
    "pretest:once": "npm run build", 
    "test:once": "karma start karma.conf.js --single-run", 
    "lint": "tslint ./src/**/*.ts -t verbose" 
    }, 
    "keywords": [], 
    "author": "", 
    "license": "MIT", 
    "dependencies": { 
    "@angular/common": "~2.4.0", 
    "@angular/compiler": "~2.4.0", 
    "@angular/core": "~2.4.0", 
    "@angular/forms": "~2.4.0", 
    "@angular/http": "~2.4.0", 
    "@angular/platform-browser": "~2.4.0", 
    "@angular/platform-browser-dynamic": "~2.4.0", 
    "@angular/router": "~3.4.0", 
    "angular-in-memory-web-api": "~0.2.4", 
    "systemjs": "0.19.40", 
    "core-js": "^2.4.1", 
    "rxjs": "5.0.1", 
    "zone.js": "^0.7.4" 
    }, 
    "devDependencies": { 
    "@types/jasmine": "2.5.36", 
    "@types/node": "^6.0.46", 
    "awesome-typescript-loader": "^3.1.2", 
    "canonical-path": "0.0.2", 
    "concurrently": "^3.2.0", 
    "jasmine-core": "~2.4.1", 
    "karma": "^1.3.0", 
    "karma-chrome-launcher": "^2.0.0", 
    "karma-cli": "^1.0.1", 
    "karma-jasmine": "^1.0.2", 
    "karma-jasmine-html-reporter": "^0.2.2", 
    "lite-server": "^2.2.2", 
    "lodash": "^4.16.4", 
    "protractor": "~4.0.14", 
    "rimraf": "^2.5.4", 
    "tslint": "^3.15.1", 
    "typescript": "~2.0.10", 
    "webpack": "^2.2.1" 
    }, 
    "repository": {} 
} 

所有我們要做的是在腳本中包含親命令在的package.json的perty運行的命令,所以我已經包括腳本屬性這樣

"scripts": { 
    "build": "webpack --progress", 
--- 
-- 
} 

這樣,當我像這樣運行 NPM運行以下命令來構建應該建立從項目開始文件main.ts遞歸地給我一個輸出,如webpack.config.js中提到的,但我得到這樣的錯誤 enter image description here 不知道怎麼回事,如果任何人都可以提供給我至少一個適當的文檔材料有很大的幫助,我指this文件,這是沒有幫助,謝謝

回答

1

你的問題可以升級你的NPM和Node.js的

這是一個良好的開端使用的WebPack 角2應用它擁有AOT,樹搖,生產服務器和開發服務器Here you go