说明
typescript webpack-config-utils getifutils示例是从最受好评的开源项目中提取的实现代码,你可以参考下面示例的使用方式。
编程语言: TypeScript
命名空间/包名称: webpack-config-utils
示例#1
文件:
webpack.config.ts
项目:
mattlewis92/generator-angular2-module
export default (environment = 'development') => {
const { ifProduction, ifDevelopment } = getIfUtils(environment);
return {
devtool: ifProduction('source-map', 'eval'),
entry: path.join(__dirname, 'demo', 'entry.ts'),
output: {
filename: ifProduction('[name]-[chunkhash].js', '[name].js')
},
module: {
rules: removeEmpty([ifDevelopment({
test: /\.ts$/,
loader: 'tslint-loader',
exclude: /node_modules/,
enforce: 'pre'
}), ifDevelopment({
test: /\.ts$/,
loader: 'ts-loader',
exclude: /node_modules/,
options: {
transpileOnly: true
}
}, {
test: /\.ts$/,
loader: '@ngtools/webpack'
})])
},
resolve: {
extensions: ['.ts', '.js']
},
devServer: {
port: 8000,
inline: true,
hot: true,
historyApiFallback: true,
overlay: true
},
plugins: removeEmpty([
ifProduction(new webpack.optimize.ModuleConcatenationPlugin()),
ifProduction(new AngularCompilerPlugin({
tsConfigPath: './tsconfig-demo.json',
sourceMap: true
})),
ifDevelopment(new webpack.HotModuleReplacementPlugin()),
ifDevelopment(new ForkTsCheckerWebpackPlugin({
watch: ['./src', './demo'],
formatter: 'codeframe'
})),
new webpack.DefinePlugin({
ENV: JSON.stringify(environment)
}),
ifProduction(new webpack.optimize.UglifyJsPlugin({
sourceMap: true
})),
new webpack.ContextReplacementPlugin(
/angular(\\|\/)core(\\|\/)esm5/,
path.join(__dirname, 'src')
),
new HtmlWebpackPlugin({
template: path.join(__dirname, 'demo', 'index.ejs')
}),
ifProduction(new OfflinePlugin())
])
};
};
示例#2
文件:
webpack-config-utils-tests.ts
项目:
Jeremy-F/DefinitelyTyped
propIf('false', 'value', 'alternate');
// $ExpectType "alternate"
propIfNot(true, 'value', 'alternate');
// $ExpectType "value"
propIfNot(false, 'value', 'alternate');
// $ExpectType "value"
propIfNot('false', 'value', 'alternate');
}
{
// getIfUtils
{
// $ExpectType IfUtils
const utils = getIfUtils({});
}
{
const utils = getIfUtils({}, ['foo', 'bar']); // 'ifFoo', 'ifNotFoo', 'ifBar', 'ifNotBar'
const {
ifFoo, // $ExpectType IfUtilsFn
ifBar, // $ExpectType IfUtilsFn
ifNotFoo, // $ExpectType IfUtilsFn
ifNotBar // $ExpectType IfUtilsFn
} = utils;
}
{
const {
ifProduction // $ExpectType IfUtilsFn
} = getIfUtils('production');