【问题标题】:Build Failure for Django-Oscar 3.1.6 Frobshop AssetsDjango-Oscar 3.1.6 Frobshop 资产的构建失败
【发布时间】:2021-02-19 16:39:56
【问题描述】:

我正在为django-oscar 处理Frobshop sample project

django-oscar 文档在自定义资产方面相当简洁,而the unresolved bug I reported for manage.py oscar_fork_statics 只会增加混乱。这是我(失败的)手动复制文件和编译资产的尝试。

我在/var/work/django/frobshop/中安装了Frobshop。

我在/var/work/django/oscar/ 中为django-oscar 安装了一个虚拟环境,因此可以在该目录中找到分发的资产目录lib/python3.8/site-packages/oscar/static/oscar/。该目录中的README.rst 文件表示When building your own project, it is not recommended to use these files straight from the package. Rather, you should take a static copy of the ``oscar/static/oscar`` folder and commit it into your project.

看起来很简单,所以我输入了:

$ cd /var/work/django
$ mkdir frobshop/frobshop/static/
$ cp -a lib/python3.8/site-packages/oscar/static/oscar/* frobshop/frobshop/static/

接下来,README.rst 说:You can compile the static assets from the root of the project using a make target: make assets

$ make assets
make: *** No rule to make target 'assets'.  Stop.

嗯,那没用。 https://github.com/django-oscar/django-oscar/blob/master/Makefile 是正确的Makefile,我想知道它应该在哪里?

$ wget -O frobshop/static/Makefile \
  https://raw.githubusercontent.com/django-oscar/django-oscar/master/Makefile

运行make assets 给了我一条错误消息,抱怨缺少package.json,所以我也从django-oscar 获取了它。

$ wget -O frobshop/static/package.json \
  https://raw.githubusercontent.com/django-oscar/django-oscar/master/package.json

看来我应该从新的frobshop/frobshop/static/ 目录运行make

$ (cd frobshop/static/; make assets)

安装了许多文件,然后最终出现此消息:

found 3 vulnerabilities (2 moderate, 1 high)
  run `npm audit fix` to fix them, or `npm audit` for details
npm run build

> django-oscar@3.0.0 build /var/work/django/frobshopCamille/frobshop/static
> gulp copy && gulp scss

[11:32:39] No gulpfile found
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! django-oscar@3.0.0 build: `gulp copy && gulp scss`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the django-oscar@3.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/mslinn/.npm/_logs/2021-02-19T16_32_39_097Z-debug.log
make: *** [Makefile:29: assets] Error 1

我不知道如何处理该错误。我在 django-oscar 中看到一个名为 gulpfile.jsdirectory。我也应该把它复制到某个地方吗?

README.rst接着说:If you make changes to Oscar's assets in development, you can run ``npm run watch`` to automatically watch and compile changes to them.

$ (cd frobshop/static/; npm run watch)

当然,这只会产生与以前相同的错误消息。

【问题讨论】:

    标签: gulp django-oscar django-assets


    【解决方案1】:

    src/oscar/static_src/oscar/README.rst 中提到的编译资产(使用运行 Gulp 任务的make assets)的说明实际上仅适用于开发/打包django-oscar 本身。我们将努力使文档更加清晰。

    对于基于django-oscar的项目/商店,只需运行./manage.py collectstatic,即可使用Oscar的静态文件,无需修改,这里提到:https://django-oscar.readthedocs.io/en/latest/howto/how_to_handle_statics.html#customising-statics

    要修改和覆盖 Oscar 的静态文件,您还需要运行 ./manage.py oscar_fork_statics,将 Oscar 的静态文件复制到您的项目中。该命令当前已损坏,但我们正在修复:https://github.com/django-oscar/django-oscar/pull/3657

    【讨论】:

    • 我今天如何手动将 Oscar 的静态文件复制并覆盖到我的项目中,而不尝试使用损坏的 ./manage.py oscar_fork_statics
    • 当我对 SCSS 文件进行更改时,即使重新加载,它也不会反映在呈现的页面上。一些框架(如 Jekyll)会自动重建 SCSS。如何使 SCSS 的更改可见?
    • @MikeSlinn 要手动复制 Oscar 静态文件,只需:$ cp -a lib/python3.8/site-packages/oscar/static/* frobshop/static/。然后将/var/work/django/frobshop/static/ 添加到您的STATICFILES_DIRS settingoscar_fork_statics 的修复程序现在位于 master 分支中:github.com/django-oscar/django-oscar/commit/…
    • @MikeSlinn Oscar 使用 Gulp 从 SCSS 文件构建 oscar/css/styles.cssoscar/css/dashboard.css(它实际使用)。如果你想修改 SCSS 文件,你需要为你的项目设置这样的建筑基础设施。如果你想使用 Gulp,你可以看看 Oscar 本身是如何做到的:github.com/django-oscar/django-oscar/blob/master/gulpfile.js。那里甚至还有一个任务可以监视 SCSS 文件的变化,并自动重建 CSS。
    猜你喜欢
    • 1970-01-01
    • 2016-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-11
    • 1970-01-01
    • 1970-01-01
    • 2018-10-13
    相关资源
    最近更新 更多