@Dale-Lin
2022-09-16T17:32:40.000000Z
字数 732
阅读 303
TypeScript
babel/preset-typescript
可以使 babel 编译 ts 文件
pn install @babel/cli @babel/core @babel/preset-typescript -D
babel.config.js
module.exports = {
"presets": ["@babel/preset-env", "@babel/preset-typescript"]
}
pn install gulp-typescript
// gulpfile.js
import gulp from 'gulp'
import ts from 'gulp-typescript'
gulp.task('default', function() {
const tsResult = gulp
.src("src/*.ts")
.pipe(
ts({
onImplicitAny: true,
out: "output.js"
})
)
return tsResult.js.pipe(gulp.dest("built/local"))
})
pn install ts-loader -D
const path = require('path')
module.exports = {
entry: './src/index.ts',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
}
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
}
}