Skip to content

Commit

Permalink
Set up VueJS with Webpack
Browse files Browse the repository at this point in the history
In order to use ES6 with VueJS, Webpack has been installed as the build tool.
Alias added to Webpack config for Vue -- see [this issue](vuejs-templates/webpack#215).

Compiled ES5 file no longer tracked.

In future, update config so that compiled script does not include Vue and instead load it from CDN.
  • Loading branch information
tjukes committed Mar 29, 2017
1 parent 1b5ad5e commit 7cf033b
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,6 @@ typings/

# dotenv environment variables file
.env

# Compiled ES5 script
bigmoneyES5.js
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ From the root folder of this repo:
`http-server .`

## A note on ES6
This project uses ES6 and Babel to compile to ES5. Scripts with names ending in 'ES5' are autogenerated by Babel and will be overwritten.
This project uses ES6, Babel and Webpack to compile to ES5. Scripts with names ending in 'ES5' are autogenerated by Babel and will be overwritten; therefore they are no longer included in version control.

To modify or add scripts:
- Run `npm install` to install node modules.
- Create or edit your script `script.js`
- Run `babel script.js --out-file scriptES5.js`
- Run `webpack -w` to have Webpack compile in watch mode

Note that Babel may need to be installed globally for the compilation command to work properly.
Note that Webpack may need to be installed globally for the compilation command to work properly.
10 changes: 10 additions & 0 deletions bigmoney.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Vue from "vue";

var stagingURL = "http://bigmoney-staging.bhga6ezash.us-west-2.elasticbeanstalk.com/";
var localURL = "http://localhost:8000/";
var endpoint = "api/donations/";
Expand All @@ -12,3 +14,11 @@ $.getJSON(localURL+endpoint, queryData)
.fail((err) => {
console.log(err);
});


new Vue({
el: '#test',
data: {
message: "This is a test!",
}
});
14 changes: 0 additions & 14 deletions bigmoneyES5.js

This file was deleted.

3 changes: 1 addition & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ <h1>Ban Big Money in B.C. Politics</h1>
<div class="col-md-10 col-md-offset-1">
<div class="content-container">
<div class="secondary-content">
<p id="test">{{ message }}</p>
<pre id="results"></pre>
</div>
</div>
Expand All @@ -64,7 +65,6 @@ <h1>Ban Big Money in B.C. Politics</h1>
<a class="footer-icon" href="https://dogwoodbc.ca"></a>
<p class="copy">© 2017 Dogwood BC</p>
</div>
</div>
</div>
</footer>
</div>
Expand All @@ -75,5 +75,4 @@ <h1>Ban Big Money in B.C. Politics</h1>
<!-- <script type="text/javascript" src="https://dogwoodbc.ca/wp-content/themes/dogwood/js/main.min.js?ver=1.0"></script> -->
<script type="text/javascript" src="https://dogwoodbc.ca/wp-content/themes/dogwood/js/jasny-bootstrap.min.js?ver=1.0"></script>
<script type="text/javascript" src="bigmoneyES5.js"></script>

</html>
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
"homepage": "https://github.com/DogwoodBC/bigmoney-ui#readme",
"dependencies": {
"babel-cli": "^6.24.0",
"babel-preset-es2015": "^6.24.0"
"babel-preset-es2015": "^6.24.0",
"vue": "^2.2.6"
},
"devDependencies": {
"babel-core": "^6.24.0",
"babel-loader": "^6.4.1",
"babel-preset-es2015": "^6.24.0",
"webpack": "^2.3.2"
}
}
21 changes: 21 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
entry: './bigmoney',
output: {
filename: 'bigmoneyES5.js'
},
module: {
loaders: [{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['es2015']
}
}]
},
resolve: {
alias: {
vue: 'vue/dist/vue.js'
}
}
};

0 comments on commit 7cf033b

Please sign in to comment.