Last active
August 29, 2015 14:27
-
-
Save nekath/160575342ef7fe924208 to your computer and use it in GitHub Desktop.
ES6 with browserify-rails and rails
This file contains hidden or 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
diff --git a/.gitignore b/.gitignore | |
index 050c9d9..3292569 100644 | |
--- a/.gitignore | |
+++ b/.gitignore | |
@@ -15,3 +15,6 @@ | |
/log/* | |
!/log/.keep | |
/tmp | |
+ | |
+# Ignore node modules | |
+node_modules | |
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js | |
index a63162d..318f587 100644 | |
--- a/app/assets/javascripts/application.js | |
+++ b/app/assets/javascripts/application.js | |
@@ -10,3 +10,4 @@ | |
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details | |
// about supported directives. | |
// | |
+//= require foo | |
diff --git a/app/assets/javascripts/bar.js b/app/assets/javascripts/bar.js | |
new file mode 100644 | |
index 0000000..69bb71b | |
--- /dev/null | |
+++ b/app/assets/javascripts/bar.js | |
@@ -0,0 +1,3 @@ | |
+import { showWarning } from 'baz'; | |
+ | |
+module.exports = showWarning; | |
diff --git a/app/assets/javascripts/baz.js b/app/assets/javascripts/baz.js | |
new file mode 100644 | |
index 0000000..6da3eff | |
--- /dev/null | |
+++ b/app/assets/javascripts/baz.js | |
@@ -0,0 +1,5 @@ | |
+const showWarning = function() { | |
+ window.alert("Some warning!!!"); | |
+} | |
+ | |
+export { showWarning }; | |
diff --git a/app/assets/javascripts/foo.js b/app/assets/javascripts/foo.js | |
new file mode 100644 | |
index 0000000..51c489d | |
--- /dev/null | |
+++ b/app/assets/javascripts/foo.js | |
@@ -0,0 +1 @@ | |
+window.showWarning = require('./bar'); | |
diff --git a/config/application.rb b/config/application.rb | |
index e2bce81..542d81f 100644 | |
--- a/config/application.rb | |
+++ b/config/application.rb | |
@@ -22,5 +22,8 @@ module TestEs6 | |
# Do not swallow errors in after_commit/after_rollback callbacks. | |
config.active_record.raise_in_transactional_callbacks = true | |
+ | |
+ config.browserify_rails.force = true | |
+ config.browserify_rails.commandline_options = "--transform babelify --extension=.js" | |
end | |
end | |
diff --git a/package.json b/package.json | |
new file mode 100644 | |
index 0000000..9130fac | |
--- /dev/null | |
+++ b/package.json | |
@@ -0,0 +1,14 @@ | |
+{ | |
+ "name": "something", | |
+ "dependencies": { | |
+ "browserify": "~> 10.2.4", | |
+ "browserify-incremental": "^3.0.1" | |
+ }, | |
+ "license": "MIT", | |
+ "engines": { | |
+ "node": ">= 0.10" | |
+ }, | |
+ "devDependencies": { | |
+ "babelify": "^6.1.3" | |
+ } | |
+} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment