Skip to content

Commit 7a67760

Browse files
authored
Merge pull request #38 from uicrooks/dev
v2.4.8
2 parents f46c6f7 + 1d25ed9 commit 7a67760

File tree

4 files changed

+134
-34
lines changed

4 files changed

+134
-34
lines changed

README.md

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ Shopify Theme Lab is a customizable modular development environment for blazing-
5151
- [Stylus](#stylus)
5252
- [Swapping CSS framework](swapping-css-framework)
5353
- [Removing Tailwind CSS](#removing-tailwind-css)
54-
- [Bulma](#Bulma)
54+
- [Bulma](#bulma)
5555
- [Swapping JavaScript framework](swapping-javascript-framework)
5656
- [Removing Vue](#removing-vue)
57+
- [React](#react)
5758
- [Project structure](#project-structure)
5859
- [Tasks](#tasks)
5960
- [Development environment concepts](#development-environment-concepts)
@@ -92,6 +93,7 @@ Shopify Theme Lab is a customizable modular development environment for blazing-
9293
- JavaScript
9394
- [Vue](https://vuejs.org)
9495
- [Vuex](https://vuex.vuejs.org)
96+
- Swap Vue with any other framework e.g. [React](https://reactjs.org)
9597
- [Axios](https://github.com/axios/axios)
9698
- Extend with [npm packages](https://www.npmjs.com) 📦
9799
- CSS
@@ -438,6 +440,110 @@ module: {
438440
]
439441
}
440442
```
443+
444+
### React
445+
446+
1. Install packages:
447+
448+
#### npm
449+
```sh
450+
$ npm install react react-dom
451+
$ npm install @babel/preset-react --save-dev
452+
```
453+
454+
#### yarn
455+
```sh
456+
$ yarn add react react-dom
457+
$ yarn add @babel/preset-react --dev
458+
```
459+
460+
2. Inside [webpack.common.js](.config/webpack/webpack.common.js):
461+
```js
462+
...
463+
resolve: {
464+
extensions: [... '.jsx'] // add jsx to extensions array
465+
}
466+
...
467+
```
468+
469+
```js
470+
...
471+
module: {
472+
rules: [
473+
// add babel-loader for jsx,
474+
// remove the same loader from webpack.prod.js
475+
{
476+
test: /\.(js|jsx)$/,
477+
loader: 'babel-loader',
478+
exclude: /node_modules/,
479+
options: {
480+
presets: [ '@babel/preset-env', '@babel/preset-react' ]
481+
}
482+
},
483+
...
484+
]
485+
}
486+
...
487+
```
488+
489+
3. Add ecmaFeatures to [.eslint.js](config/.eslint.js):
490+
```js
491+
...
492+
parserOptions: {
493+
ecmaVersion: 2020,
494+
sourceType: 'module',
495+
ecmaFeatures: { // add ecmaFeatures
496+
jsx: true,
497+
modules: true
498+
}
499+
}
500+
...
501+
```
502+
503+
4. Add following code to [main.js](src/main.js):
504+
```js
505+
// eslint-disable-next-line
506+
import React from 'react'
507+
import { render } from 'react-dom'
508+
509+
/**
510+
* react components
511+
* auto-map all react components to dom elements
512+
*/
513+
const reactComponents = require.context('./react/components/', true, /\.(jsx|js)$/)
514+
515+
reactComponents.keys().forEach(key => {
516+
const Component = reactComponents(key).default
517+
518+
// transform file name to PascalCase
519+
const name = key.replace(/\.(\/|jsx|js)/g, '').replace(/(\/|-|_|\s)\w/g, (match) => match.slice(1).toUpperCase())
520+
521+
const domElement = document.querySelector(`[react-component='${name}']`)
522+
render(<Component/>, domElement)
523+
})
524+
```
525+
526+
5. Create `src/react/components/MyComponent.jsx` with following content:
527+
```js
528+
import React from 'react'
529+
530+
class MyComponent extends React.Component {
531+
render() {
532+
return(
533+
<div>
534+
My Component
535+
</div>
536+
)
537+
}
538+
}
539+
540+
export default MyComponent
541+
```
542+
543+
6. Add a dom element to [theme.liquid](shopify/layout/theme.liquid) or any other `.liquid` file:
544+
```html
545+
<div react-component="MyComponent"></div>
546+
```
441547
<!-- swapping javascript framework (end) -->
442548

443549
<!-- project structure (start) -->

package-lock.json

Lines changed: 22 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "shopify-theme-lab",
33
"description": "Customizable modular development environment for blazing-fast Shopify theme creation",
44
"author": "Sergej Samsonenko <contact@sergej.codes>",
5-
"version": "2.4.7",
5+
"version": "2.4.8",
66
"license": "MIT",
77
"config": {
88
"reloadr": {
@@ -47,14 +47,14 @@
4747
"css-loader": "^5.0.1",
4848
"css-minimizer-webpack-plugin": "^1.2.0",
4949
"eslint": "^7.18.0",
50-
"eslint-plugin-vue": "^7.4.1",
50+
"eslint-plugin-vue": "^7.5.0",
5151
"eslint-webpack-plugin": "^2.4.3",
5252
"file-loader": "^6.2.0",
5353
"mini-css-extract-plugin": "^1.3.4",
5454
"npm-run-all": "^4.1.5",
5555
"postcss": "^8.2.4",
5656
"postcss-import": "^14.0.0",
57-
"postcss-loader": "^4.1.0",
57+
"postcss-loader": "^4.2.0",
5858
"postcss-preset-env": "^6.7.0",
5959
"progress-webpack-plugin": "^1.0.11",
6060
"shopify-reloadr": "^1.0.2",
@@ -65,7 +65,7 @@
6565
"url-loader": "^4.1.1",
6666
"vue-loader": "^15.9.6",
6767
"vue-template-compiler": "^2.6.12",
68-
"webpack": "^5.16.0",
68+
"webpack": "^5.17.0",
6969
"webpack-cli": "^4.4.0",
7070
"webpack-merge": "^5.7.3"
7171
}

shopify/snippets/vue-examples.liquid

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
</div>
8383
</renderless-my-component>
8484

85-
<!-- vuex anywhere! -->
85+
<!-- vuex module: src/vue/store/my-module.js -->
8686
<div>
8787
<div class="shopify-theme-lab__subline">
8888
Vuex anywhere!

0 commit comments

Comments
 (0)