Javascript 如何在webpack.config.ts的Typescript中创建开关大小写?
typescript和webpack 2配置文件的语法有问题: javascript等价物是:Javascript 如何在webpack.config.ts的Typescript中创建开关大小写?,javascript,typescript,webpack-2,Javascript,Typescript,Webpack 2,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');
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';
}
我得到一个错误:“导出声明只能在模块中使用”。但我不清楚这意味着什么。如何在typescript中更正此问题?或者这不是在webpack 2中构建配置的方法吗?Typescript只支持顶级导入/导出 试一试
它是一个json文件,不是js
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;