homebrew-core/Formula/webpack.rb
2019-08-03 07:30:32 +08: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.39.1.tgz"
sha256 "d3458a829d6884cbc800ef8b9ad2ee0b9e2bb96727494eaee338fb7ef1ab5386"
head "https://github.com/webpack/webpack.git"
bottle do
sha256 "887fa16cc4cc3bfb244462ca1ece622ec6ee1986a1f4e946ea2a2a8ccf5917ba" => :mojave
sha256 "15d1718cf0dfd5c120cb36879d3b9f8d859ba14b91bec03ca0a1e20007f6d918" => :high_sierra
sha256 "47f66a5d1e6859090950ea106ba93b51a6d5a4ad52fe21765645a1ef4fe13144" => :sierra
end
depends_on "node"
resource "webpack-cli" do
url "https://registry.npmjs.org/webpack-cli/-/webpack-cli-3.3.5.tgz"
sha256 "60254336b5994487f58712714b1b1a475e74dc1d0b3b3e609086096f445b1818"
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