Laravel Mix – 永夜 https://www.shuijingwanwq.com 没有不值得去解决的问题,也没有不值得去学习的技术! Thu, 28 May 2026 12:53:55 +0000 zh-Hans hourly 1 https://wordpress.org/?v=7.0 在 Laravel 6 中,安装 Laravel Mix 时(npm install),报错:npm ERR! ERESOLVE unable to resolve dependency tree https://www.shuijingwanwq.com/2023/06/20/7747/ https://www.shuijingwanwq.com/2023/06/20/7747/#respond Tue, 20 Jun 2023 01:28:32 +0000 https://www.shuijingwanwq.com/?p=7747 浏览量: 85 1、在 Laravel 6 中,安装 Laravel Mix 时(npm install),报错:npm ERR! ERESOLVE unable to resolve dependency tree。如图1
在 Laravel 6 中,安装 Laravel Mix 时(npm install),报错:npm ERR! ERESOLVE unable to resolve dependency tree

图1



PS E:\wwwroot\object> npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: undefined@undefined
npm ERR! Found: postcss@8.3.1
npm ERR! node_modules/postcss
npm ERR!   dev postcss@"8.3.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer postcss@"^8.3.11" from laravel-mix@6.0.39
npm ERR! node_modules/laravel-mix
npm ERR!   dev laravel-mix@"^6.0.31" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR!
npm ERR! For a full report see:
npm ERR! C:\Users\Lenovo\AppData\Local\npm-cache\_logs\2023-05-19T07_21_41_833Z-eresolve-report.txt

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Lenovo\AppData\Local\npm-cache\_logs\2023-05-19T07_21_41_833Z-debug-0.log


2、发现程序根目录下存在:yarn.lock,替换为:yarn 命令,不再报错。如图2
发现程序根目录下存在:yarn.lock,替换为:yarn 命令,不再报错

图2



PS E:\wwwroot\object> yarn
yarn install v1.22.15
[1/4] Resolving packages...
[2/4] Fetching packages...


]]>
https://www.shuijingwanwq.com/2023/06/20/7747/feed/ 0
执行 yarn 时,报错:Failed to apply patch for package laravel-mix. This happened because the patch file patches\laravel-mix+6.0.43.patch could not be parsed. https://www.shuijingwanwq.com/2022/07/06/6752/ https://www.shuijingwanwq.com/2022/07/06/6752/#respond Wed, 06 Jul 2022 01:14:40 +0000 https://www.shuijingwanwq.com/?p=6752 浏览量: 323 1、执行 yarn 时,报错:Failed to apply patch for package laravel-mix.This happened because the patch file patches\laravel-mix+6.0.43.patch could not be parsed.。如图1
执行 yarn 时,报错:Failed to apply patch for package laravel-mix.This happened because the patch file patches\laravel-mix+6.0.43.patch could not be parsed.

图1



PS E:\wwwroot\object> yarn
yarn install v1.22.15
[1/5] Validating package.json...
[2/5] Resolving packages...
success Already up-to-date.
$ patch-package
patch-package 6.4.7
Applying patches...
concat@1.0.3 ✔
eslint-plugin-jsonc@2.3.0 ✔

**ERROR** Failed to apply patch for package laravel-mix

  This happened because the patch file patches\laravel-mix+6.0.43.patch could not be parsed.

  If you just upgraded patch-package, you can try running:

    cd patches\laravel-mix+6.0.43.patc
    patch -p1 -i h
    npx patch-package laravel-mix
    cd ../..

  Otherwise, try manually creating the patch file again.

  If the problem persists, please submit a bug report:

    https://github.com/ds300/patch-package/issues/new?title=Patch+file+parse+error&body=%3CPlease+attach+the+patch+file+in+question%3E


error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.


2、查看 Git 日志,patches\laravel-mix+6.0.43.patch 的上一个版本是:patches\laravel-mix+6.0.48.patch。如图2
查看 Git 日志,patches\laravel-mix+6.0.43.patch 的上一个版本是:patches\laravel-mix+6.0.48.patch

图2

