homebrew-core/Formula/webpack.rb
2018-08-06 04:13:19 -07:00

54 lines
1.8 KiB
Ruby

require "language/node"
require "json"
class Webpack < Formula
desc "Bundler for JavaScript and friends"
homepage "https://webpack.js.org/"
url "https://registry.npmjs.org/webpack/-/webpack-4.16.5.tgz"
sha256 "aeba9b94ac6a4f3906b9f531836d0bf12d2b3b3655747bbbf8aea00ad655e0e7"
head "https://github.com/webpack/webpack.git"
bottle do
sha256 "1187c724f94c76d39f6f2a775d9ebac1312a1a78d88e579d01afca1f6b88bd23" => :high_sierra
sha256 "922a4f63ab125e47635941793b7c71aebe0ac95f52dee35c7ce60a96e4241213" => :sierra
sha256 "970cea414f1d6836c8ca642e3ec94fe376fb13d2b9f12ca0d9d719dfa79090f9" => :el_capitan
end
depends_on "node"
resource "webpack-cli" do
url "https://registry.npmjs.org/webpack-cli/-/webpack-cli-3.1.0.tgz"
sha256 "813af78013aed28a967d2227c17b9c81c4809ed68b4f324a22e703167ea01e73"
end
def install
(buildpath/"node_modules/webpack").install Dir["*"]
buildpath.install resource("webpack-cli")
# declare webpack as a bundledDependency of webpack-cli
pkg_json = JSON.parse(IO.read("package.json"))
pkg_json["dependencies"]["webpack"] = version
pkg_json["bundledDependencies"] = ["webpack"]
IO.write("package.json", JSON.pretty_generate(pkg_json))
system "npm", "install", *Language::Node.std_npm_install_args(libexec)
bin.install_symlink libexec/"bin/webpack-cli"
bin.install_symlink libexec/"bin/webpack-cli" => "webpack"
end
test do
(testpath/"index.js").write <<~EOS
function component () {
var element = document.createElement('div');
element.innerHTML = 'Hello' + ' ' + 'webpack';
return element;
}
document.body.appendChild(component());
EOS
system bin/"webpack", "index.js", "--output=bundle.js"
assert_predicate testpath/"bundle.js", :exist?, "bundle.js was not generated"
end
end