webpacker-react 0.3.2 → 1.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpacker-react",
3
- "version": "0.3.2",
3
+ "version": "1.0.0-beta.1",
4
4
  "description": "Javascript",
5
5
  "main": "index.js",
6
6
  "homepage": "https://github.com/renchap/webpacker-react",
@@ -16,11 +16,13 @@
16
16
  "files": [
17
17
  "index.js",
18
18
  "configure-hot-module-replacement.js",
19
- "hmr.js",
20
19
  "ujs.js"
21
20
  ],
22
21
  "scripts": {
23
22
  "prepublish": "cd .. ; yarn run build"
24
23
  },
25
- "license": "MIT"
24
+ "license": "MIT",
25
+ "dependencies": {
26
+ "webpack-merge": "^4.1.1"
27
+ }
26
28
  }
@@ -2,3 +2,12 @@
2
2
  # yarn lockfile v1
3
3
 
4
4
 
5
+ lodash@^4.17.4:
6
+ version "4.17.4"
7
+ resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
8
+
9
+ webpack-merge@^4.1.1:
10
+ version "4.1.1"
11
+ resolved "https://registry.yarnpkg.com/webpack-merge/-/webpack-merge-4.1.1.tgz#f1197a0a973e69c6fbeeb6d658219aa8c0c13555"
12
+ dependencies:
13
+ lodash "^4.17.4"
@@ -2,17 +2,17 @@
2
2
  "name": "webpacker-react-build",
3
3
  "private": true,
4
4
  "scripts": {
5
- "build": "babel src --presets=babel-preset-es2015 --out-dir dist",
5
+ "build": "babel src --out-dir dist",
6
6
  "lint": "eslint src/"
7
7
  },
8
8
  "devDependencies": {
9
9
  "babel-cli": "^6.18.0",
10
- "babel-preset-es2015": "^6.22.0",
11
- "eslint": "^4.6.1",
12
- "eslint-config-airbnb": "^15.1.0",
13
- "eslint-plugin-import": "^2.7.0",
14
- "eslint-plugin-jsx-a11y": "^5.1.1",
15
- "eslint-plugin-react": "^7.3.0"
10
+ "babel-preset-env": "^1.6.1",
11
+ "eslint": "^5.3.0",
12
+ "eslint-config-airbnb": "^17.0.0",
13
+ "eslint-plugin-import": "^2.9.0",
14
+ "eslint-plugin-jsx-a11y": "^6.0.3",
15
+ "eslint-plugin-react": "^7.7.0"
16
16
  },
17
17
  "dependencies": {
18
18
  "lodash": "^4.0.0"
@@ -1,16 +1,7 @@
1
- import webpack from 'webpack'
2
1
  import merge from 'webpack-merge'
3
2
 
4
- function configureHotModuleReplacement(originalConfig) {
5
- const config = merge(
6
- originalConfig,
7
- {
8
- plugins: [
9
- new webpack.NamedModulesPlugin()
10
- ]
11
- }
12
- )
13
-
3
+ function configureHotModuleReplacement(origConfig) {
4
+ const config = origConfig
14
5
  config.module.rules = config.module.rules.map((rule) => {
15
6
  if (rule.loader === 'babel-loader') {
16
7
  return merge(rule, { options: { plugins: ['react-hot-loader/babel'] } })
@@ -18,12 +9,6 @@ function configureHotModuleReplacement(originalConfig) {
18
9
  return rule
19
10
  })
20
11
 
21
- Object.keys(config.entry).forEach((key) => {
22
- if (!(config.entry[key] instanceof Array)) {
23
- config.entry[key] = [config.entry[key]]
24
- }
25
- config.entry[key].unshift('react-hot-loader/patch')
26
- })
27
12
  return config
28
13
  }
29
14
 
@@ -11,38 +11,14 @@ const PROPS_ATTRIBUTE_NAME = 'data-react-props'
11
11
 
12
12
  const WebpackerReact = {
13
13
  registeredComponents: {},
14
- wrapForHMR: null,
15
14
 
16
15
  render(node, component) {
17
16
  const propsJson = node.getAttribute(PROPS_ATTRIBUTE_NAME)
18
17
  const props = propsJson && JSON.parse(propsJson)
19
18
 
20
- let reactElement = React.createElement(component, props)
21
- if (this.wrapForHMR) {
22
- reactElement = this.wrapForHMR(reactElement)
23
- }
24
- ReactDOM.render(reactElement, node)
25
- },
26
-
27
- renderOnHMR(component) {
28
- const name = component.name
29
-
30
- this.registeredComponents[name] = component
31
-
32
- if (!this.wrapForHMR) {
33
- console.warn('webpacker-react: renderOnHMR called but not elements not wrapped for HMR')
34
- }
19
+ const reactElement = React.createElement(component, props)
35
20
 
36
- const toMount = document.querySelectorAll(`[${CLASS_ATTRIBUTE_NAME}=${name}]`)
37
- for (let i = 0; i < toMount.length; i += 1) {
38
- const node = toMount[i]
39
-
40
- this.render(node, component)
41
- }
42
- },
43
-
44
- registerWrapForHMR(wrapForHMR) {
45
- this.wrapForHMR = wrapForHMR
21
+ ReactDOM.render(reactElement, node)
46
22
  },
47
23
 
48
24
  registerComponents(components) {
@@ -63,7 +39,7 @@ const WebpackerReact = {
63
39
  },
64
40
 
65
41
  mountComponents() {
66
- const registeredComponents = this.registeredComponents
42
+ const { registeredComponents } = this
67
43
  const toMount = document.querySelectorAll(`[${CLASS_ATTRIBUTE_NAME}]`)
68
44
 
69
45
  for (let i = 0; i < toMount.length; i += 1) {
@@ -74,7 +50,7 @@ const WebpackerReact = {
74
50
  if (component) {
75
51
  if (node.innerHTML.length === 0) this.render(node, component)
76
52
  } else {
77
- console.error(`webpacker-react: cant render a component that has not been registered: ${className}`)
53
+ console.error(`webpacker-react: can not render a component that has not been registered: ${className}`)
78
54
  }
79
55
  }
80
56
  },
@@ -19,7 +19,7 @@ const ujs = {
19
19
 
20
20
  setup(onMount, onUnmount) {
21
21
  const $ = (typeof window.jQuery !== 'undefined') && window.jQuery
22
- const Turbolinks = window.Turbolinks
22
+ const { Turbolinks } = window
23
23
 
24
24
  // Detect which kind of events to set up:
25
25
  if (typeof Turbolinks !== 'undefined' && Turbolinks.supported) {
@@ -46,7 +46,7 @@ const ujs = {
46
46
  },
47
47
 
48
48
  turbolinksClassic(onMount, onUnmount) {
49
- const Turbolinks = window.Turbolinks
49
+ const { Turbolinks } = window
50
50
 
51
51
  this.handleEvent(Turbolinks.EVENTS.CHANGE, onMount)
52
52
  this.handleEvent(Turbolinks.EVENTS.BEFORE_UNLOAD, onUnmount)
@@ -57,7 +57,7 @@ const ujs = {
57
57
  // have named events and didn't have a before-unload event.
58
58
  // Also, it didn't work with the Turbolinks cache, see
59
59
  // https://github.com/reactjs/react-rails/issues/87
60
- const Turbolinks = window.Turbolinks
60
+ const { Turbolinks } = window
61
61
  Turbolinks.pagesCached(0)
62
62
  this.handleEvent('page:change', onMount)
63
63
  this.handleEvent('page:receive', onUnmount)