【问题标题】:copy file directory with node ncp and minify everything使用节点 ncp 复制文件目录并缩小所有内容
【发布时间】:2019-06-09 05:59:49
【问题描述】:

我想要一个 npm 脚本:

  1. 复制结构完整的目录及其子目录
  2. 压缩所有 html、css 和 js 文件

我有复制部分使用 ncp 和节点,

var ncp = require('ncp').ncp;
ncp.limit = 16;
const options = {
    clobber: true,  //overwrite dir
    stopOnErr: true
}
ncp('src', 'public', options, function(err) {
    if (err){return console.error(err);}
    console.log('copied with node!');
});

但是如何应用 uglify 或正则表达式之类的东西来缩小文件?我不想用 gulp,只用 node 和 npm 脚本。

【问题讨论】:

    标签: node.js npm uglifyjs npm-scripts


    【解决方案1】:

    想通了,我可以用 ncp 和 html-minifier 完成这一切。 html-minifier 似乎可以抓取 html、css 和 JS 文件。完美。

    在终端:

    npm install --save ncp
    npm install --save html-minifier
    

    在我的 npm 脚本中:

    "scripts": {
        "html": "html-minifier --input-dir ./public --output-dir ./public --collapse-whitespace --remove-comments",
        "copy": "ncp ./src ./public --stopOnErr && npm run html"
    

    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-20
      • 2010-11-17
      • 1970-01-01
      • 2015-12-07
      相关资源
      最近更新 更多