Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some example scripts to load with webpack
The example JS files demonstrate * The use of CommonJS dependency management syntax[1]; 'require' and 'module.exports' statements * Using webpack to require dependencies that (for whatever reason) are in the global scope * Using ES6 features in your JS (relying on the ES6-loader to polyfill your code) * Using sprockets to load JS bundled by webpack as well as JS from gems (in this case just the default Rails jquery gem
- Loading branch information
Showing
4 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// files required here will run in the global scope | ||
require('./hello_world'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,4 @@ | |
//= require jquery | ||
//= require jquery_ujs | ||
//= require turbolinks | ||
//= require_tree . | ||
//= require main.bundle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
var $ = require('jquery'), | ||
HelloWorldView = require('./views/hello_world_view'); | ||
|
||
// Any logic to initialize the app goes here | ||
// For example, starting any routers or initializing the 'home' view | ||
$(function() { | ||
HelloWorldView.render(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
var $ = require('jquery'); | ||
|
||
var firstPar = $('<p>'), | ||
textStart = $('<span>').text("You're using "), | ||
webpackURL = 'http://webpack.github.io/', | ||
webpackLink = $('<a>').attr('href', webpackURL).text('webpack'), | ||
textEnd = $('<span>').text(' with Rails.'), | ||
es6text = 'ES6', | ||
// The ES6 loader will compile this template string into the ES5 equivalent. | ||
es6Par = $('<p>').text( | ||
`You can also use ${es6text} features with the ES6 loader.` | ||
); | ||
|
||
firstPar.append(textStart).append(webpackLink).append(textEnd); | ||
|
||
var HelloWorldView = { | ||
render: function() { | ||
$('.main').append(firstPar).append(es6Par); | ||
} | ||
}; | ||
|
||
module.exports = HelloWorldView; |