homebrew-core/Formula/webpack.rb
2019-06-13 08:42:29 +02: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.34.0.tgz"
sha256 "0896c4cd7f46f8adf86eea880579e95d4f59ea7e9f630d8903675b3a8efd21e7"
head "https://github.com/webpack/webpack.git"
bottle do
sha256 "d2321bcaabb2e0ee9e675ec98841911d61d04f7cd50850ac31ca6bc080a247fc" => :mojave
sha256 "0866cf9af65362c782ccbf48988b9c9ebd1bccd90913baa405a4b64913f41874" => :high_sierra
sha256 "9a08698e7a54a55a08effdcfd106d966c2b84c4c7fe778965276666ff8629c99" => :sierra
end
depends_on "node"
resource "webpack-cli" do
url "https://registry.npmjs.org/webpack-cli/-/webpack-cli-3.3.2.tgz"
sha256 "dcb31e31e1ffe79e97d51782a38459785f2ded99bc15467ffe35f9ac33146df4"
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