Use webpack

This change adds webpack as the main tool used while developing the
extension. The extension has been minimally refactored so it works with
webpack, with the intention of refactoring it even further in follow-up
CLs in order to improve the file/folder structure of the project and its
readibility.

Bug: translateselectedtext:5
Change-Id: I89d7422e38fdaf46661c96527c51aa4436ad8056
diff --git a/Makefile b/Makefile
index ea01c71..79fce51 100644
--- a/Makefile
+++ b/Makefile
@@ -1,12 +1,38 @@
-.PHONY: all chromium-stable chromium-beta
+.PHONY: node_deps clean_dist deps clean_deps serve_chromium release release_chromium_stable release_chromium_beta clean_releases clean
 
-all: chromium-stable chromium-beta
+.DEFAULT_GOAL := release
+WEBPACK := ./node_modules/webpack-cli/bin/cli.js
+RELEASE_SCRIPT := bash tools/release.bash
 
-chromium-stable:
-	bash release.bash -c stable -b chromium -f
+node_deps:
+	npm ci --no-save
 
-chromium-beta:
-	bash release.bash -c beta -b chromium -f
+clean_dist:
+	rm -rf dist
 
-clean:
+deps: node_deps
+	mkdir -p dist
+
+clean_deps:
+	rm -rf node_modules
+
+
+serve_chromium: deps
+	$(WEBPACK) --mode development --env browser_target=chromium --watch
+
+release: release_chromium_stable release_chromium_beta
+
+release_chromium_stable: deps
+	$(WEBPACK) --mode production --env browser_target=chromium
+	$(RELEASE_SCRIPT) -c stable -b chromium -f
+	rm -rf dist/chromium
+
+release_chromium_beta: deps
+	$(WEBPACK) --mode production --env browser_target=chromium
+	$(RELEASE_SCRIPT) -c beta -b chromium -f
+	rm -rf dist/chromium
+
+clean_releases:
 	rm -rf out
+
+clean: clean_deps clean_dist clean_releases