|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Qirolab\Theme\Presets; |
| 4 | + |
| 5 | +use Qirolab\Theme\Presets\Traits\PresetTrait; |
| 6 | + |
| 7 | +class Vue3Preset |
| 8 | +{ |
| 9 | + use PresetTrait; |
| 10 | + |
| 11 | + public function export(): void |
| 12 | + { |
| 13 | + $this->updatePackages() |
| 14 | + ->exportVueComponent() |
| 15 | + ->exportJs(); |
| 16 | + } |
| 17 | + |
| 18 | + /** |
| 19 | + * Update the given package array. |
| 20 | + * |
| 21 | + * @param array $packages |
| 22 | + * @return array |
| 23 | + */ |
| 24 | + protected static function updatePackageArray(array $packages): array |
| 25 | + { |
| 26 | + return [ |
| 27 | + '@vue/compiler-sfc' => '^3.0.5', |
| 28 | + 'resolve-url-loader' => '^3.1.2', |
| 29 | + 'sass' => '^1.32.1', |
| 30 | + 'sass-loader' => '^10.1.1', |
| 31 | + 'vue' => '^3.0.5', |
| 32 | + 'vue-loader' => '^16.1.2', |
| 33 | + ] + $packages; |
| 34 | + |
| 35 | + // return [ |
| 36 | + // 'resolve-url-loader' => '^2.3.1', |
| 37 | + // 'sass' => '^1.20.1', |
| 38 | + // 'sass-loader' => '^8.0.0', |
| 39 | + // 'vue' => '^2.5.17', |
| 40 | + // 'vue-template-compiler' => '^2.6.10', |
| 41 | + // ] + Arr::except($packages, [ |
| 42 | + // '@babel/preset-react', |
| 43 | + // 'react', |
| 44 | + // 'react-dom', |
| 45 | + // ]); |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * Update the bootstrapping files. |
| 50 | + * |
| 51 | + * @return $this |
| 52 | + */ |
| 53 | + protected function exportJs() |
| 54 | + { |
| 55 | + copy(__DIR__ . '/../../stubs/Presets/vue3-stubs/app.js', $this->themePath('js/app.js')); |
| 56 | + |
| 57 | + if (! $this->exists($this->themePath('js/bootstrap.js'))) { |
| 58 | + copy(__DIR__ . '/../../stubs/Presets/vue3-stubs/bootstrap.js', $this->themePath('js/bootstrap.js')); |
| 59 | + } |
| 60 | + |
| 61 | + return $this; |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * Update the example component. |
| 66 | + * |
| 67 | + * @return $this |
| 68 | + */ |
| 69 | + protected function exportVueComponent() |
| 70 | + { |
| 71 | + $this->ensureDirectoryExists($this->themePath('js/components')); |
| 72 | + |
| 73 | + copy( |
| 74 | + __DIR__ . '/../../stubs/Presets/vue3-stubs/ExampleComponent.vue', |
| 75 | + $this->themePath('js/components/ExampleComponent.vue') |
| 76 | + ); |
| 77 | + |
| 78 | + return $this; |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * @return null|string |
| 83 | + */ |
| 84 | + public function webpackJs() |
| 85 | + { |
| 86 | + $jsMix = '.js(`${__dirname}/js/app.js`, "js")'; |
| 87 | + $jsMix .= "\n .vue()"; |
| 88 | + |
| 89 | + return $jsMix; |
| 90 | + } |
| 91 | +} |
0 commit comments