如何在 Typescript 中为 webpack.config.ts 创建一个 switch case?
How to make a switch case in Typescript for the webpack.config.ts?
我在使用 typescript 和 webpack 2 配置文件时遇到语法问题:
javascript 等价于:
switch (process.env.BUILD_ENV) {
case 'live':
module.exports = require('./config/webpack.live');
break;
case 'debug':
module.exports = require('./config/webpack.debug');
break;
default:
module.exports = require('./config/webpack.doesntexist');
}
Webpack 2 需要一个 TS 配置文件,所以我尝试将这部分更改为:
switch (process.env.BUILD_ENV) {
case 'live':
export * from './config/webpack.live';
break;
case 'debug':
export * from './config/webpack.debug';
break;
default:
export * from './config/webpack.doesntexist';
}
我收到错误:"an export declaration can only be used in a module"。但我不清楚这意味着什么。我怎样才能在打字稿中更正这个?还是这不是在 webpack 2 中构建配置的方式?
Typescript 仅支持顶级import/export。
尝试
import * as liveConfig from "./config/webpack.live";
import * as debugConfig from "./config/webpack.debug";
import * as defaultConfig from "./config/webpack.doesntexist";
let config;
switch (process.env.BUILD_ENV) {
case 'live':
config = liveConfig;
break;
case 'debug':
config = debugConfig;
break;
default:
config = defaultConfig;
}
export = config;
我在使用 typescript 和 webpack 2 配置文件时遇到语法问题:
javascript 等价于:
switch (process.env.BUILD_ENV) {
case 'live':
module.exports = require('./config/webpack.live');
break;
case 'debug':
module.exports = require('./config/webpack.debug');
break;
default:
module.exports = require('./config/webpack.doesntexist');
}
Webpack 2 需要一个 TS 配置文件,所以我尝试将这部分更改为:
switch (process.env.BUILD_ENV) {
case 'live':
export * from './config/webpack.live';
break;
case 'debug':
export * from './config/webpack.debug';
break;
default:
export * from './config/webpack.doesntexist';
}
我收到错误:"an export declaration can only be used in a module"。但我不清楚这意味着什么。我怎样才能在打字稿中更正这个?还是这不是在 webpack 2 中构建配置的方式?
Typescript 仅支持顶级import/export。
尝试
import * as liveConfig from "./config/webpack.live";
import * as debugConfig from "./config/webpack.debug";
import * as defaultConfig from "./config/webpack.doesntexist";
let config;
switch (process.env.BUILD_ENV) {
case 'live':
config = liveConfig;
break;
case 'debug':
config = debugConfig;
break;
default:
config = defaultConfig;
}
export = config;