Code Monkey home page Code Monkey logo

felt's Introduction

Felt

Build Status

On-demand bundler for ES6 / CSS Next.

See also its options, plugins and recipes.

Note: Felt runs on Node 6.x or above.

CLI usages

In short, install Felt globally:

$ npm install -g felt felt-recipe-minimal

Note: felt-recipe-minimal is a recipe for Felt. You may install other recipes, too.

And run Felt:

$ cd path/to/project/
$ felt

Then, open your site in browser: http://localhost:3000.

Note: type Ctrl + C to stop the server

Run Felt

Assume that you have a project like this:

  • project/
    • public/
      • index.html
      • main.js
      • style.css
    • cache/
    • package.json

Then run Felt:

$ cd path/to/project/
$ felt --recipe minimal --src public

There're some official recipes. Check them, too.

Use config files

Assume that you have a project like this:

  • project/
    • public/
      • index.html
      • main.js
      • style.css
    • cache/
    • package.json
    • felt.config.js

Or choose your own config file:

$ felt --config felt.config.js

The default name of config is felt.config.js, so it's also fine:

$ felt --config

The config file could be like this:

'use strict'
const
  rollup = require('felt-rollup'),
  buble = require('rollup-plugin-buble'),
  resolve = require('rollup-plugin-node-resolve'),
  commonjs = require('rollup-plugin-commonjs')

module.exports = {
  src: 'public',
  handlers: {
    '.js': rollup({
      plugins: [
        resolve({ jsnext: true,  main: true, browser: true }),
        commonjs(),
        buble()
      ],
      sourceMap: true
    })
  }
}

See more detail about options

Change port

The default port is 3000. If you want to change it, use --port option:

$ felt --port 3333

Note: you can set the port option in your config file, too.

Watch changes

$ felt --src public --watch

Export static files

This is handy to upload the contents to amazon S3 or GitHub Pages. Felt exports not only compiled files but also other assets like HTML, PNG, ...etc, too.

$ felt --src public --export dist

Note: with export option, Felt is not run as a server. It works as just a bundler.

With Express

Install Felt and use it as an express middleware.

$ npm install --save felt

Add server.js to the project:

const
  express = require('express'),
  felt = require('felt'),
  recipe = require('felt-recipe-minimal')

const app = express()

app.use(felt(recipe, { src: 'public' }))
app.use(express.static('public'))
app.listen(3000)

Separated config files

It's a good idea to separate the config from server.js:

const
  express = require('express'),
  felt = require('felt')
  config = require('./felt.config.js')

app.use(felt(config))
app.use(express.static('public'))
app.listen(3000)

felt.config.js could be like this:

const
  rollup = require('felt-rollup'),
  buble = require('rollup-plugin-buble'),
  resolve = require('rollup-plugin-node-resolve'),
  commonjs = require('rollup-plugin-commonjs')

module.exports = {/* options */}

Options

property default descriptions
opts.src . the document directory to serve
opts.cache 'cache' if it's located inside src, ignored on requests
opts.root process.cwd() usually no need to set it
opts.handlers {} see the section below
opts.patterns [] see the section below
opts.excludes [] see the section below
opts.external {} see the section below
opts.update 'once' 'never' or 'always'
opts.refresh true set false to skip refreshing on starting
opts.watch false set true to detect changes
opts.debug false set true to show debug comments on the terminal

opts.handlers

Default handlers for each extension.

{
  handlers: {
    '*.js': rollup({
      plugins: [
        resolve({ jsnext: true }),
        commonjs(),
        buble()
      ],
      sourceMap: true
    })
  }
}

opts.patterns

This option limits the target which Felt works with. This is handy when you want to use Felt for only a few files like this:

{
  patterns: ['index.js', 'components/*.js']
}

Which handler will be used is depends on the extension. If no handler for the extension, Felt will throw exceptions.

You can also specify the custom handler for the pattern:

{
  patterns: [
    'index.js',
    {
      pattern: 'components/*.js',
      handler: rollup({
        plugins: [babel()],
        sourceMap: true
      })
    }
  ]
}

opts.excludes

This option excludes the files from compiling and copying (when exporting). Cache directory and 'node_modules/**' are always excluded. For example:

{
  excludes: ['no-compile/**']
}

opts.external

This option makes copies from deeper files typically in node_modules. For example, if you need to access node_modules/pouchdb/dist/pouchdb.min.js, you may write like this:

{
  external: {
    'pouchdb.js': 'node_modules/pouchdb/dist/pouchdb.min.js'
    // 'where/to/expose': 'path/from/opts.root'
  }
}

Then you can access it by http://localhost:3000/pouchdb.js. This option is convenient to directly expose a JavaScript or CSS file which comes from npm or bower.

Note: The files will not be processed by opts.handlers. This means that the file will skip compiling by rollup and so on.

Plugins

Plugins are the interface to compilers like Rollup or PostCSS. Actually, these are the thin wrapper of these libraries:

Recipes

Recipes are pre-made configurations. You can use these recipes with some overwrite with ease.

Note: the repository name of the recipe supposed to have prefix felt-recipe-.

License

