为具有静态路径的生产添加前缀资产 [英] prefix assets for production with static path

查看:105
本文介绍了为具有静态路径的生产添加前缀资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我在样式表,javascript等中调用的资产(例如/assets/image.png)

for assets such as /assets/image.png, that I call in stylesheets, javascript etc...

我需要为服务器添加前缀或前缀

I need to prefix or prepend a path to server.

,因此/assets/image.png变为/static/ember/memory/dist/assets/image.png进行生产。

so that /assets/image.png becomes /static/ember/memory/dist/assets/image.png for production.

用作以下位置: http: //domain.com/static/ember/memory/dist/assets/image.png

在编译时,我需要传递并使用STATIC_PATH变量/

i need to pass and use a STATIC_PATH variable when compiled/built for production that will be prefixed, or compile it so that it does it automatically.

我已经检查了ember-cli文档以进行资产编译:

I have checked ember-cli docs for assets compilation:

var app = new EmberApp({
指纹:{
前置:'/ static / ember / memory / dist /'
}
} );

var app = new EmberApp({ fingerprint: { prepend: '/static/ember/memory/dist/' } });

但是,这不起作用,因为在调用资产的位置生产不会改变,除非它实际修改了

however, this doesn't work as where the assets are being called the path doesn't change in production, unless it actually modified the path where it's called.

例如,在styles.css中,如果我在某个地方调用/assets/image.png,则需要在添加STATIC_PATH + /assets/image.png时添加前缀

for example in styles.css if I call /assets/image.png somewhere, I need to prefix this with STATIC_PATH + /assets/image.png when in production.

STATIC_PATH类似于:

the STATIC_PATH will look something like:

/ static / ember / memory / dist /

/static/ember/memory/dist/

我可以手动将其添加到开发中的生产中,但随后无法在开发中进行测试。

I can add this manually for production in development, but then cannot test in development.

感谢您的任何答复。

推荐答案

您可以在<$ c中传递 prepend 选项$ c> ember-cli-build 文件,则必须排除不需要该路径的资产:

You can pass a prepend option in the ember-cli-build file, you will have to exclude the assets that don't need the path:

var app = new EmberApp({
   fingerprint: {
     exclude: ['excludedAssets/'],
     prepend: '/static/ember/memory/dist/'
   }
});

有关更多信息,请查看资产编译

For more information check out asset compilation

这篇关于为具有静态路径的生产添加前缀资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