How to use the uglifycss.processString function in uglifycss

To help you get started, we’ve selected a few uglifycss examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github YMFE / ykit / src / modules / MinifyWorker.js View on Github external
}).join('');

                    response.error = extend(true, e, {
                        assetName: assetName,
                        errorSource: errorSource
                    });
                } else {
                    /* eslint-disable no-console */
                    console.error(e);
                    /* eslint-enable no-console */
                }
            }

        } else if (path.extname(assetName) === '.css') {
            const uglifycssOpts = buildOpts.uglifycss || {};
            minifiedCode = cssUglify.processString(content, uglifycssOpts);
        }

        if(minifiedCode) {
            fs.writeFileSync(path.resolve(cwd, assetName), minifiedCode, {encoding: 'utf8'});

            // 重新生成版本号, webpack 打的样式文件 hash 会根据所在目录不同而不同,造成 beta/prd 环境下版本号不一致
            if(assetName.indexOf(HASH_PLACEHOLDER) > -1) {
                const version = md5(minifiedCode).slice(0, 20); // 和 webpack hash 长度保持一致
                const nextName = assetName.replace(HASH_PLACEHOLDER, version);
                fs.renameSync(path.resolve(cwd, assetName), path.resolve(cwd, nextName));
                response.replacedAssets = [assetName, nextName];
            } else {
                response.replacedAssets = [assetName, assetName];
            }
        }
    }
github YMFE / ykit / lib / modules / MinifyWorker.js View on Github external
return codeLine = ('line: ' + (e.line + index) + '    ').grey + codeLine.red + '\n';
                    }).join('');

                    response.error = extend(true, e, {
                        assetName: assetName,
                        errorSource: errorSource
                    });
                } else {
                    /* eslint-disable no-console */
                    console.error(e);
                    /* eslint-enable no-console */
                }
            }
        } else if (path.extname(assetName) === '.css') {
            var uglifycssOpts = buildOpts.uglifycss || {};
            minifiedCode = cssUglify.processString(content, uglifycssOpts);
        }

        if (minifiedCode) {
            fs.writeFileSync(path.resolve(cwd, assetName), minifiedCode, { encoding: 'utf8' });

            // 重新生成版本号, webpack 打的样式文件 hash 会根据所在目录不同而不同,造成 beta/prd 环境下版本号不一致
            if (assetName.indexOf(HASH_PLACEHOLDER) > -1) {
                var version = md5(minifiedCode).slice(0, 20); // 和 webpack hash 长度保持一致
                var nextName = assetName.replace(HASH_PLACEHOLDER, version);
                fs.renameSync(path.resolve(cwd, assetName), path.resolve(cwd, nextName));
                response.replacedAssets = [assetName, nextName];
            } else {
                response.replacedAssets = [assetName, assetName];
            }
        }
    }
github weseek / growi / src / server / service / customize.js View on Github external
initCustomCss() {
    const uglifycss = require('uglifycss');

    const rawCss = this.configManager.getConfig('crowi', 'customize:css') || '';

    // uglify and store
    this.customCss = uglifycss.processString(rawCss);
  }
