• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

typeScript之(5)打包

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

 

注意执行以下命令安装包

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
  }
}

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap