diff --git a/bin/setup b/bin/setup new file mode 100644 index 0000000..6d86c7b --- /dev/null +++ b/bin/setup @@ -0,0 +1,4 @@ + #!/usr/bin/env ruby + require "hanami_webpack/cli" + +HanamiWebpack::CLI.start \ No newline at end of file diff --git a/hanami-webpack.gemspec b/hanami-webpack.gemspec index e25235b..227d851 100644 --- a/hanami-webpack.gemspec +++ b/hanami-webpack.gemspec @@ -9,4 +9,5 @@ Gem::Specification.new do |s| s.license = 'MIT' s.add_dependency 'hanami' + s.add_dependency "thor" end diff --git a/lib/hanami-webpack.rb b/lib/hanami-webpack.rb index 47845e4..2855bb0 100644 --- a/lib/hanami-webpack.rb +++ b/lib/hanami-webpack.rb @@ -3,6 +3,7 @@ require 'hanami/utils/blank' require 'hanami/config/security' require_relative 'hanami_webpack/view_helper' +require_relative 'hanami_webpack/cli' require_relative 'hanami_webpack/dev_server' require_relative 'hanami_webpack/security_headers_hijack' diff --git a/lib/hanami_webpack/cli.rb b/lib/hanami_webpack/cli.rb new file mode 100644 index 0000000..f5a2f5e --- /dev/null +++ b/lib/hanami_webpack/cli.rb @@ -0,0 +1,15 @@ +require "thor" + +module HanamiWebpack + class CLI < Thor + include Thor::Actions + + source_root File.expand_path("../templates", File.dirname(__FILE__)) + + desc "setup", "Setup webpack and package.json" + def webpack + copy_file 'webpack.config.sample.js', './webpack.config.js' + copy_file 'package.sample.json', './package.json' + end + end +end diff --git a/package.sample.json b/lib/templates/package.sample.json similarity index 100% rename from package.sample.json rename to lib/templates/package.sample.json diff --git a/webpack.config.sample.js b/lib/templates/webpack.config.sample.js similarity index 100% rename from webpack.config.sample.js rename to lib/templates/webpack.config.sample.js diff --git a/package.json b/package.json new file mode 100644 index 0000000..a82077a --- /dev/null +++ b/package.json @@ -0,0 +1,9 @@ +{ + "name": "myApp", + "version": "0.0.1", + "devDependencies": { + "stats-webpack-plugin": "*", + "webpack": "*", + "webpack-dev-server": "*" + } +} diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..858096c --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,33 @@ +var path = require("path"), + StatsPlugin = require("stats-webpack-plugin"); + +var devServerPort = process.env.WEBPACK_DEV_SERVER_PORT, + devServerHost = process.env.WEBPACK_DEV_SERVER_HOST, + publicPath = process.env.WEBPACK_PUBLIC_PATH; + +var config = { + entry: {}, + + output: { + path: path.join(__dirname, "public"), + filename: "[name]-[chunkhash].js" + }, + + resolve: { + root: path.join(__dirname, "apps") + }, + + plugins: [ + new StatsPlugin("webpack_manifest.json") + ] +}; + +if (process.env.INBUILT_WEBPACK_DEV_SERVER) { + config.devServer = { + port: devServerPort, + headers: { "Access-Control-Allow-Origin": "*" } + }; + config.output.publicPath = "//" + devServerHost + ":" + devServerPort + "/"; +} + +module.exports = config;