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