Code Monkey home page Code Monkey logo

hanami-webpack's Introduction

hanami-webpack

⚠️ This is a very experimental version, but it works, so, be aware!

This plugin will help you to use Webpack as your asset pipeline for Hanami with webpack-dev-server for development.

It'll work without any problem with your existent assets using the hanami/assets.

Setup

I'll assume that you already have the Node.js installed.

  1. Add the gem 'hanami-webpack', github: 'samuelsimoes/hanami-webpack' on your Gemfile.
  2. Run bundle install.
  3. Copy the base Webpack config webpack.config.sample.js and package.sample.json on your app root (removing the .sample in the name).
  4. Run npm install.
  5. Run bundle exec hanami serve and profite.

Usage

On development, this plugin will try to start the webpack-dev-server with your Hanami server. You can disable this behavior (see configuration section).

You will need use the webpack_asset_path helper on your templates to get the correct bundle path.

Let's say that you have a bundle with the name web.people. You should place on your template:

<script src="<%= webpack_asset_path('web.people') %>"></script>

To make a build just run ./node_modules/.bin/webpack on the project root.

Configuration

All plugin configuration is done by the following ENV vars:

Name Default Value Description
WEBPACK_DEV_SERVER_HOST localhost The host where your asset dev server is running.
WEBPACK_DEV_SERVER_PORT 3020 The port where your asset dev server is running.
WEBPACK_PUBLIC_PATH / Whenever you want use other publicPath you should update this var.
INBUILT_WEBPACK_DEV_SERVER true If you want start the webpack-dev-server when you start your hanami server (except on production).
WEBPACK_DEV_SERVER false on production true in any other env. If you want disable the webpack-dev-server integration set this as false.
WEBPACK_MANIFEST_FILE webpack_manifest.json The name of the manifest file that exposes the assets path to Hanami.

With Heroku

Just run the command below to configure your Heroku app. This command will set your Hanami app to serve the assets (you probably already done this) and will set the Ruby and Node.js buildpacks.

heroku config:set SERVE_STATIC_ASSETS=true && heroku buildpacks:set --index 1 heroku/nodejs && heroku buildpacks:set --index 2 heroku/ruby

To build your assets when you deploy, you will need place on your package.json the Heroku auto-commands:

{
  ...
  "scripts": {
    "build": "webpack",
    "heroku-postbuild": "npm run build"
  }
}

Todo

  • Write tests.
  • Release on RubyGems.
  • Research a better way to do these things without monkey patches (I have done, but looks like that with the current Hanami version it's impossible).

Samuel Simões ~ @samuelsimoes ~ Blog

hanami-webpack's People

Contributors

samuelsimoes 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

Watchers

 avatar  avatar  avatar  avatar  avatar

hanami-webpack's Issues

Add host option to webpack dev server binary

Hello!

How about to add --host option to webpack-dev-server invocation?

My use case is that I run hanami application in Docker, so I need to specify --host=0.0.0.0 to make webpack dev server available for my web browser

Looking for contributors

Hi people, there's a while that I don't do any kind of projects with Hanami and I am very busy in the last months because my other projects, but I see that some people still interested in updates and some tweaks, so if you want to help me to keep this project, please send an email to [email protected] that I will talk with you.

Of course, it will be a volunteer job.

Thank you for your attention.

Rake task to copy config files

Hi, @samuelsimoes!

Following the discussion on Gitter, I investigated a little bit whether it would be possible or not to have dynamically loaded rake task to create default configuration. Turns out it's probably not possible. I know we are all used to Rails' ecosystem and how it scans all the load path in search of possible rake tasks, but this comes with a performance cost and I think this is not a "Hanami-way", so it won't be introduces in any near future.

Alternatively, the README could ask the user to manually include in his Rakefile a line like this:

require 'hanami_webpack/tasks'

This would expose the tasks from a file in hanami-webpack gem to Hanami project, for example aforementioned task to copy default config.

How do you feel about solution like that? I know it is far from perfect but is the best thing I could come up with about this.

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.