如何用 webpack.mix.js 编译纯 CSS

how to compile plain CSS with webpack.mix.js

我正在使用Laravel 8PHP框架,我需要编译JSCSS 文件在 localhost 上使用 node。当我尝试 运行 npm run dev 时,错误输出是:

$ npm run dev

> dev
> npm run development


> development
> mix

[webpack-cli] AssertionError [ERR_ASSERTION]: mix.combine() requires a full output file path as the second argument. Got C:\xampp\htdocs\project\public\css
    at Function.combine (C:\xampp\htdocs\project\node_modules\laravel-mix\src\Assert.js:54:9)
    at Combine.addTask (C:\xampp\htdocs\project\node_modules\laravel-mix\src\components\Combine.js:49:16)
    at Combine.register (C:\xampp\htdocs\project\node_modules\laravel-mix\src\components\Combine.js:29:14)
    at Object.components.<computed> [as styles] (C:\xampp\htdocs\project\node_modules\laravel-mix\src\components\ComponentRegistrar.js:163:49)
    at Object.<anonymous> (C:\xampp\htdocs\project\webpack.mix.js:17:5)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19) {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: false,
  expected: true,
  operator: '=='
}

我怎么看出来的,问题出在mix文件中,语法错误会不会是个问题?

代码如下

const mix = require('laravel-mix');

mix.js('resources/js/app.js', 'public/js')
    .js('resources/assets/js/bootstrap.js', 'public/js')
    .js('resources/assets/js/core.min.js', 'public/js')
    .js('resources/assets/js/script.js', 'public/js')
    .js('resources/assets/js/slider.js', 'public/js')
    .js('resources/assets/js/html5shiv.min.js', 'public/js')
    .js('resources/assets/js/jquery-3.6.0.min.js', 'public/js')
    .js('resources/assets/js/pointer-events.js', 'public/js');

mix.styles([
    'resources/assets/css/bootstrap.css',
    'resources/assets/css/bootstrap-grid.css',
    'resources/assets/css/bootstrap-utilities.css'
],'public/css');

mix.styles([
    'resources/assets/css/app.css',
    'resources/assets/css/util.css'
], 'public/css');

为此我使用 Laravel 7 Docs 因为我在 Laravel 8 文档

中没有找到任何内容

我没有使用 sassscss,因为源项目有 ~30000 css 行每个文件,我不知道如何转换它。

这是package.json文件

{
  "dependencies": {
    "bootstrap-icons": "^1.7.2",
    "cross-env": "^7.0.3",
    "laravel-mix": "^6.0.39"
  },
  "scripts": {
      "dev": "npm run development",
      "development": "mix",
      "watch": "mix watch",
      "watch-poll": "mix watch -- --watch-options-poll=1000",
      "hot": "mix watch --hot",
      "prod": "npm run production",
      "production": "mix --production"
  }
}

您必须将文件而不是文件夹作为第二个参数传递。所以:

    mix.styles([
        'resources/assets/css/bootstrap.css',
        'resources/assets/css/bootstrap-grid.css',
        'resources/assets/css/bootstrap-utilities.css'
    ],'public/css/bootstrap.css');
    
    mix.styles([
        'resources/assets/css/app.css',
        'resources/assets/css/util.css'
    ], 'public/css/app.css');