3、删除掉目录:node_modules 后,再次执行:yarn,仍然报同样的错误。如图3
删除掉目录:node_modules 后,再次执行:yarn,仍然报同样的错误

图3

4、参考提示,执行:npx patch-package laravel-mix。如图4
参考提示,执行:npx patch-package laravel-mix

图4



PS E:\wwwroot\object> npx patch-package laravel-mix
patch-package 6.4.7
• Creating temporary folder
• Installing laravel-mix@6.0.43 with yarn
• Diffing your files with clean files
⁉️  Not creating patch file for package 'laravel-mix'
⁉️  There don't appear to be any changes.
npm notice
npm notice New minor version of npm available! 8.1.2 -> 8.12.1
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.12.1
npm notice Run npm install -g npm@8.12.1 to update!
npm notice


5、再次执行:yarn,仍然报错。参考:https://github.com/ds300/patch-package/issues/191 。将换行符从 CRLF 替换为 LF。不再报错。如图5
再次执行:yarn,仍然报错。参考:https://github.com/ds300/patch-package/issues/191 。将换行符从 CRLF 替换为 LF。不再报错。

图5

]]>
https://www.shuijingwanwq.com/2022/07/06/6752/feed/ 0
执行命令:npm run build 时,提示:npm ERR! Missing script: “build” https://www.shuijingwanwq.com/2022/04/18/6301/ https://www.shuijingwanwq.com/2022/04/18/6301/#respond Mon, 18 Apr 2022 01:39:17 +0000 https://www.shuijingwanwq.com/?p=6301 浏览量: 154 1、执行命令:npm run build 时,提示:npm ERR! Missing script: “build”。如图1
执行命令:npm run build 时,提示:npm ERR! Missing script: "build"

图1



PS E:\wwwroot\object> npm run build
npm ERR! Missing script: "build"
npm ERR!
npm ERR! To see a list of scripts, run:
npm ERR!   npm run

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Lenovo\AppData\Local\npm-cache\_logs\2022-04-15T01_30_16_068Z-debug.log


2、查看 package.json 文件,可以确认 scripts 中并未包含 build 脚本。如图2
查看 package.json 文件,可以确认 scripts 中并未包含 build 脚本

图2



{
  "private": true,
  "scripts": {
    "test": "jest",
    "dev": "npm run development",
    "development": "mix",
    "watch": "mix watch",
    "watch-poll": "mix watch -- --watch-options-poll=1000",
    "hot": "mix watch --hot",
    "production": "mix --production",
    "prod": "npm run production",
    "gh-pages": "gh-pages -d public/docs -r https://github.com/pheye/wdocs.git",
    "analyzer": "NODE_ENV=production npm_config_report=true npm run prod"
  },
  "devDependencies": {
    "@sentry/webpack-plugin": "^1.13.0",
    "babel-core": "^6.26.3",
    "babel-eslint": "^10.1.0",
    "babel-jest": "^25.1.0",
    "babel-plugin-component": "^1.1.1",
    "babel-plugin-import": "^1.13.0",
    "babel-preset-es2015": "^6.24.1",
    "credit-card-type": "^9.1.0",
    "cross-env": "^5.1",
    "eslint": "^6.8.0",
    "eslint-config-airbnb": "^18.1.0",
    "eslint-plugin-import": "^2.20.1",
    "eslint-plugin-jsx-a11y": "^6.2.3",
    "eslint-plugin-react": "^7.19.0",
    "gh-pages": "^3.2.3",
    "jest": "^25.1.0",
    "jest-allure": "^0.1.1",
    "jest-puppeteer": "^4.4.0",
    "laravel-mix": "^6.0.31",
    "laravel-mix-alias": "^1.0.3",
    "laravel-mix-bundle-analyzer": "^1.0.5",
    "laravel-mix-versionhash": "^2.0.1",
    "mockjs": "^1.1.0",
    "popper.js": "^1.12",
    "postcss": "8.3.1",
    "regenerator-runtime": "^0.13.3",
    "resolve-url-loader": "^2.3.1",
    "sass": "1.32.12",
    "sass-loader": "12.3.0",
    "sass-resources-loader": "^2.2.4",
    "slick-carousel": "^1.8.1",
    "terser-webpack-plugin": "5.2.4",
    "vue": "^2.5.17",
    "vue-custom-scrollbar": "^1.4.0",
    "vue-template-compiler": "^2.6.11"
  },
  "dependencies": {
    "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.5",
    "@babel/plugin-proposal-optional-chaining": "^7.16.5",
    "@sentry/browser": "^5.27.0",
    "@sentry/integrations": "^5.27.0",
    "@stripe/stripe-js": "^1.7.0",
    "axios": "^0.21.1",
    "babel-polyfill": "^6.26.0",
    "better-scroll": "^1.15.2",
    "bootstrap": "^4.6.1",
    "credit-card-type": "^9.1.0",
    "currency-symbol-map": "^4.0.4",
    "element-ui": "^2.13.0",
    "jquery": "^3.5",
    "lazysizes": "^5.2.0",
    "lodash": "^4.17.21",
    "normalize.css": "^8.0.1",
    "puppeteer": "^2.1.1",
    "qs": "^6.10.1",
    "slick-carousel": "^1.8.1",
    "uuid": "^7.0.3",
    "vue-awesome-swiper": "^3.1.3",
    "vue-country-flag": "^2.0.1",
    "vue-custom-scrollbar": "^1.4.0",
    "vue-i18n": "^8.22.2",
    "vue-loader": "15.9.8",
    "vue-phone-number-input": "^1.1.7",
    "vue-social-sharing": "^2.4.7",
    "vue-waterfall2": "^1.10.1",
    "vue-youtube": "^1.4.0",
    "vuex": "^3.1.2"
  }
}



