GithubHelp home page GithubHelp logo

Comments (9)

timwis avatar timwis commented on May 16, 2024 1

How's this feel? Usage would be like:

const browserify = require('browserify')
const bankai = require('bankai')
const http = require('http')
const path = require('path')

const client = path.join(__dirname, 'client.js')

const assets = bankai({
  js: {
    browserify: browserify,
    src: client
    // other opts here, at top level (rather than inside `opts` object)
  },
  html: true,
  css: true
})

http.createServer((req, res) => {
  switch req.url {
    case '/': return assets.html(req, res).pipe(res)
    case '/bundle.js': return assets.js(req, res).pipe(res)
    case '/bundle.css': return assets.css(req, res).pipe(res)
    default: return res.statusCode = 404 && res.end('404 not found')
  }
}).listen(8080)

html and css could be objects as well, if you want to configure them

from bankai.

timwis avatar timwis commented on May 16, 2024 1

Good idea. In fact, cssEntry and jsEntry are really just options of create-html, similar to browserify's opts. Playing around with it a bit, how about this?

If you're happy with the out-of-the-box config,

const assets = bankai({
  entry: 'index.js',
  optimize: true,
  js: true,
  html: true,
  css: true
})

If you want to customize,

const assets = bankai({
  entry: 'index.js',
  optimize: true,
  js: {
    debug: true
  },
  html: {
    title: 'Hello, world',
    script: 'bundle.js',
    css: 'styles.css'
  },
  css: {
    use: 'sheetify-cssnext'
  }
})

I was also considering using the underlying library names to make it clear to the user that they're just passing options to the underlying libraries, but I'm leaning more towards the above (html/js/css):

const assets = bankai({
  entry: 'index.js',
  optimize: true,
  browserify: {
    debug: true
  },
  createHtml: {
    title: 'Hello, world',
    script: 'bundle.js',
    css: 'styles.css'
  },
  sheetify: {
    use: 'sheetify-cssnext'
  }
})

Thoughts?

from bankai.

yoshuawuyts avatar yoshuawuyts commented on May 16, 2024

yeah sounds good to me!

from bankai.

yoshuawuyts avatar yoshuawuyts commented on May 16, 2024

Yeah I like the idea! - I find nested objects can be hard to remember though, so maybe we should go for a flat scope:

const assets = bankai({
  browserify: browserify,
  src: client,
  html: true,
  css: true,
  js: true,
  cssEntry: '/bundle.css',
  jsEntry: '/bundle.js'
})

I think this is only feasible because we're not aiming to add a mad amount of of options. What do you think?

from bankai.

timwis avatar timwis commented on May 16, 2024

What about supporting the ability to pass arguments to browserify? Ie. Debug, transform, etc.

from bankai.

yoshuawuyts avatar yoshuawuyts commented on May 16, 2024

Oh hey yeah, so if we're not passing in browserify anymore as per #62 then the browserify arg is open to be an object of options. That could work right?

from bankai.

yoshuawuyts avatar yoshuawuyts commented on May 16, 2024

@timwis I like your suggestion; think it makes for a intuitive API. All 👍 for that :D

from bankai.

yoshuawuyts avatar yoshuawuyts commented on May 16, 2024

Done in 4.0.0, close enough

from bankai.

timwis avatar timwis commented on May 16, 2024

Thanks! Sorry for dropping the ball on this one :/

from bankai.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.