如何解决使用 ts-loader 运行 emitDeclarationOnly
目前我正在使用 bable-loader 从打字稿生成 javascript。但我也想生成打字稿声明。
为了解决这个问题,我只是在构建脚本的末尾添加了 tsc --emitDeclarationOnly
。
这种方法适用于构建但不适用于观看
因此我想仍然使用emitDeclarationsOnly 的ts-loader。我怎么一直收到以下错误
lerna ERR! yarn run build stdout:
$ cross-env NODE_ENV=production webpack --config ./webpack.config.js --mode production
assets by status 122 KiB [cached] 117 assets
./src/index.ts 39 bytes [built]
ERROR in ./src/index.ts
Module build failed (from ./node_modules/ts-loader/index.js):
Error: TypeScript emitted no output for G:\SOMEPATH\src\index.ts.
at makeSourceMapAndFinish (G:\SOMEPATH\node_modules\ts-loader\dist\index.js:53:18)
at successLoader (G:\SOMEPATH\node_modules\ts-loader\dist\index.js:40:5)
at Object.loader (G:\SOMEPATH\node_modules\ts-loader\dist\index.js:23:5)
webpack 5.11.1 compiled with 1 error in 8620 ms
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
我的 tsconfig 是
{
"compilerOptions": {
"alwaysStrict": true,/* Parse in strict mode and emit "use strict" for each source file. */
"declaration": true,"declarationMap": true,"esModuleInterop": true,/* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
"emitDeclarationOnly": true,"lib": ["ESNext","DOM"],"module": "esnext","moduleResolution": "node",/* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
"noImplicitAny": true,"noImplicitReturns": true,"noImplicitThis": true,/* Raise error on 'this' expressions with an implied 'any' type. */
"useDefineForClassFields": true,"outDir": "./dist/","sourceMap": true,"strict": true,/* Enable all strict type-checking options. */
"strictFunctionTypes": true,/* Enable strict checking of function types. */
"strictNullChecks": true,/* Enable strict null checks. */
"strictPropertyInitialization": true,/* Enable strict checking of property initialization in classes. */
"target": "es2015","types": []
/* Module Resolution Options */
},"exclude": ["node_modules"],"files": [
"./src/index.ts","./src/index.d.ts",]
}
网络包
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path');
const isProduction = process.env.NODE_ENV === 'production';
module.exports = {
cache: {
type: 'filesystem',},devtool: isProduction ? 'source-map' : 'source-map',entry: './src/index.ts',module: {
rules: [
{
enforce: 'pre',exclude: /node_modules/,test: /\.(ts|tsx)$/,use: [
{
loader: require.resolve('eslint-loader'),options: {
eslintPath: require.resolve('eslint'),],{
exclude: /node_modules/,use: ['ts-loader'],test: /\.tsx?$/,use: ['babel-loader'],output: {
filename: 'index.js',globalObject: 'this',library: 'data',libraryTarget: 'umd',path: path.resolve(__dirname,'dist'),resolve: {
extensions: ['.tsx','.ts','.js'],};
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。