MIT © Tsutomu Kawamura

felt's People

Contributors

azu avatar cognitom avatar geckotang avatar ninbryan avatar torounit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

felt's Issues

Multiple bundles (and cache) for user-agents

In the near future (or already now), we need to handle these browsers:

  • Native ES6, native module
  • Native ES7 supported, but no native module
  • Native ES6 supported, but no native module
  • No native ES6, no native module

Already we have no need to ES6 transpile on Chrome and Safari 10, but we still do that. That could be big overhead for such the latest browsers. I think we should make different bundle for each environment.

cannot set a dest directory for watching server

i have the following configs

server.js

const
  express = require('express'),
  felt = require('felt')
  config = require('./felt.config.js')

const app = express()

app.use(felt(config))
app.use(express.static('public'))
app.listen(3000)

felt.config.json

'use strict'

/**
 * Minimal recipe for Felt
 */

const
  rollup = require('felt-rollup'),
  buble = require('rollup-plugin-buble'),
  resolve = require('rollup-plugin-node-resolve'),
  commonjs = require('rollup-plugin-commonjs'),
  postcss = require('felt-postcss'),
  postcssImport = require('postcss-import'),
  cssnext = require('postcss-cssnext'),
  cssnano = require('cssnano')

module.exports = {
  src: 'src',
  export: 'public', // works only from cli (as the docs specify)
  watch: true,
  debug: true,
  patterns: ['entry.js', 'app.css'],
  excludes: ['components/*.js'],    
  // default handlers for each extension
  handlers: {
    '.js': rollup({
      plugins: [
        resolve({ jsnext: true,  main: true, browser: true }),
        commonjs(),
        buble()
      ],
      sourceMap: true
    }),
    '.css': postcss({
      plugins: [
        postcssImport(),
        cssnext({warnForDuplicates: false}),
        cssnano(),        
      ],
      options: {
        map: { inline: false }
      }
    })
  }
}

running node server.js ignores the export param
so, in order to have <script src="build/entry.js">

i had to set

cache: './public/build'

all good so far, but watch: true is not listening for changes.
any ideea ?

Serves a deeper file inside node_modules directly: opts.external

I'm working on a new option: opts.refs opts.external.
For example, if you want to expose node_modules/pouchdb/dist/pouchdb.min.js, this option make it possible with setting like below:

{
  external: {
    'pouchdb.js': 'node_modules/pouchdb/dist/pouchdb.min.js'
    // 'where/to/expose': 'path/from/opts.root'
  }
}

Then you can access it by http://localhost:3000/pouchdb.js.

I've almost done about the code, but I'm not sure what name is the best... Any feedback is welcome!

  • opts.refs
  • opts.aliases
  • opts.files
  • opts.copy
  • etc.

Remembers dependencies

To detect the changes well, it needs to care about dependencies.

  • rollup can return the dependencies while compiling
  • postcss-import may not support it

Hmm...

Single entry

Is there a way to limit to a single entry point?

example: /client/entry.js (rollup bundles from entry)
ignores everything else in /client

felt-imagemin

would creating felt-imagemin to handle 'images/*.{jpg,png}'be of interest?

Build errors fail silently

Build errors (apparently from missing modules, but I assume that there are lots of other causes) seem to result in a bad build that fails silently. The "bad build" in my case always results in the source files being copied as-is to the destination directory, which is worse (IMO) than not copying anything. 😢

Can’t run Felt with SyntaxError on Node v4

自分の環境だけかもしれませんが、うまく動かなかったので・・。
凡ミスだったらすみません。。

I’ve tried to use Felt with just described commands as below.

$ npm install -g felt felt-recipe-minimal
$ cd path/to/project/
$ felt

But I couldn’t run Felt with these error messages.

/Users/youthkee/.nodebrew/node/v4.2.6/lib/node_modules/felt/lib/config-builder.js:20
module.exports = function(...configs) {
                          ^^^

SyntaxError: Unexpected token ...
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:374:25)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/Users/youthkee/.nodebrew/node/v4.2.6/lib/node_modules/felt/bin/index.js:12:19)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)

Is there any requirements or settings to use Felt?
My environments are here.

Mac OS X 10.10.5
node v4.2.6 (installed with nodebrew)

MIME type conversion

At this point Felt is made for homologous conversions:

  • css to css
  • js to js

But it could be handy if it support such conversions, too:

  • scss to css
  • coffee to js

But, to do that, we need to handle MIME type as well.

configオプションでファイル名を省略できません。

こんにちは。
READMEには、コンフィグファイル名を省略した場合、デフォルトのファイル名file.config.jsが指定されたものと見なすよう説明がありますが、下記を実行すると、

felt --config --src src --debug --watch

以下のエラーが表示されます。

Error: felt-recipe-minimal is not installed

下記のように、ファイル名を指定してあげるときちんと動作してくれるようです。

felt --config felt.config.js --src src --debug --watch

私が使用しているバージョンは0.3.2です。

--watch doesn't work with --export

I'm running felt with a custom recipe like so:

felt --watch --recipe 18F --src src --export dist

But it always just builds once and exits, rather than watching the src directory.

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.