I want to import a submodule from a ts file into my project. The problem is that the output file includes the entire imported file and not only the imported object.
I have an example.ts file with several exports:
export enum e1{a, b}
export enum e2{c, d}
export class exampleclass
{
static f()
{
return 1;
}
}
Update: I have another file - exampleUser.ts which imports parts from example.ts.
import {e2} from "./example";
export enum eu1{a, b}
export enum eu2{c, d}
I have a 3rd file - main.ts which imports parts from exampleUser.ts. When I use the following import
import {eu2} from "./exampleUser";
and transpile the project (using webpack) the bundled output contains un-used parts of code from exampleUser.ts and from example.ts.
tsconfig.json:
{
"compilerOptions": {
"target": "es3",
"module": "es6",
"allowJs": true,
"checkJs": false,
"sourceMap": true,
"removeComments": true,
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
}
}
package.json:
{
"sideEffects": false
"devDependencies": {
"concurrently": "^3.6.0",
"ts-loader": "^4.3.0",
"typescript": "^2.8.3",
"webpack": "^4.8.3",
"webpack-cli": "^2.1.3"
},
}
webpack.prod.js:
{
mode: 'production',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
}
]
},
optimization: {
minimize: true, // Control if the output is monified (and uglified) or not
usedExports: true
},
}
package-lock.json:
{
"ts-loader": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ts-loader/-/ts-loader-4.3.0.tgz",
"integrity": "sha512-+zduqQJaeouVrGY3y6+nUG7+OE1+Q7slGCHsiQM/aITCEZ0og3GxrJVsnjM5QcWvOcu9C4VR5dP+egIyT+sNNg==",
"dev": true,
"requires": {
"chalk": "2.4.1",
"enhanced-resolve": "4.0.0",
"loader-utils": "1.1.0",
"micromatch": "3.1.10",
"semver": "5.5.0"
}
}
}
Is it possible to import only the relevant code?