我想在我的Stylus文件中使用ID选择器。问题 - 选择器的名称应动态设置。
具体来说,我想从node.js模块的package.json文件中检索ID选择器的名称。我使用webpack作为构建工具运行良好。
示例:
的package.json
{
"name":"mymodule",
}
webpack.config.json
var modulname = require('./package.json').name
module.exports = {
stylus: {
use: [ ]
}
}
app.styl
#{dynamicselctor}
color: red
display: flex
app.css
#modulname
color: red
display: flex
如何将{dynamicselctor}
中的app.styl
部分替换为var modulename
中webpack.config.json
所需的package.json
的值,以便app.css
#include <Elementary.h>
// gcc -g main.c -o main `pkg-config --cflags --libs elementary`
// @url https://www.enlightenment.org/docs/efl/start
Evas_Object *win;
int curIndex = 0;
int numposters = 1022;
int showXImages = 4;
int showYImages = 2;
int widthImage = 200;
int heightImage = 300;
int padding = 20;
Evas_Object* curImages[8] = {NULL}; // showXImages * showYImages
static void getImage(Evas_Object *win) {
int x, y;
for (y=0; y<showYImages; ++y) {
for (x=0; x<showXImages; ++x) {
// Destroy previous one
int index = y*showXImages + x;
if (curImages[index] != NULL) {
evas_object_del(curImages[index]);
curImages[index] = NULL;
}
// Create new image url
char result[1024] = "";
sprintf(result, "http://unsplash.it/200/300?image=%d", curIndex + index);
// Add new image
Evas_Object* img = elm_image_add(win);
elm_image_file_set(img, result, NULL);
evas_object_move(img, x * (widthImage + padding), y * (heightImage + padding));
evas_object_resize(img, widthImage, heightImage);
evas_object_show(img);
// Set image
curImages[index] = img;
}
}
}
Eina_Bool sCheckCallback(void *data) {
// Increase index
curIndex = curIndex + (showYImages*showXImages);
curIndex = curIndex % numposters;
// Get and set new images
getImage(win);
return ECORE_CALLBACK_RENEW;
}
EAPI_MAIN int elm_main(int argc, char **argv) {
// Create window
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
win = elm_win_util_standard_add("Main", "Hello, World!");
elm_win_autodel_set(win, EINA_TRUE);
evas_object_resize(win, 1280, 720);
evas_object_show(win);
// Add callback
Ecore_Timer* timer = ecore_timer_add(1.0f, sCheckCallback, NULL);
elm_run();
return 0;
}
ELM_MAIN()
如图所示呈现?
答案 0 :(得分:0)
您可以在webpack配置中使用define
stylus-loader选项:
var modulname = require('./package.json').name
module.exports = {
stylus: {
define: {
dynamicselctor: modulname
}
}
}