相思资源网 Design By www.200059.com

webpack2和angular2搭建的项目

github地址:项目链接

  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",
  //debug: true, webpack2 已切换到plugins中,据说在3中将取消
  entry: {
    main: [
      format("webpack-dev-server/client", 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)
})

搭建中遇到的问题:

The URL 'localhost:1699/sockjs-node' is invalid, 

该问题是由于webpack配置文件中的publicPath前边没有加http://,导致url解析失败

Uncaught reflect-metadata shim is required when using class decorators,

 这个问题是由于main.ts文件中没有引入 reflect-metadata和zone.js


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

标签:
webpack搭建angular,webpack,angular,项目,webpack搭建angular

相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com

评论“详解用webpack2搭建angular2的项目”

暂无详解用webpack2搭建angular2的项目的评论...

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。