Skip to content

Commit

Permalink
Switch to babel-preset-env, upgrade ESLint and fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
renchap committed Apr 18, 2018
1 parent 3df9f5f commit 1110bad
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 121 deletions.
7 changes: 7 additions & 0 deletions javascript/webpacker_react-npm-module/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"presets": [["env", {
"targets": {
"browsers": ["> 1%", "last 2 versions"]
}
}]]
}
14 changes: 7 additions & 7 deletions javascript/webpacker_react-npm-module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
"name": "webpacker-react-build",
"private": true,
"scripts": {
"build": "babel src --presets=babel-preset-es2015 --out-dir dist",
"build": "babel src --out-dir dist",
"lint": "eslint src/"
},
"devDependencies": {
"babel-cli": "^6.18.0",
"babel-preset-es2015": "^6.22.0",
"eslint": "^4.6.1",
"eslint-config-airbnb": "^15.1.0",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-jsx-a11y": "^5.1.1",
"eslint-plugin-react": "^7.3.0"
"babel-preset-env": "^1.6.1",
"eslint": "^4.18.1",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-import": "^2.9.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.7.0"
},
"dependencies": {
"lodash": "^4.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import webpack from 'webpack'
import merge from 'webpack-merge'

function configureHotModuleReplacement(config) {
function configureHotModuleReplacement(origConfig) {
const config = origConfig
config.module.rules = config.module.rules.map((rule) => {
if (rule.loader === 'babel-loader') {
return merge(rule, { options: { plugins: ['react-hot-loader/babel'] } })
}
return rule
})

return config
}

module.exports = configureHotModuleReplacement
2 changes: 1 addition & 1 deletion javascript/webpacker_react-npm-module/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const WebpackerReact = {
},

mountComponents() {
const registeredComponents = this.registeredComponents
const { registeredComponents } = this
const toMount = document.querySelectorAll(`[${CLASS_ATTRIBUTE_NAME}]`)

for (let i = 0; i < toMount.length; i += 1) {
Expand Down
6 changes: 3 additions & 3 deletions javascript/webpacker_react-npm-module/src/ujs.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const ujs = {

setup(onMount, onUnmount) {
const $ = (typeof window.jQuery !== 'undefined') && window.jQuery
const Turbolinks = window.Turbolinks
const { Turbolinks } = window

// Detect which kind of events to set up:
if (typeof Turbolinks !== 'undefined' && Turbolinks.supported) {
Expand All @@ -46,7 +46,7 @@ const ujs = {
},

turbolinksClassic(onMount, onUnmount) {
const Turbolinks = window.Turbolinks
const { Turbolinks } = window

this.handleEvent(Turbolinks.EVENTS.CHANGE, onMount)
this.handleEvent(Turbolinks.EVENTS.BEFORE_UNLOAD, onUnmount)
Expand All @@ -57,7 +57,7 @@ const ujs = {
// have named events and didn't have a before-unload event.
// Also, it didn't work with the Turbolinks cache, see
// https://github.com/reactjs/react-rails/issues/87
const Turbolinks = window.Turbolinks
const { Turbolinks } = window
Turbolinks.pagesCached(0)
this.handleEvent('page:change', onMount)
this.handleEvent('page:receive', onUnmount)
Expand Down
Loading

0 comments on commit 1110bad

Please sign in to comment.