• laravel vue tailwind normalize


    下载laravel最新7.x

    composer create-project --prefer-dist laravel/laravle blog 7.x-dev

     cd blog

    valet link blog

    valet links 

    blog.test

    测试通过后,开始安装tailwind

    npm i

    npm i tailwindcss autoprefixer postcss@7

    都是最新版应该也没有什么问题

    在根目录下添加

    tailwind.js

    1. module.exports = {
    2. content: [
    3. "./resources/**/*.blade.php",
    4. "./resources/**/*.js",
    5. "./resources/**/*.vue",
    6. ],
    7. darkMode: "class",
    8. theme: {
    9. extend: {},
    10. },
    11. plugins: [],
    12. };

    在webpack.mix.js 改为

    1. mix.js("resources/js/app.js", "public/js")
    2. .sass("resources/sass/app.scss", "public/css")
    3. .options({
    4. processCssUrls: false,
    5. postCss: [tailwindcss("./tailwind.js")],
    6. });

    在res / sass /app.scss 中添加,vscode 的报错不用管,只要打包成就没什么问题,如果你是强迫症直接网上查找 或者  用phpstorm 

    1. @tailwind base;
    2. @tailwind components;
    3. @tailwind utilities;

    在welcome.blade.php中添加,测试代码dfdf

    1. <link rel="stylesheet" href="{{ asset('css/app.css') }}">
    2. @stack('stylesheets')

    在终端输入命令

    npm run prod

    这个时候刷新页面,是有出现文字背景是红色的,加载成功,

    这个时候你会发现浏览器的css都是报红,不要慌,

    在package.json 中添加

    1. "browserslist": [
    2. "> 1%",
    3. "last 2 versions"
    4. ]

    再运行 npm run prod

    问题解决,接着在测试添加vue后会出现的问题

    添加vue 

     composer require laravel/ui:^2.4

    php artisan ui vue

    npm install  初始化

    打包要重新写

    1. const mix = require("laravel-mix");
    2. const fs = require("fs");
    3. const Path = require("path");
    4. const { argv } = require("process");
    5. const tailwindcss = require("tailwindcss");
    6. /*
    7. |--------------------------------------------------------------------------
    8. | Mix Asset Management
    9. |--------------------------------------------------------------------------
    10. |
    11. | Mix provides a clean, fluent API for defining some Webpack build steps
    12. | for your Laravel application. By default, we are compiling the Sass
    13. | file for the application as well as bundling up all the JS files.
    14. |
    15. */
    16. // 模块参数名称
    17. const MODULE_ARG_NAME = "pages";
    18. const FILE_TYPE = {
    19. SASS: "sass",
    20. JS: "js",
    21. };
    22. const SASS_PATH_PREFIX = "resources/sass/views";
    23. const JS_PATH_PREFIX = "resources/js/views";
    24. const CSS_DEST_PATH = "public/css";
    25. const JS_DEST_PATH = "public/js";
    26. function resolve(dir) {
    27. return Path.resolve(process.cwd(), dir);
    28. }
    29. const getCompilerModules = () => {
    30. let modules = [];
    31. const lastArg = argv[argv.length - 1];
    32. if (lastArg.indexOf(MODULE_ARG_NAME) > -1) {
    33. const modulesStr = lastArg.split("=")[1];
    34. modules = modulesStr.split(",");
    35. }
    36. return modules;
    37. };
    38. const complierFile = (
    39. fileType = FILE_TYPE.SASS,
    40. pathPerfix = SASS_PATH_PREFIX,
    41. destPath = CSS_DEST_PATH
    42. ) => {
    43. if (!mix[fileType] || !mix[fileType] instanceof Function) {
    44. throw new Error("文件类型非法!");
    45. }
    46. const _fn = mix[fileType];
    47. const _findNeedComfilerFile = (dirPath, subDirPath) => {
    48. const files = fs.readdirSync(dirPath);
    49. files.forEach((item) => {
    50. const fPath = Path.join(dirPath, item);
    51. const stat = fs.statSync(fPath);
    52. if (stat.isDirectory()) {
    53. _findNeedComfilerFile(fPath, item);
    54. }
    55. if (stat.isFile()) {
    56. let _targetDestPath = destPath;
    57. if (subDirPath) {
    58. _targetDestPath = `${_targetDestPath}/${subDirPath}`;
    59. }
    60. _fn(fPath, _targetDestPath);
    61. }
    62. });
    63. };
    64. try {
    65. _findNeedComfilerFile(pathPerfix);
    66. } catch (e) {
    67. // throw new Error(e);
    68. console.error(e);
    69. }
    70. };
    71. const gloableCompier = () => {
    72. // 编译SASS
    73. complierFile(FILE_TYPE.CSS, SASS_PATH_PREFIX, `${CSS_DEST_PATH}/views`);
    74. // 编译JS
    75. complierFile(FILE_TYPE.JS, JS_PATH_PREFIX, `${JS_DEST_PATH}/views`);
    76. };
    77. const init = () => {
    78. mix.webpackConfig({
    79. resolve: {
    80. alias: {
    81. "@": resolve("resources"),
    82. "@views": resolve("resources/views"),
    83. "@js": resolve("resources/js"),
    84. "@sass": resolve("resources/sass"),
    85. $public: resolve("public"),
    86. },
    87. },
    88. });
    89. // mix.js("resources/js/app.js", "public/js").sass(
    90. // "resources/sass/app.scss",
    91. // "public/css"
    92. // );
    93. mix.js("resources/js/app.js", "public/js")
    94. .sass("resources/sass/app.scss", "public/css")
    95. .options({
    96. processCssUrls: false,
    97. postCss: [tailwindcss("./tailwind.js")],
    98. });
    99. const compilerModules = getCompilerModules();
    100. console.log(compilerModules);
    101. if (compilerModules.length) {
    102. // 按需编译
    103. for (const module of compilerModules) {
    104. const sassPath = `${SASS_PATH_PREFIX}/${module}`;
    105. const jsPath = `${JS_PATH_PREFIX}/${module}`;
    106. // 编译SASS
    107. complierFile(
    108. FILE_TYPE.CSS,
    109. sassPath,
    110. `${CSS_DEST_PATH}/views/${module}`
    111. );
    112. // 编译JS
    113. complierFile(
    114. FILE_TYPE.JS,
    115. jsPath,
    116. `${JS_DEST_PATH}/views/${module}`
    117. );
    118. }
    119. } else {
    120. // 全局编译
    121. gloableCompier();
    122. }
    123. if (mix.inProduction()) {
    124. mix.version();
    125. }
    126. mix.sourceMaps(false, "eval-source-map");
    127. };
    128. init();

    完成后显示没有问题,但是

    浏览器css 全部都报红,

    解决方案:

    1.直接将public /css / app.css 中修改 -webkit-text-size-adjust: none;  

    2.在res / sass / app.scss 中修导入 

    1. // @tailwind base;
    2. // @tailwind components;
    3. @tailwind utilities;
    4. // 如果你不需要它的初始,可以只有它的实例,那么,就没有 红色波浪线,

    关于laravel 的模版语言,直接套用就好

    layouts / app.blade.php

    1. html>
    2. <html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    3. <head>
    4. <meta charset="utf-8">
    5. <meta name="viewport" content="width=device-width, initial-scale=1">
    6. <title>
    7. @yield('page-title')
    8. title>
    9. <link rel="stylesheet" href="{{ asset('css/app.css') }}">
    10. @stack('stylesheets')
    11. head>
    12. <body>
    13. @yield('content')
    14. <script src="{{ asset('js/app.js')}}">script>
    15. @stack('scripts')
    16. body>
    17. html>

    接下来就直接继承就好 了

    1. @extends('layouts.app')
    2. @section('page-title', 'home index')
    3. @section('content')
    4. 'home-wrapper'>
    5. wo
    6. @{{test}}
    7. class=' text-blue-900'>this is goodspan>
    8. <span class=' bg-red-600'>thi is btspan>
    9. <span class=' text-blue-900'>this is xiaomingspan>
    10. div>
    11. @endsection
    12. @push('scripts')
    13. <script src="{{ asset('js/views/home/index.js') }}">
    14. @endpush
    15. @push('stylesheets')
    16. " href="{{ asset('css/views/home/index.css') }}">
    17. @endpush

     接下来就愉快的撸代码吧,如果出现其他问题可留言讨论

     这个时候看需要,导入一个组件库,我选择 antd

    npm i ant-design-vue@1.7.8

    复制 antd.min.js   antd.min.css 

    这个时候就 normalize 和 reset  的效果都有了,用 e-ui  也是一样的,

  • 相关阅读:
    #gStore-weekly | gStore源码解析(四):安全机制之黑白名单配置解析
    Tomcat下载安装配置
    Flink学习之旅:(四)Flink转换算子(Transformation)
    探寻JWT的本质:它是什么?它有什么作用?
    第2-4-8章 规则引擎Drools实战(1)-个人所得税计算器
    Eslint安装配置教程
    微前端无界机制浅析
    MetaGPT day02: MetaGPT Role源码分析
    【OpenCV】Chapter7.图像噪声与滤波器
    Java中ReentrantLock测试线程的安全
  • 原文地址:https://blog.csdn.net/qq_35886411/article/details/128132814