0.2.5 • Published 7 years ago

wcf v0.2.5

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

wcf

Webpack configuration factory

js-standard-style

Installation

npm install wcf --save

Example 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

7 years ago

0.2.4

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.11

7 years ago

0.1.10

7 years ago

0.1.9

7 years ago

0.1.8

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago