awesome-typescript-loader
awesome-typescript-loader copied to clipboard
Webpack 4: Cannot create declaration file
Im trying to bundle a library i wrote with webpack and create the following files:
./dist
- index.js // for easy lookup - no minification - with sourcemap
- index.min.js // for production - with minification - with sourcemap
- index.d.ts // for debugging for Typescript applciations
my library has all its sources in: ./src/*
I have a file ./src/index.ts that exports what i want to export for my consumers and i want to compile this file and create the files i mentioned above.
The problem is that it succeed to create the source files, but the declaration file (index.d.ts) is missing, though i added the option: "declaration: true" in tsconfig.json.
Reproduce
im running the command:
webpack -d --env.NODE_ENV=develop
here is my webpack configuration file:
var nodeExternals = require('webpack-node-externals');
var WebpackBuildNotifierPlugin = require('webpack-build-notifier');
var webpack = require('webpack');
var path = require('path');
var envData = {
'develop': {
out: 'index.js'
},
'production': {
out: 'index.min.js'
}
};
var webpack_opts = (env) => ({
entry: ["./src/index.ts"],
target: 'node',
output: {
filename: `${envData[env.NODE_ENV].out}`,
libraryTarget: "commonjs2"
},
resolve: {
extensions: ['.ts', '.js'],
alias: {
'@lib': path.resolve(__dirname, 'src/')
}
},
plugins: [
new WebpackBuildNotifierPlugin({
title: 'Webpack Build'
})
],
devtool: 'inline-source-map',
module: {
rules: [{
test: /\.tsx?$/,
loader: "awesome-typescript-loader"
}]
}
});
module.exports = webpack_opts;
and my tsconfig.json file:
{
"compilerOptions": {
"target": "es5",
"baseUrl": "./",
"lib": [
"es2015",
"dom",
"es6",
"esnext"
],
"types": [
"jest",
"node",
"lodash",
"reflect-metadata"
],
"paths": {
"@lib/*": [
"src/*"
]
},
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"declaration": true,
"outDir": "build",
"typeRoots": [
"node_modules/@types"
]
},
"include": [
"src/**/*.ts"
],
"files": [
"src/index.ts"
],
"exclude": [
"node_modules"
]
}
Additional info:
Webpack version: 4.2.0 awesome-typescript-loader-version: 4.0.1 nodejs version: 9.5.0 npm version: 5.6.0
Have you made any progress with that please?