3、根据提示:To see a list of scripts, run: npm run。要查看脚本列表,请运行 npm run。支持:npm run dev、npm run prod。如图3
根据提示:To see a list of scripts, run: npm run。要查看脚本列表,请运行 npm run。支持:npm run dev、npm run prod

图3



PS E:\wwwroot\object> npm run
Lifecycle scripts included in undefined:
  test
    jest

available via `npm run-script`:
  dev
    npm run development
  development
    mix
  watch
    mix watch
  watch-poll
    mix watch -- --watch-options-poll=1000
  hot
    mix watch --hot
  production
    mix --production
  prod
    npm run production
  gh-pages
    gh-pages -d public/docs -r https://github.com/pheye/wdocs.git
  analyzer
    NODE_ENV=production npm_config_report=true npm run prod



4、执行 npm run dev ,运行成功。如图4
执行 npm run dev ,运行成功

图4



PS E:\wwwroot\object> npm run dev

> dev
> npm run development


> development
> mix


● Mix █████████████████████████ emitting (98%)
 after emit





   Laravel Mix v6.0.39


✔ Compiled Successfully in 127974ms


]]>
https://www.shuijingwanwq.com/2022/04/18/6301/feed/ 0
在 Laravel 6 中,报错:Illuminate \ View \ ViewException (E_ERROR) The Mix manifest does not exist. https://www.shuijingwanwq.com/2022/03/10/6109/ https://www.shuijingwanwq.com/2022/03/10/6109/#respond Thu, 10 Mar 2022 01:20:39 +0000 https://www.shuijingwanwq.com/?p=6109 浏览量: 146 1、在 Laravel 6 中,报错:Illuminate \ View \ ViewException (E_ERROR) The Mix manifest does not exist.。如图1
在 Laravel 6 中,报错:Illuminate \ View \ ViewException (E_ERROR) The Mix manifest does not exist.

图1



