javascript - 将 Javascript 转换为 Typescript。我构建的文件没有在我预期的地方结束
问题描述
我正在学习 Cypress 和 Typescript。我根据以下文章设置了我的文件:
将 JavaScript 项目转换为 Typescript,一次一个文件
webpack.config.js:
var path = require('path');
var webpack = require('webpack');
module.exports = {
mode: "development",
entry: {
index: "./cypress/integration/alloy_test.ts"
},
target: 'node',
: {
rules: [
{ test: /\.ts(x?)$/, loader: 'ts-loader' },
{ test: /\.json$/, loader: 'json-loader' }
]
},
plugins: [
new webpack.DefinePlugin({'process.env.NODE_ENV': '"production"'})
],
resolve: {
extensions: ['.ts', '.js', '.json']
},
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, 'lib'),
filename: '[name].js'
},
};
这里指定了目录 /lib,这是我希望所有生成的 Typescript 文件所在的位置。
tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"noImplicitAny": true,
"lib": [
"es5","es2015", "es6", "dom"
],
"types": ["cypress"]
}
}
包.json:
{
"name": "playground",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"cypress:open": "cypress open",
"build": "node_modules/.bin/webpack --config webpack.config.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@types/prompt-sync": "^4.1.0",
"cypress": "^3.1.0",
"json-loader": "^0.5.7",
"ts-loader": "^5.2.2",
"webpack": "^4.20.2",
"webpack-cli": "^3.1.2"
},
"dependencies": {
"ajv": "^6.0.0",
"ajv-keywords": "^3.2.0",
"typescript": "^3.1.3"
}
}
我正在运行 npm run build 来进行转译。
最后,我的一个 .ts 文件 /cypress/integration/alloy-test.ts - 已被转译到同一目录:/cypress/integration/alloy-test.js。
我期待它去/lib。
解决方案
推荐阅读
- html - 将鼠标移动到子菜单时,如何在父导航元素上保持悬停状态?
- kubernetes - 如何在 k8s 中转储每个命名空间的资源(CPU、内存)使用情况?
- augmented-reality - ARCore 使用哪些传感器?
- python - 按日期时间列对 Pandas Dataframe 的所有元素进行分组
- javascript - 将 CSS 变量导入 Typescript 文件
- reactjs - 反应 -> 状态管理
- amazon-web-services - 是否可以将 Amazon Web Application Firewall 与未托管在 AWS 实例上的应用程序一起使用?
- javascript - 如何从 Cloud Functions for Firebase 文件夹中读取证书文件
- sql - SQL 查询以查找 Date、TranscationAmount_US、TransactionAmount_UK
- javascript - Bootstrap 4.2 脚本未加载/工作