homebrew-core/Formula/webpack.rb
2019-08-02 02:20:54 +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.0.tgz"
sha256 "3f56192e2042c5ad105cab60e9a05e0d4f5a7cb82f93debb870ce32857e1be34"
head "https://github.com/webpack/webpack.git"
bottle do
sha256 "4600f9e76372c2ccb99d9107d8deca56316665b1319ca98b7303c18574cf4f46" => :mojave
sha256 "320d399f80324f7f43b0c199e53453a77b5df4735413c4b02ed47dfbeb5feca0" => :high_sierra
sha256 "f22258f97fea2c00b3a8ba538bac730b406c34f363ff35611c6fdc3e4c925493" => :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