zoukankan      html  css  js  c++  java
  • typeScript 之 (5) 打包

    注意执行以下命令安装包

    npm init -y
    npm i typescript
    npm i ts-loader
    npm i webpack  -g
    npm i webpack-cli  -g
    npm html-webpack-plugin
    npm webpack-dev-server
    npm @babel/core
    npm @babel/preset-env
    npm babel-loader
    npm core-js

    package.json 去配置

    执行 npm run start 就可以运行

    "scripts": {
        "test": "echo "Error: no test specified" && exit 1",
        "build": "webpack",
        "start": "webpack serve --open chrome.exe"
      },

    webpack.config.js 配置

    const {resolve} = require('path')
    const HtmlWebpackPlugin = require('html-webpack-plugin')
    const {CleanWebpackPlugin} = require('clean-webpack-plugin')
    
    module.exports = {
     entry:['./src/index.ts'],
     output:{
      filename:'bundle.js',
      path:resolve(__dirname,'dist'),
      // 打包时不要箭头函数
      environment:{
        arrowFunction:false
      }
     },
     module:{
       rules:[
         {
           test:/.ts$/,
           use:[
             {
              loader:'babel-loader',
              options:{
                //设置预定义的环境
                presets:[
                  [
                    '@babel/preset-env',
                    {
                      //按需加载
                      useBuiltIns:'usage',
                      "corejs":{
                        version:3
                      },
                      targets:{
                        chrome:'68',
                        firefox:'60',
                        ie:'9',
                        safari:'10',
                        edge:'17'
                      }
                    }
                  ]
                ]
              }
             },
             'ts-loader'
          ],
           exclude:/node_modules/
         },
       ]
     },
     plugins:[
        new CleanWebpackPlugin(),
        new HtmlWebpackPlugin({
          template:'./src/index.html'
        })
     ],
     mode:"development",
     devServer:{
       hot:true
     },
     resolve:{
       //省略后缀名
       extensions:['.ts','.js']
     }
    
    }

    tsconfig.json

    {
      "compilerOptions": {
        "module":"es2015",
        "target":"es2015",
        // 这个是总检查配置的总开关(只与三个属性有关)
        "strict": true
      }
    }
  • 相关阅读:
    树链剖分(转载)
    随机数生成器
    错排公式的理解与推导(转载)
    容斥原理(转载)
    Luogu 3758 [TJOI2017]可乐(有向图邻接矩阵幂的意义 矩阵快速幂)
    vue input复选框checkbox默认样式纯css修改
    vue 页面切换的时候vuex记录之前的滚动条位置
    vue从入门到进阶
    es6 学习笔记
    vue 项目笔记
  • 原文地址:https://www.cnblogs.com/zmztya/p/14718671.html
Copyright © 2011-2022 走看看