码迷,mamicode.com
首页 > 其他好文 > 详细

typescript 基本环境 搭建

时间:2019-03-14 21:17:18      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:source   enc   license   key   3.2   new   目录   client   2.0   

typescript 基本环境 搭建

工具

vs code

步骤

扩展-- 主题

One Dark Pro

npm  init
package.json
{
  "name": "client-side",
  "version": "1.0.0",
  "description": "source code of ts-learning",
  "main": "./src/index.ts",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "typescript",
    "source_code",
    "hequan"
  ],
  "author": "hequan <hequan2011@sina.com>",
  "license": "MIT"
}
目录

build
    webpack.config.js
package.json
src
    api  
    assets
            font
            img
    config  
    tools  
    utils
typings
安装

npm install -g typescript  tslint  ts-loader   cross-env 
tsc --init

npm install  webpack  webpack-cli webpack-dev-server  clean-webpack-plugin    html-webpack-plugin  -D
npm install  typescript  -S
package.json

{
  "name": "client-side",
  "version": "1.0.0",
  "description": "source code of ts-learning",
  "main": "./src/index.ts",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "cross-env NODE_ENV=development webpack-dev-server --config ./build/webpack.config.js",
    "build": "cross-env NODE_ENV=production webpack --config ./build/webpack.config.js"
  },
  "keywords": [
    "typescript"
  ],
  "author": "hequan<hequan2011@sina.com>",
  "license": "MIT",
  "devDependencies": {
    "clean-webpack-plugin": "^2.0.0",
    "cross-env": "^5.2.0",
    "html-webpack-plugin": "^3.2.0",
    "ts-loader": "^5.3.3",
    "webpack": "^4.29.6",
    "webpack-cli": "^3.2.3",
    "webpack-dev-server": "^3.2.1"
  },
  "dependencies": {
    "typescript": "^3.3.3333"
  }
}
webpack.config.js

const HtmlWebpackPlugin = require(‘html-webpack-plugin‘)
const CleanWebpackPlugin = require(‘clean-webpack-plugin‘)

module.exports = {
    entry: "./src/index.ts",
    output: {
        filename: "main.js"
    },
    resolve: {
        extensions: [‘.ts‘, ‘.tsx‘, ‘.js‘]
    },
    module: {
        rules: [{
            test: /\.tsx?$/,
            use: ‘ts-loader‘,
            exclude: /node_modules/
        }]
    },
    devtool: process.env.NODE_ENV === ‘production‘ ? false : ‘inline-source-map‘,
    devServer: {
        contentBase: ‘./dist‘,
        stats: ‘errors-only‘,
        compress: false,
        host: ‘localhost‘,
        port: 8089
    },
    plugins: [
        new CleanWebpackPlugin({
            cleanOnceBeforeBuildPatterns: [‘./dist‘]
        }),
        new HtmlWebpackPlugin({
            template: ‘./src/template/index.html‘
        })
    ]
}

typescript 基本环境 搭建

标签:source   enc   license   key   3.2   new   目录   client   2.0   

原文地址:https://blog.51cto.com/hequan/2363220

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!