温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

使用webpack2怎么搭建一个angular2项目

发布时间:2021-03-11 15:56:48 阅读:151 作者:Leah 栏目:web开发
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

这期内容当中小编将会给大家带来有关使用webpack2怎么搭建一个angular2项目,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

  1. npm install,安装依赖包

  2. 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配置文件开发版:

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",
  //debugtrue, webpack2 已切换到plugins中,据说在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, {
  inlinetrue,
  hottrue,
  port: PORT,
  stats: {
    colorstrue
  }
}).listen(PORT, 'localhost', (err) => {
  console.log(123)
})

上述就是小编为大家分享的使用webpack2怎么搭建一个angular2项目了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI

开发者交流群×