[2022-02-16 17:15:55] local.ERROR: The Mix manifest does not exist. (View: E:\wwwroot\object\resources\views\vogue\pages\index.blade.php) {"exception":"[object] (Illuminate\\View\\ViewException(code: 0): The Mix manifest does not exist. (View: E:\\wwwroot\\object\
esources\\views\\vogue\\pages\\index.blade.php) at E:\\wwwroot\\object\\vendor\\arubacao\\asset-cdn\\src\\helpers.php:36)
[stacktrace]
#0 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\View\\Engines\\PhpEngine.php(45): Illuminate\\View\\Engines\\CompilerEngine->handleViewException(Object(Exception), 1)
#1 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\View\\Engines\\CompilerEngine.php(59): Illuminate\\View\\Engines\\PhpEngine->evaluatePath('E:\\\\wwwroot\\\\wsho...', Array)
#2 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\View\\View.php(143): Illuminate\\View\\Engines\\CompilerEngine->get('E:\\\\wwwroot\\\\wsho...', Array)
#3 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\View\\View.php(126): Illuminate\\View\\View->getContents()
#4 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\View\\View.php(91): Illuminate\\View\\View->renderContents()
#5 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Http\\Response.php(42): Illuminate\\View\\View->render()
#6 E:\\wwwroot\\object\\vendor\\symfony\\http-foundation\\Response.php(205): Illuminate\\Http\\Response->setContent(Object(Illuminate\\View\\View))
#7 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(749): Symfony\\Component\\HttpFoundation\\Response->__construct(Object(Illuminate\\View\\View), 200, Array)
#8 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(721): Illuminate\\Routing\\Router::toResponse(Object(Illuminate\\Http\\Request), Object(Illuminate\\View\\View))
#9 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(681): Illuminate\\Routing\\Router->prepareResponse(Object(Illuminate\\Http\\Request), Object(Illuminate\\View\\View))
#10 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(130): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#11 E:\\wwwroot\\object\\vendor\\silber\\page-cache\\src\\Middleware\\CacheResponse.php(38): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#12 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(171): Silber\\PageCache\\Middleware\\CacheResponse->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#13 E:\\wwwroot\\object\\app\\Http\\Middleware\\CheckStoreStatus.php(37): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#14 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(171): App\\Http\\Middleware\\CheckStoreStatus->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#15 E:\\wwwroot\\object\\app\\Http\\Middleware\\Statistics.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#16 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(171): App\\Http\\Middleware\\Statistics->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#17 E:\\wwwroot\\object\\app\\Http\\Middleware\\PasswordProtected.php(66): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#18 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(171): App\\Http\\Middleware\\PasswordProtected->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#19 E:\\wwwroot\\object\\app\\Http\\Middleware\\CurrentTheme.php(20): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#20 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(171): App\\Http\\Middleware\\CurrentTheme->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#21 E:\\wwwroot\\object\\app\\Http\\Middleware\\ConfigTheme.php(101): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#22 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(171): App\\Http\\Middleware\\ConfigTheme->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#23 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Middleware\\SubstituteBindings.php(41): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#24 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(171): Illuminate\\Routing\\Middleware\\SubstituteBindings->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#25 E:\\wwwroot\\object\\app\\Http\\Middleware\\SwitchDomain.php(54): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#26 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(171): App\\Http\\Middleware\\SwitchDomain->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#27 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken.php(78): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#28 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(171): Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#29 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\View\\Middleware\\ShareErrorsFromSession.php(49): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#30 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(171): Illuminate\\View\\Middleware\\ShareErrorsFromSession->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#31 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Session\\Middleware\\StartSession.php(56): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#32 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(171): Illuminate\\Session\\Middleware\\StartSession->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#33 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse.php(37): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#34 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(171): Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#35 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Cookie\\Middleware\\EncryptCookies.php(67): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#36 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(171): Illuminate\\Cookie\\Middleware\\EncryptCookies->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#37 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(105): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#38 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(683): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#39 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(658): Illuminate\\Routing\\Router->runRouteWithinStack(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request))
#40 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(624): Illuminate\\Routing\\Router->runRoute(Object(Illuminate\\Http\\Request), Object(Illuminate\\Routing\\Route))
#41 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(613): Illuminate\\Routing\\Router->dispatchToRoute(Object(Illuminate\\Http\\Request))
#42 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(170): Illuminate\\Routing\\Router->dispatch(Object(Illuminate\\Http\\Request))
#43 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(130): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}(Object(Illuminate\\Http\\Request))
#44 E:\\wwwroot\\object\\vendor\\barryvdh\\laravel-debugbar\\src\\Middleware\\InjectDebugbar.php(67): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#45 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(171): Barryvdh\\Debugbar\\Middleware\\InjectDebugbar->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#46 E:\\wwwroot\\object\\app\\Http\\Middleware\\ChangeAppUrlMiddleware.php(23): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#47 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(171): App\\Http\\Middleware\\ChangeAppUrlMiddleware->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#48 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#49 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(171): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#50 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#51 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(171): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#52 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#53 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(171): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#54 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode.php(63): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#55 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(171): Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#56 E:\\wwwroot\\object\\vendor\\fideloper\\proxy\\src\\TrustProxies.php(57): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#57 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(171): Fideloper\\Proxy\\TrustProxies->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#58 E:\\wwwroot\\object\\vendor\\dingo\\api\\src\\Http\\Middleware\\Request.php(111): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#59 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(171): Dingo\\Api\\Http\\Middleware\\Request->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#60 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(105): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#61 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(145): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#62 E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(110): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))
#63 E:\\wwwroot\\object\\public\\index.php(57): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))
#64 {main}



2、安装 Laravel Mix,执行命令:yarn install 来安装当前项目的 npm 依赖包


PS E:\wwwroot\object> yarn install
yarn install v1.22.15
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@2.3.2: The platform "win32" is incompatible with this module.
info "fsevents@2.3.2" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...


3、运行 Mix 任务,执行命令:npm run dev


PS E:\wwwroot\object> npm run dev

> dev
> npm run development


> development
> mix


● Mix █████████████████████████ emitting (98%)
 after emit





   Laravel Mix v6.0.39


✔ Compiled Successfully in 541488ms


4、刷新页面,不再报错。如图2
刷新页面,不再报错

图2

]]>
https://www.shuijingwanwq.com/2022/03/10/6109/feed/ 0
在 Laravel 8 中参考 igaster / laravel-theme 示例实现 https://www.shuijingwanwq.com/2022/01/25/5811/ https://www.shuijingwanwq.com/2022/01/25/5811/#respond Tue, 25 Jan 2022 01:25:18 +0000 https://www.shuijingwanwq.com/?p=5811 浏览量: 69

