How to use @types/webpack-env is an example of using @types/webpack-env
. Make it and @types/node
coexist in the same working directory.
@types/webpack-env
provides a type definition for the webpack Module API and Node.js module.
@types/webpack-env
and @types/node
are mutually exclusive because they represent different environments.
You can clone this repository and test it.
npm run frontend
npm run backend
npm run inline
The sample file is in the following directory.
\backend\
\frontend\
Use two tsconfig.json files separately, and configure the type definitions to include.
webpack environment
{
"compilerOptions": {
"types": ["webpack-env"],
}
}
node environment
{
"compilerOptions": {
"types": ["node"],
}
}
The sample file is in the following directory.
\inline\
Edit tsconfig.json
to exclude type definitions. (webpack-env
and node
)
{
"compilerOptions": {
"types": [],
}
}
Use The Triple-Slash Directives to import type definitions.
webpack environment
/// <reference path="../node_modules/@types/node/index.d.ts" />
node environment
/// <reference path="../node_modules/@types/webpack-env/index.d.ts" />
DefinitelyTyped/DefinitelyTyped#11324
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) ZSkycat
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.