github joomla-projects / media-manager-improvement / build / build-modules-js / build-check.js View on Github external
const buildCheck = (options) => {
  let initTemplate = fs.readFileSync(`${srcPath}/template.html`, 'utf-8');
  let cssContent = fs.readFileSync(`${srcPath}/template.css`, 'utf-8');
  let jsContent = fs.readFileSync(`${srcPath}/template.js`, 'utf-8');

  cssContent = uglifyCss.processString(cssContent, { expandVars: false });
  jsContent = uglifyJs.minify(jsContent);

  Recurs(dir).then(
    (files) => {
      files.forEach((file) => {
        const languageStrings = ini.parse(fs.readFileSync(file, 'UTF-8'));

        // Build the variables into json for the unsupported page
        if (languageStrings.MIN_PHP_ERROR_LANGUAGE) {
          const name = file.replace('.ini', '').replace(/.+\//, '').replace(/.+\\/, '');
          unsupported += `"${name}":{"language":"${languageStrings.MIN_PHP_ERROR_LANGUAGE}","header":"${languageStrings.MIN_PHP_ERROR_HEADER}","text1":"${languageStrings.MIN_PHP_ERROR_TEXT}","help-url-text":"${languageStrings.MIN_PHP_ERROR_URL_TEXT}"},`;
        }

        // Build the variables into json for the unsupported page
        if (languageStrings.BUILD_INCOMPLETE_LANGUAGE) {
          const name = file.replace('.ini', '').replace(/.+\//, '').replace(/.+\\/, '');
github commercetools / merchant-center-application-kit / packages / mc-html-template / lib / html-styles / index.js View on Github external
const loadStyleAsString = fileName => {
  const content = fs.readFileSync(path.join(__dirname, fileName), {
    encoding: 'utf8',
  });
  if (process.env.NODE_ENV !== 'production') return content;

  // Minify styles for production usage
  return uglifycss.processString(content);
};
github YMFE / ykit / src / modules / minWorker.js View on Github external
if (isCliArgvCloseMangle || isBuildOptsCloseMangle) {
                willMangle = false;
            }

            try {
                let ast = jsParser.parse(content);
                ast = willMangle ? jsUglify.ast_mangle(ast, uglifyjsOpts.mangle) : ast;
                ast = uglifyjsOpts.squeeze ? jsUglify.ast_squeeze(ast, uglifyjsOpts.squeeze) : ast;
                minifiedCode = jsUglify.gen_code(ast, uglifyjsOpts.genCode);
            } catch(e) {
                response.error = extend(true, e, {assetName: assetName});
            }

        } else if (path.extname(assetName) === '.css') {
            const uglifycssOpts = buildOpts.uglifycss || {};
            minifiedCode = cssUglify.processString(content, uglifycssOpts);
        }

        if(minifiedCode) {
            fs.writeFileSync(path.resolve(cwd, assetName), minifiedCode, {encoding: 'utf8'});

            // 重新生成版本号, webpack 打的样式文件 hash 会根据所在目录不同而不同,造成 beta/prd 环境下版本号不一致
            if(assetName.indexOf(HASH_PLACEHOLDER) > -1) {
                const version = md5(minifiedCode).slice(0, 20); // 和 webpack hash 长度保持一致
                const nextName = assetName.replace(HASH_PLACEHOLDER, version);
                fs.renameSync(path.resolve(cwd, assetName), path.resolve(cwd, nextName));
                response.replacedAssets = [assetName, nextName];
            } else {
                response.replacedAssets = [assetName, assetName];
            }
        }
    }
github YMFE / ykit / lib / modules / minWorker.js View on Github external
var isBuildOptsCloseMangle = uglifyjsOpts.mangle === false;
            if (isCliArgvCloseMangle || isBuildOptsCloseMangle) {
                willMangle = false;
            }

            try {
                var ast = jsParser.parse(content);
                ast = willMangle ? jsUglify.ast_mangle(ast, uglifyjsOpts.mangle) : ast;
                ast = uglifyjsOpts.squeeze ? jsUglify.ast_squeeze(ast, uglifyjsOpts.squeeze) : ast;
                minifiedCode = jsUglify.gen_code(ast, uglifyjsOpts.genCode);
            } catch (e) {
                response.error = extend(true, e, { assetName: assetName });
            }
        } else if (path.extname(assetName) === '.css') {
            var uglifycssOpts = buildOpts.uglifycss || {};
            minifiedCode = cssUglify.processString(content, uglifycssOpts);
        }

        if (minifiedCode) {
            fs.writeFileSync(path.resolve(cwd, assetName), minifiedCode, { encoding: 'utf8' });

            // 重新生成版本号, webpack 打的样式文件 hash 会根据所在目录不同而不同,造成 beta/prd 环境下版本号不一致
            if (assetName.indexOf(HASH_PLACEHOLDER) > -1) {
                var version = md5(minifiedCode).slice(0, 20); // 和 webpack hash 长度保持一致
                var nextName = assetName.replace(HASH_PLACEHOLDER, version);
                fs.renameSync(path.resolve(cwd, assetName), path.resolve(cwd, nextName));
                response.replacedAssets = [assetName, nextName];
            } else {
                response.replacedAssets = [assetName, assetName];
            }
        }
    }
github xunuoi / gulpman / lib / inline.js View on Github external
isMinifyJs  = options && !!options.minifyJs,
        ignore      = options['ignore'] || 'ignore',
        basePath    = options['basePath'] || '',
        queryKey    = options['queryKey'] || '_gm_inline',
        queryRegx   = new RegExp('&*'+ queryKey +'[=|&]?', 'i'),
        code = content,
        tags;

    tags = content.match(/<[\s\S]*?<*\/*[\s\S]*?>/gi);

    if(tags && tags[0] && tags[0].indexOf(ignore) !== -1)
        return content;

    if('css' === type){
        if(!isMinifyCss) return content;
        code = uglifycss.processString(content, options);
    }
    else if('js' === type){
        if(!isMinifyJs) return content;

        /**
         * FIX BUGS FOR replace
         */
        // gmutil.alert('content: \n'+content)
        // gmutil.alert('opts: \n'+JSON.stringify(options))

        var pt = /(?=['"]?)([\w\/\-\?\&\=]*?\.js)(?=['"]?)/gm,
            item

        // 如果没有标记inline,那么不处理
        if((item = content.match(pt)) && (item = item[0])){
            if(!item.match(queryRegx)) return content
github xunuoi / gulpman / lib / inline.js View on Github external
if(!fs.existsSync(sourceFile)){
        gmutil.error('\n*Error: \n*Inline File Not Exist: '+sourceFile+'\n')

        return match;
    }

    content = getFileContent(sourceFile);

    // add for gulpman store save
    store.save(sourceFile, _file.path)


    if('css' === type){
        if(!isMinifyCss)
            return joint('style', content);
        code = uglifycss.processString(content, options);
        code = joint('style', code);
    }
    else if('js' === type){

        if(!isMinifyJs)
            return joint('script', content);
        code = jsmin(content, options).code.replace(/\n*\t*/gi, '');
        code = joint('script', code);
    }

    return code;

};
github DefinitelyTyped / DefinitelyTyped / uglifycss / uglifycss-tests.ts View on Github external
import * as UglifyCSS from 'uglifycss';

var test1 = UglifyCSS.processString('some css string');

var test2 = UglifyCSS.processString('some css string', {
    maxLineLen: 0,
    expandVars: true,
    uglyComments: true,
    cuteComments: true
});

var test3 = UglifyCSS.processFiles(['/path/to/file']);

var test4 = UglifyCSS.processFiles(['/path/to/file'], {
    maxLineLen: 0,
    cuteComments: true
});

uglifycss

Port of YUI CSS Compressor to NodeJS

MIT
Latest version published 7 years ago

Package Health Score

50 / 100
Full package analysis

Popular uglifycss functions