@@ -54,7 +54,7 @@ Shopify Theme Lab is a customizable modular development environment for blazing-
54
54
- [ Bulma] ( #bulma )
55
55
- [ Swapping JavaScript framework] ( #swapping-javascript-framework )
56
56
- [ Removing Vue] ( #removing-vue )
57
- - [ React ] ( #react )
57
+ - [ Alpine.js ] ( #alpinejs )
58
58
- [ Project structure] ( #project-structure )
59
59
- [ Tasks] ( #tasks )
60
60
- [ Development environment concepts] ( #development-environment-concepts )
@@ -95,7 +95,7 @@ Shopify Theme Lab is a customizable modular development environment for blazing-
95
95
- JavaScript
96
96
- [ Vue] ( https://vuejs.org )
97
97
- [ Vuex] ( https://vuex.vuejs.org )
98
- - Swap Vue with any other framework e.g. [ React ] ( https://reactjs.org )
98
+ - Swap Vue with any other framework e.g. [ Alpine.js ] ( https://github.com/alpinejs/alpine )
99
99
- [ Axios] ( https://github.com/axios/axios )
100
100
- Extend with [ npm packages] ( https://www.npmjs.com ) 📦
101
101
- CSS
@@ -443,108 +443,24 @@ module: {
443
443
}
444
444
` ` `
445
445
446
- # ## React
446
+ # ## Alpine.js
447
+ If you want to use something lighter than Vue, a good alternative is [Alpine.js](https://github.com/alpinejs/alpine).
447
448
448
- 1. Install packages :
449
+ 1. Install package :
449
450
450
451
# ### npm
451
452
` ` ` sh
452
- $ npm install react react-dom
453
- $ npm install @babel/preset-react --save-dev
453
+ $ npm install alpinejs
454
454
` ` `
455
455
456
456
# ### yarn
457
457
` ` ` sh
458
- $ yarn add react react-dom
459
- $ yarn add @babel/preset-react --dev
458
+ $ yarn add alpinejs
460
459
` ` `
461
460
462
- 2. Inside [webpack.common. js](.config/webpack/webpack.common .js) :
461
+ 2. Import `alpinejs` in [main. js](src/main .js) :
463
462
` ` ` js
464
- ...
465
- resolve: {
466
- extensions: [... '.jsx'] // add jsx to extensions array
467
- }
468
- ...
469
- ` ` `
470
-
471
- ` ` ` js
472
- ...
473
- module: {
474
- rules: [
475
- // add babel-loader for jsx,
476
- // remove the same loader from webpack.prod.js
477
- {
478
- test: /\. (js|jsx)$/,
479
- loader: 'babel-loader',
480
- exclude: /node_modules/,
481
- options: {
482
- presets: [ '@babel/preset-env', '@babel/preset-react' ]
483
- }
484
- },
485
- ...
486
- ]
487
- }
488
- ...
489
- ` ` `
490
-
491
- 3. Add ecmaFeatures to [.eslint.js](config/.eslint.js) :
492
- ` ` ` js
493
- ...
494
- parserOptions: {
495
- ecmaVersion: 2020,
496
- sourceType: 'module',
497
- ecmaFeatures: { // add ecmaFeatures
498
- jsx: true,
499
- modules: true
500
- }
501
- }
502
- ...
503
- ` ` `
504
-
505
- 4. Add following code to [main.js](src/main.js) :
506
- ` ` ` js
507
- // eslint-disable-next-line
508
- import React from 'react'
509
- import { render } from 'react-dom'
510
-
511
- /**
512
- * react components
513
- * auto-map all react components to dom elements
514
- */
515
- const reactComponents = require.context('./react/components/', true, /\. (jsx|js)$/)
516
-
517
- reactComponents.keys().forEach(key => {
518
- const Component = reactComponents(key).default
519
-
520
- // transform file name to PascalCase
521
- const name = key.replace(/\. (\/ |jsx|js)/g, '').replace(/(\/ |-|_|\s )\w /g, (match) => match.slice(1).toUpperCase())
522
-
523
- const domElement = document.querySelector(` [react-component='${name}']`)
524
- render(<Component/>, domElement)
525
- })
526
- ```
527
-
528
- 5 . Create ` src/react/components/MyComponent.jsx ` with following content:
529
- ``` js
530
- import React from ' react'
531
-
532
- class MyComponent extends React .Component {
533
- render () {
534
- return (
535
- < div>
536
- My Component
537
- < / div>
538
- )
539
- }
540
- }
541
-
542
- export default MyComponent
543
- ```
544
-
545
- 6 . Add a dom element to [ theme.liquid] ( shopify/layout/theme.liquid ) or any other ` .liquid ` file:
546
- ``` html
547
- <div react-component =" MyComponent" ></div >
463
+ import 'alpinejs'
548
464
` ` `
549
465
<!-- swapping javascript framework (end) -->
550
466
0 commit comments