1

I created a project using ng. I called ng eject to get a webpack.config.js. I added pug to the webpack. I want to pass the data from src/environments/environment.ts to pug but I can't figure out how to require the typescript file from a normal javascript file.

I can always change environment.ts to a json file or javascript file but would like to leave it the way it is.

Here is the environment.ts file

export const environment = {
  production: false,
  title: 'My App DEV'
};

1 Answer 1

1

As long as it is actually valid JavaScript (not TypeScript), as your example is, then yes. You'll just need to include/require it including the extensions:

require('./environment.ts');
// or
import environment from './environment.ts';

If it were to contain TypeScript code, you'd need to transpile it to regular JavaScript at some point. Where/when/how you do that would be up to your build pipeline.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.