django集成用于laravel mix
djangomix的Python项目详细描述
Django混音
的django集成python表示中的laravel mix helper,便于在django项目中使用laravel mix npm包。
安装
Django:
pip install djangomix
注意:不要忘记在需求中包含包
Laravel Mix NPM包装:
Follow instructions on Laravel Mix webpage
请参阅下面的webpack.mix.js配置示例。
用法
将'djangomix'添加到django配置中已安装的应用程序中
INSTALLED_APPS = [
...
'djangomix',
]
包含在base.html(或任何其他模板中)
{% load mix %}
在模板中使用mix template标记加载脚本、样式…
注意:第二个参数是manifest.json的路径
<script src="{% mix 'build/app.js' 'polls/static' %}"></script>
路径与webpack.mix.js配置相关。
您也可以在django设置中为manifest dir和public path设置路径
MANIFEST_DIRECTORY = getattr(settings, 'LARAVELMIX_MANIFEST_DIRECTORY','')
PUBLIC_URL = getattr(settings, 'LARAVELMIX_PUBLIC_URL', settings.STATIC_URL)
webpack.mix.js的示例配置:
let mix = require('laravel-mix');
let staticPath = 'polls/static/build'
let resourcesPath = 'polls/resources'
mix.setResourceRoot('/static/build') // setResroucesRoots add prefix to url() in scss on example: from /images/close.svg to /static/images/close.svg
mix.setPublicPath('polls/static') // Path where mix-manifest.json is created
// if you don't need browser-sync feature you can remove this lines
if (process.argv.includes('--browser-sync')) {
mix.browserSync('localhost:8000')
}
// Now you can use full mix api
mix.js(`${resourcesPath}/js/app.js`, `${staticPath}/`)
mix.sass(`${resourcesPath}/sass/app.scss`, `${staticPath}/`)
你对设置有问题吗?Read how to setup and start with Vue in Django
维护者:Marek Racík来自IdeaLoop