您好,登錄后才能下訂單哦!
這期內(nèi)容當中小編將會給大家?guī)碛嘘P使用webpack2怎么搭建一個angular2項目,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
npm install
,安裝依賴包
npm run dev
,啟動本地工程,在localhost:1699進行預覽
package.json { "name": "angular-webpack", "version": "1.0.0", "description": "webpack2 & angular2", "scripts": { "dev": "babel-node ./src/config/dev.js" }, "author": "Travis Lee", "license": "ISC", "dependencies": { "@angular/common": "~4.0.0", "@angular/compiler": "~4.0.0", "@angular/core": "~4.0.0", "@angular/forms": "~4.0.0", "@angular/http": "~4.0.0", "@angular/platform-browser": "~4.0.0", "@angular/platform-browser-dynamic": "~4.0.0", "@angular/router": "~4.0.0", "core-js": "^2.4.1", "es6-shim": "^0.35.3", "reflect-metadata": "^0.1.8", "rxjs": "5.0.1", "zone.js": "^0.8.4" }, "devDependencies": { "babel-core": "^6.25.0", "babel-loader": "^7.1.0", "babel-preset-es2015": "^6.24.1", "clean-webpack-plugin": "^0.1.16", "css-loader": "^0.28.4", "extract-text-webpack-plugin": "^2.1.2", "path": "^0.12.7", "style-loader": "^0.18.2", "ts-loader": "^2.1.0", "typescript": "^2.3.4", "typings": "^2.1.1", "uglifyjs-webpack-plugin": "^0.4.6", "webpack": "^2.6.1", "webpack-dev-server": "^2.5.0", "webpack-merge": "^4.1.0" } }
webpack配置文件開發(fā)版:
import path from 'path' import config from "./webpack.config" import merge from "webpack-merge" import webpack from "webpack" import webpackDevServer from "webpack-dev-server" import { format } from 'util' let PORT = 1699; let PUBLIC_PATH = "http://localhost:" + PORT + "/"; let webpackConifg = merge(config, { devtool: "source-map", //debug: true, webpack2 已切換到plugins中,據(jù)說在3中將取消 entry: { main: [ format("webpack-dev-server/client?%s", PUBLIC_PATH), "webpack/hot/dev-server", "./src/main.ts" ] }, output: { path: path.resolve(__dirname, '../../dist'), publicPath: PUBLIC_PATH, filename: '[name].js' }, plugins: [ new webpack.HotModuleReplacementPlugin() ] }) const compiler = webpack(webpackConifg); new webpackDevServer(compiler, { inline: true, hot: true, port: PORT, stats: { colors: true } }).listen(PORT, 'localhost', (err) => { console.log(123) })
上述就是小編為大家分享的使用webpack2怎么搭建一個angular2項目了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關知識,歡迎關注億速云行業(yè)資訊頻道。
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。