1、在本地使用 Composer 来创建一个新的 Laravel 项目:laravel-theme-demo。


PS E:\wwwroot> composer create-project laravel/laravel laravel-theme-demo
Creating a "laravel/laravel" project at "./laravel-theme-demo"
Installing laravel/laravel (v8.6.10)
  - Installing laravel/laravel (v8.6.10): Extracting archive
Created project in E:\wwwroot\laravel-theme-demo
> @php -r "file_exists('.env') || copy('.env.example', '.env');"
Loading composer repositories with package information
Updating dependencies
Lock file operations: 110 installs, 0 updates, 0 removals


2、igaster / laravel-theme 是一个 Laravel 包,增加了对管理主题的基本支持。它允许您在单独的文件夹中构建视图和资产,并支持主题扩展。执行命令:composer require “igaster/laravel-theme”,以安装 igaster/laravel-theme。


PS E:\wwwroot\laravel-theme-demo> composer require "igaster/laravel-theme"
Using version ^2.0 for igaster/laravel-theme
./composer.json has been updated
Running composer update igaster/laravel-theme
Loading composer repositories with package information
Updating dependencies
Lock file operations: 1 install, 0 updates, 0 removals
  - Locking igaster/laravel-theme (v2.0.17)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Installing igaster/laravel-theme (v2.0.17): Extracting archive
1 package suggestions were added by new dependencies, use `composer suggest` to see details.
Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fruitcake/laravel-cors
Discovered Package: igaster/laravel-theme
Discovered Package: laravel/sail
Discovered Package: laravel/sanctum
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
77 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> @php artisan vendor:publish --tag=laravel-assets --ansi --force
No publishable resources for tag [laravel-assets].
Publishing complete.
PS E:\wwwroot\laravel-theme-demo>


3、安装 Laravel Mix,执行:yarn install,运行所有的 Mix 任务,执行:npm run dev。


