0.2.5 • Published 9 years ago
wcf v0.2.5
wcf
Webpack configuration factory
Installation
npm install wcf --saveExample usage
const Webpack = require('webpack')
const wcf = require('wcf')
const target = process.argv[2] || 'web'
const nodeEnv = process.env.NODE_ENV || 'development'
const prod = nodeEnv === 'production'
const f = wcf()
.devtool('source-map')
.prod.web.devtool('hidden-source-map')
.web.pluginsWith(() => new Webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(nodeEnv)
}))
.node.pluginsWith(({secret}) => new Webpack.DefinePlugin(
Object.keys(process.env)
.map((key) => [key, process.env[key]])
.concat([['NODE_ENV', nodeEnv]])
.concat([['SECRET', secret]])
.map(([key, val]) => [key, JSON.stringify(val)])
.reduce((acc, [key, val]) => Object.assign(acc, {[`process.env.${key}`]: val}), {})
))
const webpackConfig = f.$build({secret: 'supersecret'}, {prod, target})
console.dir(webpackConfig, {depth: null})
// $ node example.js web
// { target: 'web',
// devtool: 'source-map',
// plugins: [ DefinePlugin { definitions: { 'process.env.NODE_ENV': '"development"' } } ] }
// $ NODE_ENV=production node example.js web
// { target: 'web',
// devtool: 'hidden-source-map',
// plugins: [ DefinePlugin { definitions: { 'process.env.NODE_ENV': '"production"' } } ] }
// $ node example.js node
// { target: 'node',
// devtool: 'source-map',
// plugins:
// [ DefinePlugin {
// definitions:
// { ...
// process.env.NODE_ENV: '"development"',
// process.env.SECRET: '"supersecret"' } } ] }License
MIT
0.2.5
9 years ago
0.2.4
10 years ago
0.2.3
10 years ago
0.2.2
10 years ago
0.2.1
10 years ago
0.2.0
10 years ago
0.1.11
10 years ago
0.1.10
10 years ago
0.1.9
10 years ago
0.1.8
10 years ago
0.1.7
10 years ago
0.1.6
10 years ago
0.1.5
10 years ago
0.1.4
10 years ago
0.1.3
10 years ago
0.1.2
10 years ago
0.1.1
10 years ago
0.1.0
10 years ago