Webpack now bundling all our app code

- We use import/export to indicate dependencies
- Webpack makes sure everything loads in the correct order
- We can remove all our additional script tags in index.html
This commit is contained in:
Colt Steele 2019-03-05 11:18:36 -08:00
parent 2400d188ea
commit 2b11dd3624
8 changed files with 15 additions and 14 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
.DS_Store
node_modules
dist

View File

@ -39,10 +39,5 @@
</div>
<img src="./assets/webpack.svg" />
</body>
<script src="./src/app/alert.service.js"></script>
<script src="./src/app/component.service.js"></script>
<script src="./src/app/utils/inputs-are-valid.js"></script>
<script src="./src/app/utils/parse-inputs.js"></script>
<script src="./src/app/app.js"></script>
<script src="./dist/main.js"></script>
</html>

View File

@ -1,4 +1,5 @@
class AlertService {
import { inputsAreValid } from "./utils/inputs-are-valid";
export class AlertService {
constructor() {
this.errorBox = document.getElementById("error");
}

View File

@ -1,6 +1,6 @@
const alertService = new AlertService();
const componentService = new ComponentService();
const run = (alertService, componentService) => {
import { inputsAreValid } from "./utils/inputs-are-valid";
import { parseInputs } from "./utils/parse-inputs";
export const run = (alertService, componentService) => {
alertService.hideErrors();
componentService.onClick(() => {
@ -16,4 +16,3 @@ const run = (alertService, componentService) => {
}
});
};
run(alertService, componentService);

View File

@ -1,4 +1,4 @@
class ComponentService {
export class ComponentService {
constructor() {
this.numberOneInput = document.getElementById("numberOne");
this.numberTwoInput = document.getElementById("numberTwo");

View File

@ -1,3 +1,3 @@
const inputsAreValid = (...input) => {
export const inputsAreValid = (...input) => {
return input.every(num => typeof num === "number" && !isNaN(num));
};

View File

@ -1,3 +1,3 @@
const parseInputs = (...input) => {
export const parseInputs = (...input) => {
return input.map(str => parseInt(str));
};

View File

@ -1 +1,6 @@
alert("HELLO FROM WEBPACK!");
import { run } from "./app/app";
import { AlertService } from "./app/alert.service";
import { ComponentService } from "./app/component.service";
const alertService = new AlertService();
const componentService = new ComponentService();
run(alertService, componentService);