homebrew-core/Formula/webpack.rb
2019-07-09 03:35:57 +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.35.3.tgz"
sha256 "1da882b55d5712c2e17c7039a34b3d6977310a149279b099f66c713ab79a7b94"
head "https://github.com/webpack/webpack.git"
bottle do
sha256 "a315fdee6ea7b52f0c9ddb7c888264422339b7ad57036f25f1fc30743f882391" => :mojave
sha256 "8128342740c54d3febe9caca910bb2423845f6b66b15168a43b54bf532072855" => :high_sierra
sha256 "2c95bca88e81976654b5a5e5d66aa0ef83be0166752b0a36c8f1a96caf4da791" => :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