Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【Angular 2】How ts-loader imports webpack resolved alias's variables? #25

Open
dongtong opened this issue Nov 2, 2016 · 0 comments

Comments

@dongtong
Copy link
Owner

dongtong commented Nov 2, 2016

I have met a special issue that typescript can not access webpack resolved alias variables, and I spent some time investigating. I have already solved it. The following is my procedures.

Step 1: Define webpack configuration file, my file name is webpack.config.dev.js

resolve: {
      extensions: ['', '.js', '.ts', '.json', '.less', '.scss', '.css', '.html', ".config.dev.js"],
      alias: {
        config: path.join(__dirname, 'src/config/dev.ts')
      }
}

Step 2: Define src/config/dev.ts. You could define global variables here.

// define special environment constants
export default {
    ENV: "development"
}

Step 3: Typescript class import it and use it

import config from 'config';

console.log(config.ENV)

You should define different environment webpack configuration file, such webpack.config.dev.js, webpack.config.prod.js etc, and then refer to src/config/dev.ts, src/config/prod.ts etc.

That's it. :)

@dongtong dongtong changed the title 【Angular 2】How ts-loader import webpack resolved alias variables? 【Angular 2】How ts-loader imports webpack resolved alias's variables? Nov 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant