webpack4 打包TS


Typescript

安装  

npm install --save-dev typescript ts-loader

配置

  webpack.config.js

module.exports = {
  entry:'./src/app.ts',

  output:{
    filename:'[name].[hash:8].js'
  },
  module:{
    rules:[
      {
        test: /\.tsx?$/,
        use:'ts-loader',
        exclude:/node_modules/
      }
    ]
  },
  mode:'none'
}

  tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es5",
    "allowJs": true
  },
  "include": [
    "./src/*"
  ],
  "exclude": [
    "./node_modules"
  ]
}  

  ts

const NUM = 45

interface Cat{
  name: String,
  sex:String
}

function touchCat(cat:Cat) {
  console.log(cat.name)
}

touchCat({
  name:'tom',
  sex:'man'
})

  打包结果

/* 0 */
/***/ (function(module, exports) {

var NUM = 45;
function touchCat(cat) {
    console.log(cat.name);
}
touchCat({
    name: 'tom',
    sex: 'man'
});


/***/ })

声明文件

  typings


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM