Answer the question
In order to leave comments, you need to log in
How to open typescript module with export in global scope?
Good day. Typescript + webpack when compiling a simple file with a class, this class is available for global access. When adding an export/import, the file is executed, but the class is not available globally. How to fix?
I suppose that it is possible to somehow compile ts files separately without importing, then compile them into one, but how to set it up, I didn’t use the words import / export, did it work anyway?
const glob = require("glob");
module.exports = {
entry: glob.sync('./src/*.js'),
output: {
filename: 'module.js',
//path: path.resolve(__dirname, 'dist'),
},
optimization: {
minimize: false
}
};
Answer the question
In order to leave comments, you need to log in
I didn't understand anything, but
- "exporting" something to the global scope is bad practice, you need a good reason to do it
- write in a simple way - without 'module'
- configure webpack so that it compiles and collects ts files for you. you don't need to compile them separately and build them separately. how to do this is described here https://github.com/TypeStrong/ts-loader
Seems to have found the answer. For webpack added to the configuration
output: {
library: 'MyModule',
filename: 'example3.js',
import {Example1} from './example1';
import {Example2} from './example2';
export {Example1} from './example1';
export {Example2} from './example2';
export class Example3 {
constructor().....
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question