PS E:\wwwroot\laravel-theme-demo> yarn install
yarn install v1.22.15
info No lockfile found.
[1/4] Resolving packages...
warning laravel-mix > node-libs-browser > url > querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
[2/4] Fetching packages...
info fsevents@2.3.2: The platform "win32" is incompatible with this module.
info "fsevents@2.3.2" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning " > laravel-mix@6.0.39" has unmet peer dependency "@babel/core@^7.15.8".
warning " > laravel-mix@6.0.39" has unmet peer dependency "@babel/plugin-proposal-object-rest-spread@^7.15.6".
warning " > laravel-mix@6.0.39" has unmet peer dependency "@babel/plugin-syntax-dynamic-import@^7.8.3".
warning " > laravel-mix@6.0.39" has unmet peer dependency "@babel/plugin-transform-runtime@^7.15.8".
warning " > laravel-mix@6.0.39" has unmet peer dependency "@babel/preset-env@^7.15.8".
warning " > laravel-mix@6.0.39" has unmet peer dependency "webpack@^5.60.0".
warning " > laravel-mix@6.0.39" has unmet peer dependency "webpack-cli@^4.9.1".
[4/4] Building fresh packages...
success Saved lockfile.
warning Your current version of Yarn is out of date. The latest version is "1.22.17", while you're on "1.22.15".
Done in 87.72s.
PS E:\wwwroot\laravel-theme-demo> npm run dev

> dev
> npm run development


> development
> mix


● Mix █████████████████████████ emitting (98%)
 after emit




● Mix █████████████████████████ done (99%) plugins
 WebpackBar:done
















✔ Mix
  Compiled successfully in 3.82s


































   Laravel Mix v6.0.39


✔ Compiled Successfully in 3717ms
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────┬─────────┐
│                                                                                                       File │ Size    │
├────────────────────────────────────────────────────────────────────────────────────────────────────────────┼─────────┤
│                                                                                                 /js/app.js │ 606 KiB │
│                                                                                                css/app.css │ 1 bytes │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────┴─────────┘

● Mix █████████████████████████ done (99%)
 plugins

webpack compiled successfully
PS E:\wwwroot\laravel-theme-demo>


4、将配置文件发布到您的应用程序


PS E:\wwwroot\laravel-theme-demo> php artisan vendor:publish --provider="Igaster\LaravelTheme\themeServiceProvider"
Copied File [\vendor\igaster\laravel-theme\src\Config\themes.php] To [\config\themes.php]
Publishing complete.


5、创建主题,执行命令:theme:create。生成目录结构,如法炮制,生成主题 t2。如图1

创建主题,执行命令:theme:create。生成目录结构,如法炮制,生成主题 t2

图1


PS E:\wwwroot\laravel-theme-demo> php artisan theme:create

 Give theme name::
 > t1

 Where will views be located? [t1]:
 >

 Where will assets be located? [t1]:
 >

 Extends an other theme? (yes/no) [no]:
 >

Summary:
- Theme name: t1
- Views Path: E:\wwwroot\laravel-theme-demo\resources\views/t1
- Asset Path: E:\wwwroot\laravel-theme-demo\public\t1
- Extends Theme: No

 Create Theme? (yes/no) [yes]:
 > yes
PS E:\wwwroot\laravel-theme-demo> php artisan theme:create

 Give theme name::
 > t2

 Where will views be located? [t2]:
 >

 Where will assets be located? [t2]:
 >

 Extends an other theme? (yes/no) [no]:
 >

Summary:
- Theme name: t2
- Views Path: E:\wwwroot\laravel-theme-demo\resources\views/t2
- Asset Path: E:\wwwroot\laravel-theme-demo\public\t2
- Extends Theme: No

 Create Theme? (yes/no) [yes]:
 > yes



6、打开首页:http://laravel-theme-demo.local/ ,默认的界面。如图2

打开首页:http://laravel-theme-demo.local/ ,默认的界面

图2

7、使用中间件设置主题,执行命令:php artisan make:middleware SetTheme


PS E:\wwwroot\laravel-theme-demo> php artisan make:middleware SetTheme
Middleware created successfully.


