-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
45 lines (34 loc) · 1.55 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
CDBT = cd buildtools
DEVPACKAGES = @babel/[email protected] @babel/[email protected] @babel/[email protected] [email protected] [email protected] [email protected]
PACKAGES = @babel/polyfill
WPARGS = --config=webpack.config.js
WPCONFIG = "module.exports = { module: { rules: [ { test: /\.js$$/, loader: 'babel-loader', options: { presets: [ ['@babel/preset-env' , { targets: '> 0.25%, not dead' } ] ] } } ] } };"
SRC_DIRS = $(shell find src -type d)
SRC_FILES = $(shell find src -type f -name '*')
PROD_FILES = $(patsubst src/%,out/prod/%,$(SRC_FILES))
DEV_FILES = $(patsubst src/%,out/dev/%,$(SRC_FILES))
.PHONY: prod dev bundle prod-bundle dev-bundle clean clean-all
prod: $(PROD_FILES)
dev: $(DEV_FILES)
bundle: prod-bundle
prod-bundle: out/prod-bundle.js
dev-bundle: out/dev-bundle.js
clean:
rm -rf out
clean-all: clean
rm -rf buildtools
out/prod/% out/dev/%: src/%
@mkdir -p $(@D)
cp $< $@
out/prod/js/bundle.js out/prod-bundle.js: $(SRC_FILES) $(SRC_DIRS) buildtools/package.json
$(CDBT); npx webpack @babel/polyfill ../src/index.js -o ../$@ --mode=production $(WPARGS)
out/dev/js/bundle.js out/dev-bundle.js: $(SRC_FILES) $(SRC_DIRS) buildtools/package.json
$(CDBT); npx webpack @babel/polyfill ../src/index.js -o ../$@ --mode=development $(WPARGS)
buildtools/package.json: | buildtools/webpack.config.js
@mkdir -p $(@D)
@echo
@echo "************* Downloading Webpack and Babel *************"
$(CDBT); npm init -y > /dev/null; npm install --save-dev $(DEVPACKAGES); npm install --save $(PACKAGES)
buildtools/webpack.config.js:
@mkdir -p $(@D)
@echo $(WPCONFIG) > buildtools/webpack.config.js