【发布时间】:2019-03-04 05:50:34
【问题描述】:
我想在 Symfony 4.1 中使用带有 Webpack Encore 的引导程序,但引导程序不起作用。在这篇文章的 template/base.html.twig 文件中,我使用了一些引导类,但没有考虑在内,我不明白为什么。
我使用 yarn 安装了引导程序所需的依赖项:
yarn add bootstrap --dev
yarn add jquery --dev
yarn add popper.js --dev
模板/base.html.twig
在这个文件中,我使用资产函数来考虑文件:build/app.scss 和 build/app.js
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>{% block title %}Welcome!{% endblock %}</title>
{% block stylesheets %}
<link rel="stylesheet" href="{{ asset('build/app.scss') }}">
{% endblock %}
</head>
<body>
{% block body %}
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" ar$
<span class="navbar-toggler-icon"></span>
</button>
</nav>
{% endblock %}
{% block javascripts %}
<script src="{{ asset('build/app.js') }}"></script>
{% endblock %}
</body>
</html>
在以下两个文件中,我需要并导入了引导程序所需的内容。
assets/js/app.js
require('../css/app.scss');
var $ = require('jquery');
require('bootstrap');
assets/css/app.scss
@import "~bootstrap/scss/bootstrap";
webpack.config.js
在这个文件中,我使用 enableSassLoader() 来激活 Sass 并使用 autoProvidejQuery() 来作为全局变量访问 jQuery。
var Encore = require('@symfony/webpack-encore');
Encore
// directory where compiled assets will be stored
.setOutputPath('public/build/')
// public path used by the web server to access the output path
.setPublicPath('/build')
// only needed for CDN's or sub-directory deploy
//.setManifestKeyPrefix('build/')
/*
* ENTRY CONFIG
*
* Add 1 entry for each "page" of your app
* (including one that's included on every page - e.g. "app")
*
* Each entry will result in one JavaScript file (e.g. app.js)
* and one CSS file (e.g. app.css) if you JavaScript imports CSS.
*/
.addEntry('app', './assets/js/app.js')
/*
* FEATURE CONFIG
*
* Enable & configure other features below. For a full
* list of features, see:
* https://symfony.com/doc/current/frontend.html#adding-more-features
*/
.cleanupOutputBeforeBuild()
.enableBuildNotifications()
.enableSourceMaps(!Encore.isProduction())
// enables hashed filenames (e.g. app.abc123.css)
.enableVersioning(Encore.isProduction())
// enables Sass/SCSS support
.enableSassLoader()
// uncomment if you use TypeScript
//.enableTypeScriptLoader()
// uncomment if you're having problems with a jQuery plugin
.autoProvidejQuery()
;
module.exports = Encore.getWebpackConfig();
yarn encore dev 命令可以正确构建所有内容。但是,我在屏幕上看不到引导主题。
提前致谢,
【问题讨论】:
标签: bootstrap-4 symfony4 webpack-encore