8、在 app\Http\Kernel.php 文件中注册你的中间件。 例如,如果您想将主题应用于所有路由,则应将其添加到 web 数组中。


    /**
     * The application's route middleware groups.
     *
     * @var array>
     */
    protected $middlewareGroups = [
        'web' => [
            // ...
            \App\Http\Middleware\SetTheme::class,
        ],
    ];


9、添加文件:public/images/test.gif、public/t1/images/test.gif、public/t2/images/test.gif,编辑主题文件:resources/views/welcome.blade.php、resources/views/welcome.blade.php、resources/views/welcome.blade.php,其内容完全一样

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
 
    <title>Laravel</title>
 
    <!-- Fonts -->
    <link href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700&display=swap" rel="stylesheet">
 
    <!-- Styles -->
    <style>
        /*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */html{line-height:1.15;-webkit-text-size-adjust:100%}body{margin:0}a{background-color:transparent}[hidden]{display:none}html{font-family:system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;line-height:1.5}*,:after,:before{box-sizing:border-box;border:0 solid #e2e8f0}a{color:inherit;text-decoration:inherit}svg,video{display:block;vertical-align:middle}video{max-width:100%;height:auto}.bg-white{--bg-opacity:1;background-color:#fff;background-color:rgba(255,255,255,var(--bg-opacity))}.bg-gray-100{--bg-opacity:1;background-color:#f7fafc;background-color:rgba(247,250,252,var(--bg-opacity))}.border-gray-200{--border-opacity:1;border-color:#edf2f7;border-color:rgba(237,242,247,var(--border-opacity))}.border-t{border-top-width:1px}.flex{display:flex}.grid{display:grid}.hidden{display:none}.items-center{align-items:center}.justify-center{justify-content:center}.font-semibold{font-weight:600}.h-5{height:1.25rem}.h-8{height:2rem}.h-16{height:4rem}.text-sm{font-size:.875rem}.text-lg{font-size:1.125rem}.leading-7{line-height:1.75rem}.mx-auto{margin-left:auto;margin-right:auto}.ml-1{margin-left:.25rem}.mt-2{margin-top:.5rem}.mr-2{margin-right:.5rem}.ml-2{margin-left:.5rem}.mt-4{margin-top:1rem}.ml-4{margin-left:1rem}.mt-8{margin-top:2rem}.ml-12{margin-left:3rem}.-mt-px{margin-top:-1px}.max-w-6xl{max-width:72rem}.min-h-screen{min-height:100vh}.overflow-hidden{overflow:hidden}.p-6{padding:1.5rem}.py-4{padding-top:1rem;padding-bottom:1rem}.px-6{padding-left:1.5rem;padding-right:1.5rem}.pt-8{padding-top:2rem}.fixed{position:fixed}.relative{position:relative}.top-0{top:0}.right-0{right:0}.shadow{box-shadow:0 1px 3px 0 rgba(0,0,0,.1),0 1px 2px 0 rgba(0,0,0,.06)}.text-center{text-align:center}.text-gray-200{--text-opacity:1;color:#edf2f7;color:rgba(237,242,247,var(--text-opacity))}.text-gray-300{--text-opacity:1;color:#e2e8f0;color:rgba(226,232,240,var(--text-opacity))}.text-gray-400{--text-opacity:1;color:#cbd5e0;color:rgba(203,213,224,var(--text-opacity))}.text-gray-500{--text-opacity:1;color:#a0aec0;color:rgba(160,174,192,var(--text-opacity))}.text-gray-600{--text-opacity:1;color:#718096;color:rgba(113,128,150,var(--text-opacity))}.text-gray-700{--text-opacity:1;color:#4a5568;color:rgba(74,85,104,var(--text-opacity))}.text-gray-900{--text-opacity:1;color:#1a202c;color:rgba(26,32,44,var(--text-opacity))}.underline{text-decoration:underline}.antialiased{-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.w-5{width:1.25rem}.w-8{width:2rem}.w-auto{width:auto}.grid-cols-1{grid-template-columns:repeat(1,minmax(0,1fr))}@media (min-width:640px){.sm\:rounded-lg{border-radius:.5rem}.sm\:block{display:block}.sm\:items-center{align-items:center}.sm\:justify-start{justify-content:flex-start}.sm\:justify-between{justify-content:space-between}.sm\:h-20{height:5rem}.sm\:ml-0{margin-left:0}.sm\:px-6{padding-left:1.5rem;padding-right:1.5rem}.sm\:pt-0{padding-top:0}.sm\:text-left{text-align:left}.sm\:text-right{text-align:right}}@media (min-width:768px){.md\:border-t-0{border-top-width:0}.md\:border-l{border-left-width:1px}.md\:grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}}@media (min-width:1024px){.lg\:px-8{padding-left:2rem;padding-right:2rem}}@media (prefers-color-scheme:dark){.dark\:bg-gray-800{--bg-opacity:1;background-color:#2d3748;background-color:rgba(45,55,72,var(--bg-opacity))}.dark\:bg-gray-900{--bg-opacity:1;background-color:#1a202c;background-color:rgba(26,32,44,var(--bg-opacity))}.dark\:border-gray-700{--border-opacity:1;border-color:#4a5568;border-color:rgba(74,85,104,var(--border-opacity))}.dark\:text-white{--text-opacity:1;color:#fff;color:rgba(255,255,255,var(--text-opacity))}.dark\:text-gray-400{--text-opacity:1;color:#cbd5e0;color:rgba(203,213,224,var(--text-opacity))}.dark\:text-gray-500{--tw-text-opacity:1;color:#6b7280;color:rgba(107,114,128,var(--tw-text-opacity))}}
    </style>
 
    <style>
        body {
            font-family: 'Nunito', sans-serif;
        }
    </style>
</head>
<body class="antialiased">
<div class="relative flex items-top justify-center min-h-screen bg-gray-100 dark:bg-gray-900 sm:items-center py-4 sm:pt-0">
    @if (Route::has('login'))
        <div class="hidden fixed top-0 right-0 px-6 py-4 sm:block">
            @auth
                <a href="{{ url('/home') }}" class="text-sm text-gray-700 dark:text-gray-500 underline">Home</a>
            @else
                <a href="{{ route('login') }}" class="text-sm text-gray-700 dark:text-gray-500 underline">Log in</a>
 
                @if (Route::has('register'))
                    <a href="{{ route('register') }}" class="ml-4 text-sm text-gray-700 dark:text-gray-500 underline">Register</a>
                @endif
            @endauth
        </div>
    @endif
 
    <div class="max-w-6xl mx-auto sm:px-6 lg:px-8">
        <div class="flex justify-center pt-8 sm:justify-start sm:pt-0">
            This is the "{{Theme::get()}}" theme.
        </div>
        <div class="flex justify-center pt-8 sm:justify-start sm:pt-0">
            <img src={{Theme::url('images/test.gif')}}>
        </div>
 
    </div>
</div>
</body>
</html>
 
 

10、打开首页,主题名为空。如图3

打开首页,主题名为空

图3

11、编辑 app/Http/Middleware/SetTheme.php,设置主题为 t1,打开首页,主题名为 t1。如图4

编辑 app/Http/Middleware/SetTheme.php,设置主题为 t1,打开首页,主题名为 t1

图4

<?php
 
namespace App\Http\Middleware;
 
use Closure;
use Illuminate\Http\Request;
 
class SetTheme
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse)  $next
     * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
     */
    public function handle(Request $request, Closure $next)
    {
        $themeName = "t1";
        if(\Theme::exists($themeName)){
            \Theme::set($themeName);
        }
 
        return $next($request);
    }
}

12、编辑 app/Http/Middleware/SetTheme.php,设置主题为 t2,打开首页,主题名为 t2。如图5

编辑 app/Http/Middleware/SetTheme.php,设置主题为 t2,打开首页,主题名为 t2

图5

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class SetTheme
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse)  $next
     * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
     */
    public function handle(Request $request, Closure $next)
    {
        $themeName = "t2";
        if(\Theme::exists($themeName)){
            \Theme::set($themeName);
        }

        return $next($request);
    }
}
]]>
https://www.shuijingwanwq.com/2022/01/25/5811/feed/ 0