简体   繁体   English

我如何使用 gulp-clean-css 缩小我的 css?

[英]How can i minify my css with gulp-clean-css?

I have a problem with gulp-clean-css in my gulpfile.babel.js file我的 gulpfile.babel.js 文件中的 gulp-clean-css 有问题

package.json包.json

{
  "name": "project",
  "version": "1.0.0",
  "scripts": {
    "test": ""
  },
  "devDependencies": {
    "@babel/core": "^7.8.3",
    "@babel/preset-env": "^7.8.3",
    "@babel/register": "^7.8.3",
    "autoprefixer": "^9.7.3",
    "babel-loader": "^8.0.6",
    "browser-sync": "^2.26.7",
    "del": "^5.1.0",
    "dotenv": "^6.0.0",
    "gulp": "^4.0.0",
    "gulp-clean-css": "^4.2.0",
    "gulp-if": "^3.0.0",
    "gulp-imagemin": "^6.2.0",
    "gulp-postcss": "^8.0.0",
    "gulp-replace": "^1.0.0",
    "gulp-sass": "^4.0.2",
    "gulp-sourcemaps": "^2.6.5",
    "gulp-zip": "^5.0.1",
    "vinyl-named": "^1.1.0",
    "webpack-stream": "^5.2.1",
    "yargs": "^13.3.0"
  }
}

babelrc巴贝尔

{
    "presets": [ "@babel/preset-env" ]
}

gulfile.babel.js gulfile.babel.js

import { themeLocation } from './settings';
import gulp from 'gulp';
import yargs from 'yargs';

//styles
import sass from 'gulp-sass';
import cleanCSS from 'gulp-clean-css';
import gulpif from 'gulp-if';
import sourcemaps from 'gulp-sourcemaps';


//variables
config();
const PRODUCTION = yargs.argv.prod;


//STYLES
export const styles = () => {
    return gulp.src(`src/scss/bundle.scss`)
        .pipe(gulpif(!PRODUCTION, sourcemaps.init()))
        .pipe(sass().on('error', sass.logError))
        .pipe(gulpif(PRODUCTION, cleanCSS({compatibility:'ie8'})))
        .pipe(gulpif(!PRODUCTION, sourcemaps.write()))
        .pipe(gulp.dest(`${themeLocation}/css`))
}

I would like to minify my css file on production, but it doesn't work.我想在生产环境中缩小我的 css 文件,但它不起作用。 In my gulpfile file, I only see information:在我的 gulpfile 文件中,我只看到信息:

Could not find a declaration file for module 'gulp-clean-css'. './node_modules/gulp-clean-css/index.js' implicitly has an 'any' type.
  Try `npm install @types/gulp-clean-css` if it exists or add a new declaration (.d.ts) file containing `declare module 'gulp-clean-css';`

I tried to install @types/gulp-clean-css but I got only some errors.我尝试安装 @types/gulp-clean-css 但我只遇到了一些错误。

How can I solve my problem?我该如何解决我的问题? Thanks!谢谢!

The package you need is: gulp-clean-css.你需要的包是:gulp-clean-css。 Try with npm install --save-dev gulp-clean-css .尝试使用npm install --save-dev gulp-clean-css

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM