【问题标题】:Yocto - NodeJS minify assetsYocto - NodeJS 缩小资产
【发布时间】:2016-12-23 02:22:33
【问题描述】:

我想缩小在节点 js 上运行的项目的资产。我不想直接在目标上缩小,因为我们使用的 ARM 处理器没有足够的能力在启动时的合理时间内缩小所有资产。相反,我想在构建主机(Yocto)上启动缩小过程。我在网上搜索过有关此过程的任何帮助,但没有。

理想情况下,我想使用 node-minify 之类的东西,我可以在 Yocto 的 do_install 任务中的构建机器的 js 文件中运行它。

我首先在 (meta-nodejs/issues/62) 上寻求帮助,但没有得到帮助。因此,我现在在这里尝试,因为我们很匆忙,我真的不知道如何实现这一目标。

这是一个基本的食谱和我的问题:

SRC_URI = "svn://URL_TO_THE_TARGET_PROJECT \
    file://host-minify-asset-script.js"

DEPENDS = "nodejs-native "
RDEPENDS_${PN} = "nodejs "

inherit npm npm-install

do_install() {

    # This build/install dependency for target ?
    oe_runnpm install
    oe_runnpm prune --production

    # Is it the proper way to install node-minify on the host like this ?
    oe_runnpm_native install https://github.com/srod/node-minify/tarball/2.0.2

    # Now, how can I run natively my script (host-minify-asset-script.js) 
    # to minify the assets present in the work folder of the recipe ?
}    

最好的问候,

【问题讨论】:

    标签: node.js minify yocto


    【解决方案1】:

    您可以使用uglify 来缩小您的节点源。

    npm install -g uglify # install uglify
    
    rm -rf ./minified # remove existing minified directory if it exists
    
    # minify each .js file in the current directory and place the output in ./minified
    find . -name "*.js" | xargs -I % sh -c 'mkdir -p ./minified/$(dirname %); uglify -s % -o ./minified/%'
    

    【讨论】:

    • 很好的解决方案,非常感谢。我真的需要全局安装 uglify "-g" 吗?我很好奇,如果我打电话给node host-minify-asset-script.js,它会起作用吗?这个过程会在构建机器上运行吗?
    • 您不需要全局安装它。我不明白为什么你不能在构建机器上缩小并将缩小的文件推送到生产机器。
    • 我的问题问错了。在 do_install() 任务中调用node host-minify-asset-script.js 将在构建机器上运行吗?而且,即使构建机器上没有安装节点 js,构建机器是否也会具有运行节点 js 所需的依赖项?根据我在 github 上的 imyller 提出的最初问题,主机已经配置为能够通过 nodejs-native 运行节点。我明白了吗?
    • 我真的不确定。我不熟悉你的设置或 yocto。
    • do_install() 中这样做可以工作oe_runnpm_native install uglify 跟随find . -name "*.js" -exec uglifyjs -o {} {} \;
    猜你喜欢
    • 2016-05-20
    • 2016-01-04
    • 1970-01-01
    • 2012-03-29
    • 2021-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-13
    相关资源
    最近更新 更多