webpack从0开始搭建react的ts开发环境(4)
2020-01-16 本文已影响0人
汤姆猫_6074
本章演示基本的ts转译成js
webpack从0开始搭建react的ts开发环境(3)
demo https://github.com/757566833/webpack-guide
1.添加ts支持
yarn add ts-loader --dev
2.修改webpack.config.js
const path = require('path');
module.exports = {
entry: './src/app.ts',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'app.js'
},
module: {
rules: [{
test: /\.tsx?$/,
loader: "ts-loader",
exclude: /node_modules/,
}]
}
};
3.将src下的app.js 改为app.ts
const str:string = 'hello ts';
console.log(str)
- npm run webpack
5.node ./dist/app.js