typescript - Can't provide environment variable from Webpack config to Angular 2 -


in config webpack have following.

var config = require("./webfig"); config.module = config.module || []; config.plugins.push(new webpack.defineplugin({ "hazaa": "shazoo" })); module.exports = config; 

however, in ts file, when try access using line below, transpiler complains such thing isn't available. i'm not entirely how troubleshoot , googlearching produced not of value specific issue (as far i've recognized diagnostics properly).

how access hazaa in typescript code?

edit

based on comments, i've introduced following changes.

config.plugins.push(new webpack.defineplugin({ "hazaa": json.stringify("shazoo") })); 

a file called app.d.ts created in same directory pre-existing index.d.ts was. contains declare var hazaa: string; , i'm referring typings.json this.

{   "globaldependencies": {     "core-js": "registry:dt/core-js#0.9.7+20161130133742",     "app": "file:./typings/app.d.ts"   } } 

i referred tsconfig.json section files follows.

{   "compileroptions": {     "baseurl": "./source/application",     "target": "es5",     "experimentaldecorators": true,     "emitdecoratormetadata": true   },   "files": [     "typings/index.d.ts",     "typings/app.d.ts"   ],   "include": [ "source/**/*" ],   "exclude": [ "node_modules" ] } 

nothing helps - when go console.log(hazaa) in constructor of component, compile time error saying name can't found.

as typescript doesn't know webpack global variables (variables defined defineplugin) injected code when build project hence gives error. have tell typescript hazaa variable of type string evaluated @ build time.

so declare hazaa .d.ts file.

declare var hazaa: string; 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -