From 86164d1c0730847669bbbceddd55f7a14e95fa7c Mon Sep 17 00:00:00 2001 From: Gaurav Tiwari Date: Fri, 24 Feb 2017 14:18:16 +0000 Subject: [PATCH 01/15] Add eslint --- .eslintrc.js | 8 ++++++++ package.json | 27 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 .eslintrc.js create mode 100644 package.json diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 000000000..0552d707e --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,8 @@ +module.exports = { + "extends": "airbnb", + "plugins": [ + "react", + "jsx-a11y", + "import" + ], +}; diff --git a/package.json b/package.json new file mode 100644 index 000000000..f982959c4 --- /dev/null +++ b/package.json @@ -0,0 +1,27 @@ +{ + "name": "webpacker", + "version": "1.0.0", + "description": "Webpacker makes it easy to use the JavaScript preprocessor and bundler [Webpack](https://webpack.github.io) to manage application-like JavaScript in Rails. It coexists with the asset pipeline, as the purpose is only to use Webpack for app-like JavaScript, not images, css, or even JavaScript Sprinkles (that all continues to live in app/assets).", + "main": "index.js", + "dependencies": {}, + "devDependencies": { + "eslint": "^3.16.1", + "eslint-config-airbnb": "^14.1.0", + "eslint-plugin-import": "^2.2.0", + "eslint-plugin-jsx-a11y": "^4.0.0", + "eslint-plugin-react": "^6.10.0" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/rails/webpacker.git" + }, + "author": "David Heinemeier Hansson ", + "license": "MIT", + "bugs": { + "url": "https://github.com/rails/webpacker/issues" + }, + "homepage": "https://github.com/rails/webpacker#readme" +} From fa3a6a4dd0ee8f39cee8c821564c79a087ccef1b Mon Sep 17 00:00:00 2001 From: Gaurav Tiwari Date: Fri, 24 Feb 2017 14:18:26 +0000 Subject: [PATCH 02/15] Ignore node_modules --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 24fe85316..1074c0051 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /.bundle +node_modules From 77b6ea0909968424e69043c361f83e070527b86d Mon Sep 17 00:00:00 2001 From: Gaurav Tiwari Date: Fri, 24 Feb 2017 14:19:06 +0000 Subject: [PATCH 03/15] Lint javascript code to make it consistent --- lib/install/angular/hello_angular.js | 2 +- lib/install/config/development.js | 21 ++++--- lib/install/config/production.js | 17 +++--- lib/install/config/shared.js | 65 +++++++++++---------- lib/install/javascript/packs/application.js | 4 +- lib/install/react/hello_react.js | 16 ----- lib/install/react/hello_react.jsx | 30 ++++++++++ 7 files changed, 91 insertions(+), 64 deletions(-) delete mode 100644 lib/install/react/hello_react.js create mode 100644 lib/install/react/hello_react.jsx diff --git a/lib/install/angular/hello_angular.js b/lib/install/angular/hello_angular.js index f94d93948..10088d5dd 100644 --- a/lib/install/angular/hello_angular.js +++ b/lib/install/angular/hello_angular.js @@ -4,4 +4,4 @@ // // <%= javascript_pack_tag 'hello_angular' %> -require("hello_angular") +require('./hello_angular'); diff --git a/lib/install/config/development.js b/lib/install/config/development.js index 22eb3ca06..df0583f7a 100644 --- a/lib/install/config/development.js +++ b/lib/install/config/development.js @@ -1,24 +1,27 @@ +/* eslint import/no-unresolved:0 */ +/* eslint import/no-extraneous-dependencies:0 */ +/* eslint import/extensions:0 */ // Note: You must restart bin/webpack-watcher for changes to take effect -const webpack = require('webpack') -const merge = require('webpack-merge') +const webpack = require('webpack'); +const merge = require('webpack-merge'); -const sharedConfig = require('./shared.js') +const sharedConfig = require('./shared.js'); module.exports = merge(sharedConfig.config, { devtool: 'sourcemap', stats: { - errorDetails: true + errorDetails: true, }, output: { - pathinfo: true + pathinfo: true, }, plugins: [ new webpack.LoaderOptionsPlugin({ - debug: true - }) - ] -}) + debug: true, + }), + ], +}); diff --git a/lib/install/config/production.js b/lib/install/config/production.js index 543f14306..7d73e5b2c 100644 --- a/lib/install/config/production.js +++ b/lib/install/config/production.js @@ -1,16 +1,19 @@ +/* eslint import/no-unresolved:0 */ +/* eslint import/no-extraneous-dependencies:0 */ +/* eslint import/extensions:0 */ // Note: You must restart bin/webpack-watcher for changes to take effect -const webpack = require('webpack') -const merge = require('webpack-merge') +const webpack = require('webpack'); +const merge = require('webpack-merge'); -const sharedConfig = require('./shared.js') +const sharedConfig = require('./shared.js'); module.exports = merge(sharedConfig.config, { output: { filename: '[name]-[hash].js' }, plugins: [ new webpack.LoaderOptionsPlugin({ - minimize: true - }) - ] -}) + minimize: true, + }), + ], +}); diff --git a/lib/install/config/shared.js b/lib/install/config/shared.js index ab1ec762d..17da7041c 100644 --- a/lib/install/config/shared.js +++ b/lib/install/config/shared.js @@ -1,39 +1,44 @@ +/* eslint import/no-unresolved:0 */ +/* eslint import/no-extraneous-dependencies:0 */ +/* eslint import/extensions:0 */ // Note: You must restart bin/webpack-watcher for changes to take effect -const webpack = require('webpack') -const path = require('path') -const process = require('process') -const glob = require('glob') -const extname = require('path-complete-extname') -let distDir = process.env.WEBPACK_DIST_DIR +const webpack = require('webpack'); +const path = require('path'); +const process = require('process'); +const glob = require('glob'); +const extname = require('path-complete-extname'); + +let distDir = process.env.WEBPACK_DIST_DIR; if (distDir === undefined) { - distDir = 'packs' + distDir = 'packs'; } -config = { +const config = { entry: glob.sync(path.join('app', 'javascript', 'packs', '*.js*')).reduce( - function(map, entry) { - const basename = path.basename(entry, extname(entry)) - map[basename] = path.resolve(entry) - return map - }, {} + (map, entry) => { + const basename = path.basename(entry, extname(entry)); + const localMap = map; + localMap[basename] = path.resolve(entry); + return localMap; + }, {}, ), output: { filename: '[name].js', path: path.resolve('public', distDir) }, module: { rules: [ - { test: /\.coffee(.erb)?$/, loader: "coffee-loader" }, + { test: /\.coffee(.erb)?$/, loader: 'coffee-loader' }, { test: /\.js(.erb)?$/, exclude: /node_modules/, loader: 'babel-loader', options: { presets: [ - [ 'latest', { 'es2015': { 'modules': false } } ] - ] - } + ['latest', { es2015: { modules: false } }], + ], + }, }, { test: /.erb$/, @@ -41,30 +46,30 @@ config = { exclude: /node_modules/, loader: 'rails-erb-loader', options: { - runner: 'DISABLE_SPRING=1 bin/rails runner' - } + runner: 'DISABLE_SPRING=1 bin/rails runner', + }, }, - ] + ], }, plugins: [ - new webpack.EnvironmentPlugin(Object.keys(process.env)) + new webpack.EnvironmentPlugin(Object.keys(process.env)), ], resolve: { - extensions: [ '.js', '.coffee' ], + extensions: ['.js', '.coffee'], modules: [ path.resolve('app/javascript'), - path.resolve('node_modules') - ] + path.resolve('node_modules'), + ], }, resolveLoader: { - modules: [ path.resolve('node_modules') ] - } -} + modules: [path.resolve('node_modules')], + }, +}; module.exports = { - distDir: distDir, - config: config -} + distDir, + config, +}; diff --git a/lib/install/javascript/packs/application.js b/lib/install/javascript/packs/application.js index 5ed8fab83..5160da0d0 100644 --- a/lib/install/javascript/packs/application.js +++ b/lib/install/javascript/packs/application.js @@ -1,3 +1,5 @@ +/* eslint no-console:0 */ + // This file is automatically compiled by Webpack, along with any other files // present in this directory. You're encouraged to place your actual application logic in // a relevant structure within app/javascript and only use these pack files to reference @@ -6,4 +8,4 @@ // To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate // layout file, like app/views/layouts/application.html.erb -console.log('Hello World from Webpacker') +console.log('Hello World from Webpacker'); diff --git a/lib/install/react/hello_react.js b/lib/install/react/hello_react.js deleted file mode 100644 index e191aea9e..000000000 --- a/lib/install/react/hello_react.js +++ /dev/null @@ -1,16 +0,0 @@ -// Run this example by adding <%= javascript_pack_tag 'hello_react' %> to the head of your layout file, -// like app/views/layouts/application.html.erb. All it does is render
Hello React
at the bottom -// of the page. - -import React from 'react' -import ReactDOM from 'react-dom' - -class Hello extends React.Component { - render() { - return
Hello {this.props.name}!
- } -} - -document.addEventListener("DOMContentLoaded", e => { - ReactDOM.render(, document.body.appendChild(document.createElement('div'))) -}) diff --git a/lib/install/react/hello_react.jsx b/lib/install/react/hello_react.jsx new file mode 100644 index 000000000..6278b48a8 --- /dev/null +++ b/lib/install/react/hello_react.jsx @@ -0,0 +1,30 @@ +/* global document */ +/* eslint import/no-unresolved:0 */ +/* eslint import/no-extraneous-dependencies:0 */ +/* eslint import/extensions:0 */ + +// Run this example by adding <%= javascript_pack_tag 'hello_react' %> to the head of your layout file, +// like app/views/layouts/application.html.erb. All it does is render
Hello React
at the bottom +// of the page. + +import React from 'react'; +import ReactDOM from 'react-dom'; + +const Hello = props => ( +
Hello {props.name}!
+); + +Hello.defaultProps = { + name: 'David', +}; + +Hello.propTypes = { + name: React.PropTypes.string, +}; + +document.addEventListener('DOMContentLoaded', () => { + ReactDOM.render( + , + document.body.appendChild(document.createElement('div')), + ); +}); From 111876b5dde4e2ea132777a35c48733feff20dd5 Mon Sep 17 00:00:00 2001 From: Gaurav Tiwari Date: Fri, 24 Feb 2017 14:24:48 +0000 Subject: [PATCH 04/15] Rename file extension in installer --- lib/tasks/webpacker.rake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/tasks/webpacker.rake b/lib/tasks/webpacker.rake index 853223923..1d1330bf9 100644 --- a/lib/tasks/webpacker.rake +++ b/lib/tasks/webpacker.rake @@ -55,9 +55,9 @@ namespace :webpacker do FileUtils.copy File.expand_path('../install/react/.babelrc', __dir__), Rails.root - puts "Copying react example to app/javascript/packs/hello_react.js" - FileUtils.copy File.expand_path('../install/react/hello_react.js', __dir__), - Rails.root.join('app/javascript/packs/hello_react.js') + puts "Copying react example to app/javascript/packs/hello_react.jsx" + FileUtils.copy File.expand_path('../install/react/hello_react.jsx', __dir__), + Rails.root.join('app/javascript/packs/hello_react.jsx') exec './bin/yarn add --dev babel-preset-react && ./bin/yarn add react react-dom' end From a372ba1a291214b36745dac2cac9c7eb24f8cc9e Mon Sep 17 00:00:00 2001 From: Gaurav Tiwari Date: Fri, 24 Feb 2017 14:36:18 +0000 Subject: [PATCH 05/15] Move eslint rules to config file --- .eslintrc.js | 13 +++++++++++++ lib/install/config/development.js | 3 --- lib/install/config/production.js | 3 --- lib/install/config/shared.js | 9 +++------ lib/install/javascript/packs/application.js | 2 -- lib/install/react/hello_react.jsx | 5 ----- lib/tasks/webpacker.rake | 4 ++-- 7 files changed, 18 insertions(+), 21 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 0552d707e..ca0a80858 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -5,4 +5,17 @@ module.exports = { "jsx-a11y", "import" ], + "rules": { + "import/no-unresolved": "off", + "import/no-extraneous-dependencies": "off", + "import/extensions": "off", + "func-names": "off", + "prefer-arrow-callback": "off", + "object-shorthand": "off", + "no-console": "off", + }, + "globals": { + "document": true, + "window": true, + }, }; diff --git a/lib/install/config/development.js b/lib/install/config/development.js index df0583f7a..4a60142b2 100644 --- a/lib/install/config/development.js +++ b/lib/install/config/development.js @@ -1,6 +1,3 @@ -/* eslint import/no-unresolved:0 */ -/* eslint import/no-extraneous-dependencies:0 */ -/* eslint import/extensions:0 */ // Note: You must restart bin/webpack-watcher for changes to take effect const webpack = require('webpack'); diff --git a/lib/install/config/production.js b/lib/install/config/production.js index 7d73e5b2c..3b92e9dff 100644 --- a/lib/install/config/production.js +++ b/lib/install/config/production.js @@ -1,6 +1,3 @@ -/* eslint import/no-unresolved:0 */ -/* eslint import/no-extraneous-dependencies:0 */ -/* eslint import/extensions:0 */ // Note: You must restart bin/webpack-watcher for changes to take effect const webpack = require('webpack'); diff --git a/lib/install/config/shared.js b/lib/install/config/shared.js index 17da7041c..669fea4d4 100644 --- a/lib/install/config/shared.js +++ b/lib/install/config/shared.js @@ -1,6 +1,3 @@ -/* eslint import/no-unresolved:0 */ -/* eslint import/no-extraneous-dependencies:0 */ -/* eslint import/extensions:0 */ // Note: You must restart bin/webpack-watcher for changes to take effect const webpack = require('webpack'); @@ -17,7 +14,7 @@ if (distDir === undefined) { const config = { entry: glob.sync(path.join('app', 'javascript', 'packs', '*.js*')).reduce( - (map, entry) => { + function (map, entry) { const basename = path.basename(entry, extname(entry)); const localMap = map; localMap[basename] = path.resolve(entry); @@ -70,6 +67,6 @@ const config = { }; module.exports = { - distDir, - config, + distDir: distDir, + config: config, }; diff --git a/lib/install/javascript/packs/application.js b/lib/install/javascript/packs/application.js index 5160da0d0..d9366bc08 100644 --- a/lib/install/javascript/packs/application.js +++ b/lib/install/javascript/packs/application.js @@ -1,5 +1,3 @@ -/* eslint no-console:0 */ - // This file is automatically compiled by Webpack, along with any other files // present in this directory. You're encouraged to place your actual application logic in // a relevant structure within app/javascript and only use these pack files to reference diff --git a/lib/install/react/hello_react.jsx b/lib/install/react/hello_react.jsx index 6278b48a8..579159650 100644 --- a/lib/install/react/hello_react.jsx +++ b/lib/install/react/hello_react.jsx @@ -1,8 +1,3 @@ -/* global document */ -/* eslint import/no-unresolved:0 */ -/* eslint import/no-extraneous-dependencies:0 */ -/* eslint import/extensions:0 */ - // Run this example by adding <%= javascript_pack_tag 'hello_react' %> to the head of your layout file, // like app/views/layouts/application.html.erb. All it does is render
Hello React
at the bottom // of the page. diff --git a/lib/tasks/webpacker.rake b/lib/tasks/webpacker.rake index 1d1330bf9..1b3b76369 100644 --- a/lib/tasks/webpacker.rake +++ b/lib/tasks/webpacker.rake @@ -42,9 +42,9 @@ namespace :webpacker do puts "Couldn't automatically update loader presets in #{config_path}. Please set presets: [ 'react', [ 'latest', { 'es2015': { 'modules': false } } ] ]." end - if config.include?("test: /\\.js(.erb)?$/") + if config.include?("test: /\.jsx?(.erb)?$/") puts "Replacing loader test to include react in #{config_path}" - config.gsub!("test: /\\.js(.erb)?$/", "test: /\\.jsx?(.erb)?$/") + config.gsub!("test: /\.jsx?(.erb)?$/", "test: /\\.jsx?(.erb)?$/") else puts "Couldn't automatically update loader test in #{config_path}. Please set test: /\.jsx?(.erb)?$/." end From d2c07fb27779a58509de4105b8949b77b3f1b95d Mon Sep 17 00:00:00 2001 From: Gaurav Tiwari Date: Fri, 24 Feb 2017 14:36:54 +0000 Subject: [PATCH 06/15] Revert changing extension --- lib/tasks/webpacker.rake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tasks/webpacker.rake b/lib/tasks/webpacker.rake index 1b3b76369..1d1330bf9 100644 --- a/lib/tasks/webpacker.rake +++ b/lib/tasks/webpacker.rake @@ -42,9 +42,9 @@ namespace :webpacker do puts "Couldn't automatically update loader presets in #{config_path}. Please set presets: [ 'react', [ 'latest', { 'es2015': { 'modules': false } } ] ]." end - if config.include?("test: /\.jsx?(.erb)?$/") + if config.include?("test: /\\.js(.erb)?$/") puts "Replacing loader test to include react in #{config_path}" - config.gsub!("test: /\.jsx?(.erb)?$/", "test: /\\.jsx?(.erb)?$/") + config.gsub!("test: /\\.js(.erb)?$/", "test: /\\.jsx?(.erb)?$/") else puts "Couldn't automatically update loader test in #{config_path}. Please set test: /\.jsx?(.erb)?$/." end From 2ad9d13ac20e18a31452e4e721677421c57a2670 Mon Sep 17 00:00:00 2001 From: Gaurav Tiwari Date: Fri, 24 Feb 2017 14:47:12 +0000 Subject: [PATCH 07/15] Fix typo --- .eslintrc.js | 3 --- lib/install/config/shared.js | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index ca0a80858..c8a34e39a 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -9,9 +9,6 @@ module.exports = { "import/no-unresolved": "off", "import/no-extraneous-dependencies": "off", "import/extensions": "off", - "func-names": "off", - "prefer-arrow-callback": "off", - "object-shorthand": "off", "no-console": "off", }, "globals": { diff --git a/lib/install/config/shared.js b/lib/install/config/shared.js index 669fea4d4..a8216638d 100644 --- a/lib/install/config/shared.js +++ b/lib/install/config/shared.js @@ -19,7 +19,7 @@ const config = { const localMap = map; localMap[basename] = path.resolve(entry); return localMap; - }, {}, + }, {} ), output: { filename: '[name].js', path: path.resolve('public', distDir) }, From d4d89273af95f4019aba92f29e2412a028104473 Mon Sep 17 00:00:00 2001 From: Gaurav Tiwari Date: Fri, 24 Feb 2017 15:14:15 +0000 Subject: [PATCH 08/15] Use short hand and arrow function --- lib/install/config/shared.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/install/config/shared.js b/lib/install/config/shared.js index a8216638d..82b0936cf 100644 --- a/lib/install/config/shared.js +++ b/lib/install/config/shared.js @@ -14,7 +14,7 @@ if (distDir === undefined) { const config = { entry: glob.sync(path.join('app', 'javascript', 'packs', '*.js*')).reduce( - function (map, entry) { + (map, entry) => { const basename = path.basename(entry, extname(entry)); const localMap = map; localMap[basename] = path.resolve(entry); @@ -67,6 +67,6 @@ const config = { }; module.exports = { - distDir: distDir, - config: config, + distDir, + config, }; From d05106dd9c64b41eaaf6c89c90750f83555156bf Mon Sep 17 00:00:00 2001 From: Gaurav Tiwari Date: Fri, 24 Feb 2017 15:56:09 +0000 Subject: [PATCH 09/15] Remove duplicate plugins and use env to target browser --- .eslintrc.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index c8a34e39a..d3cf21c21 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,18 +1,13 @@ module.exports = { "extends": "airbnb", - "plugins": [ - "react", - "jsx-a11y", - "import" - ], "rules": { "import/no-unresolved": "off", "import/no-extraneous-dependencies": "off", "import/extensions": "off", "no-console": "off", }, - "globals": { - "document": true, - "window": true, + "env": { + "node": true, + "browser": true, }, }; From 9c1d98e275ffc554defa3d1911211af4d497c061 Mon Sep 17 00:00:00 2001 From: Gaurav Tiwari Date: Fri, 24 Feb 2017 16:03:42 +0000 Subject: [PATCH 10/15] Add rules to disable semicolon and trailing comma --- .eslintrc.js | 4 +- lib/install/angular/hello_angular.js | 2 +- lib/install/config/development.js | 18 +++---- lib/install/config/production.js | 14 +++--- lib/install/config/shared.js | 52 ++++++++++----------- lib/install/javascript/packs/application.js | 2 +- lib/install/react/hello_react.jsx | 18 +++---- 7 files changed, 56 insertions(+), 54 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index d3cf21c21..fa3828e2e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,13 +1,15 @@ module.exports = { "extends": "airbnb", "rules": { + "comma-dangle": ["error", "never"], "import/no-unresolved": "off", "import/no-extraneous-dependencies": "off", "import/extensions": "off", "no-console": "off", + semi: ['error', 'never'], }, "env": { - "node": true, "browser": true, + "node": true, }, }; diff --git a/lib/install/angular/hello_angular.js b/lib/install/angular/hello_angular.js index 10088d5dd..ea1350afd 100644 --- a/lib/install/angular/hello_angular.js +++ b/lib/install/angular/hello_angular.js @@ -4,4 +4,4 @@ // // <%= javascript_pack_tag 'hello_angular' %> -require('./hello_angular'); +require('./hello_angular') diff --git a/lib/install/config/development.js b/lib/install/config/development.js index 4a60142b2..24f9d630e 100644 --- a/lib/install/config/development.js +++ b/lib/install/config/development.js @@ -1,24 +1,24 @@ // Note: You must restart bin/webpack-watcher for changes to take effect -const webpack = require('webpack'); -const merge = require('webpack-merge'); +const webpack = require('webpack') +const merge = require('webpack-merge') -const sharedConfig = require('./shared.js'); +const sharedConfig = require('./shared.js') module.exports = merge(sharedConfig.config, { devtool: 'sourcemap', stats: { - errorDetails: true, + errorDetails: true }, output: { - pathinfo: true, + pathinfo: true }, plugins: [ new webpack.LoaderOptionsPlugin({ - debug: true, - }), - ], -}); + debug: true + }) + ] +}) diff --git a/lib/install/config/production.js b/lib/install/config/production.js index 3b92e9dff..3622e7f55 100644 --- a/lib/install/config/production.js +++ b/lib/install/config/production.js @@ -1,16 +1,16 @@ // Note: You must restart bin/webpack-watcher for changes to take effect -const webpack = require('webpack'); -const merge = require('webpack-merge'); +const webpack = require('webpack') +const merge = require('webpack-merge') -const sharedConfig = require('./shared.js'); +const sharedConfig = require('./shared.js') module.exports = merge(sharedConfig.config, { output: { filename: '[name]-[hash].js' }, plugins: [ new webpack.LoaderOptionsPlugin({ - minimize: true, - }), - ], -}); + minimize: true + }) + ] +}) diff --git a/lib/install/config/shared.js b/lib/install/config/shared.js index 82b0936cf..1845627c1 100644 --- a/lib/install/config/shared.js +++ b/lib/install/config/shared.js @@ -1,24 +1,24 @@ // Note: You must restart bin/webpack-watcher for changes to take effect -const webpack = require('webpack'); -const path = require('path'); -const process = require('process'); -const glob = require('glob'); -const extname = require('path-complete-extname'); +const webpack = require('webpack') +const path = require('path') +const process = require('process') +const glob = require('glob') +const extname = require('path-complete-extname') -let distDir = process.env.WEBPACK_DIST_DIR; +let distDir = process.env.WEBPACK_DIST_DIR if (distDir === undefined) { - distDir = 'packs'; + distDir = 'packs' } const config = { entry: glob.sync(path.join('app', 'javascript', 'packs', '*.js*')).reduce( (map, entry) => { - const basename = path.basename(entry, extname(entry)); - const localMap = map; - localMap[basename] = path.resolve(entry); - return localMap; + const basename = path.basename(entry, extname(entry)) + const localMap = map + localMap[basename] = path.resolve(entry) + return localMap }, {} ), @@ -33,9 +33,9 @@ const config = { loader: 'babel-loader', options: { presets: [ - ['latest', { es2015: { modules: false } }], - ], - }, + ['latest', { es2015: { modules: false } }] + ] + } }, { test: /.erb$/, @@ -43,30 +43,30 @@ const config = { exclude: /node_modules/, loader: 'rails-erb-loader', options: { - runner: 'DISABLE_SPRING=1 bin/rails runner', - }, - }, - ], + runner: 'DISABLE_SPRING=1 bin/rails runner' + } + } + ] }, plugins: [ - new webpack.EnvironmentPlugin(Object.keys(process.env)), + new webpack.EnvironmentPlugin(Object.keys(process.env)) ], resolve: { extensions: ['.js', '.coffee'], modules: [ path.resolve('app/javascript'), - path.resolve('node_modules'), - ], + path.resolve('node_modules') + ] }, resolveLoader: { - modules: [path.resolve('node_modules')], - }, -}; + modules: [path.resolve('node_modules')] + } +} module.exports = { distDir, - config, -}; + config +} diff --git a/lib/install/javascript/packs/application.js b/lib/install/javascript/packs/application.js index d9366bc08..5ed8fab83 100644 --- a/lib/install/javascript/packs/application.js +++ b/lib/install/javascript/packs/application.js @@ -6,4 +6,4 @@ // To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate // layout file, like app/views/layouts/application.html.erb -console.log('Hello World from Webpacker'); +console.log('Hello World from Webpacker') diff --git a/lib/install/react/hello_react.jsx b/lib/install/react/hello_react.jsx index 579159650..1545a2999 100644 --- a/lib/install/react/hello_react.jsx +++ b/lib/install/react/hello_react.jsx @@ -2,24 +2,24 @@ // like app/views/layouts/application.html.erb. All it does is render
Hello React
at the bottom // of the page. -import React from 'react'; -import ReactDOM from 'react-dom'; +import React from 'react' +import ReactDOM from 'react-dom' const Hello = props => (
Hello {props.name}!
-); +) Hello.defaultProps = { - name: 'David', -}; + name: 'David' +} Hello.propTypes = { - name: React.PropTypes.string, -}; + name: React.PropTypes.string +} document.addEventListener('DOMContentLoaded', () => { ReactDOM.render( , document.body.appendChild(document.createElement('div')), - ); -}); + ) +}) From 8f38dfb281839c12d872860963fdf97f07fca5eb Mon Sep 17 00:00:00 2001 From: Gaurav Tiwari Date: Fri, 24 Feb 2017 16:09:36 +0000 Subject: [PATCH 11/15] Use single quote for strings --- .eslintrc.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index fa3828e2e..aea8d3b4b 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,15 +1,15 @@ module.exports = { - "extends": "airbnb", - "rules": { - "comma-dangle": ["error", "never"], - "import/no-unresolved": "off", - "import/no-extraneous-dependencies": "off", - "import/extensions": "off", - "no-console": "off", + 'extends': 'airbnb', + 'rules': { + 'comma-dangle': ['error', 'never'], + 'import/no-unresolved': 'off', + 'import/no-extraneous-dependencies': 'off', + 'import/extensions': 'off', + 'no-console': 'off', semi: ['error', 'never'], }, - "env": { - "browser": true, - "node": true, + 'env': { + 'browser': true, + 'node': true, }, }; From 21f5e26b6b554f8c8d2b0e50796ee13307a878b7 Mon Sep 17 00:00:00 2001 From: Gaurav Tiwari Date: Sat, 25 Feb 2017 04:18:30 +0000 Subject: [PATCH 12/15] Lint vue example --- lib/install/vue/hello_vue.js | 5 +++-- package.json | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/install/vue/hello_vue.js b/lib/install/vue/hello_vue.js index 903c42ded..955dacd55 100644 --- a/lib/install/vue/hello_vue.js +++ b/lib/install/vue/hello_vue.js @@ -1,4 +1,5 @@ -// Run this example by adding <%= javascript_pack_tag 'hello_vue' %> to the head of your layout file, +// Run this example by adding <%= javascript_pack_tag 'hello_vue' %> +// to the head of your layout file, // like app/views/layouts/application.html.erb. // All it does is render
Hello Vue
at the bottom of the page. @@ -7,7 +8,7 @@ import App from './app.vue' document.body.appendChild(document.createElement('hello')) -new Vue({ +Vue({ el: 'hello', template: '', components: { App } diff --git a/package.json b/package.json index f982959c4..e49b12c81 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "eslint-plugin-react": "^6.10.0" }, "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "lint": "node_modules/eslint/bin/eslint.js lib/ --fix" }, "repository": { "type": "git", From 6bc43046ca8bcf151cb8d9f7a66eeadb09d81820 Mon Sep 17 00:00:00 2001 From: Gaurav Tiwari Date: Sat, 25 Feb 2017 04:20:49 +0000 Subject: [PATCH 13/15] Fix typo --- lib/install/config/shared.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/install/config/shared.js b/lib/install/config/shared.js index 3dd613556..3458fc530 100644 --- a/lib/install/config/shared.js +++ b/lib/install/config/shared.js @@ -26,7 +26,7 @@ const config = { module: { rules: [ - { test: /\.coffee(.erb)?$/, loader: 'coffee-loader' }, + { test: /\.coffee(\.erb)?$/, loader: 'coffee-loader' }, { test: /\.js(\.erb)?$/, exclude: /node_modules/, From aee16bbc0730bd0cb1c32f2e105f69000c0f1f69 Mon Sep 17 00:00:00 2001 From: Gaurav Tiwari Date: Sat, 25 Feb 2017 04:22:33 +0000 Subject: [PATCH 14/15] Remove inline argument --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e49b12c81..2ae5e40ac 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "lint": "node_modules/eslint/bin/eslint.js lib/ --fix" + "lint": "node_modules/eslint/bin/eslint.js lib/" }, "repository": { "type": "git", From b373ea78d1bcaa8d12954452cbad02a9cf072be8 Mon Sep 17 00:00:00 2001 From: Gaurav Tiwari Date: Mon, 27 Feb 2017 11:03:32 +0000 Subject: [PATCH 15/15] Use standard no-console rule --- .eslintrc.js | 1 - lib/install/javascript/packs/application.js | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index aea8d3b4b..8115616dc 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -5,7 +5,6 @@ module.exports = { 'import/no-unresolved': 'off', 'import/no-extraneous-dependencies': 'off', 'import/extensions': 'off', - 'no-console': 'off', semi: ['error', 'never'], }, 'env': { diff --git a/lib/install/javascript/packs/application.js b/lib/install/javascript/packs/application.js index 5ed8fab83..54b106ee0 100644 --- a/lib/install/javascript/packs/application.js +++ b/lib/install/javascript/packs/application.js @@ -1,3 +1,4 @@ +/* eslint no-console:0 */ // This file is automatically compiled by Webpack, along with any other files // present in this directory. You're encouraged to place your actual application logic in // a relevant structure within app/javascript and only use these pack files to reference