Skip to content

Enhance the webpack-encore integration #587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions app/Resources/assets/js/admin.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
require('eonasdan-bootstrap-datetimepicker');

require('imports-loader?define=>false!typeahead.js/dist/typeahead.jquery.min.js');
const Bloodhound = require('imports-loader?define=>false!typeahead.js/dist/bloodhound.js');
window.Bloodhound = Bloodhound;
require('../scss/bootstrap-tagsinput.scss');
require('bootstrap-tagsinput');
import 'eonasdan-bootstrap-datetimepicker';
import 'typeahead.js';
import Bloodhound from "bloodhound-js";
import 'bootstrap-tagsinput';

$(function() {
// Datetime picker initialization.
Expand Down Expand Up @@ -33,16 +30,17 @@ $(function() {
datumTokenizer: Bloodhound.tokenizers.whitespace
});
source.initialize();

$input.tagsinput({
trimValue: true,
focusClass: 'focus',
typeahead: {
typeaheadjs: {
name: 'tags',
source: source.ttAdapter()
}
});
}
})
});

// Handling the modal confirmation message.
$(document).on('submit', 'form[data-confirmation]', function (event) {
Expand Down
8 changes: 4 additions & 4 deletions app/Resources/assets/js/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// loads the Bootstrap jQuery plugins
require('bootstrap-sass/assets/javascripts/bootstrap/dropdown.js');
require('bootstrap-sass/assets/javascripts/bootstrap/modal.js');
require('bootstrap-sass/assets/javascripts/bootstrap/transition.js');
import 'bootstrap-sass/assets/javascripts/bootstrap/dropdown.js';
import 'bootstrap-sass/assets/javascripts/bootstrap/modal.js';
import 'bootstrap-sass/assets/javascripts/bootstrap/transition.js';

// loads the code syntax highlighting library
require('./highlight.js');
import './highlight.js';
11 changes: 5 additions & 6 deletions app/Resources/assets/js/highlight.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
var hljs = require('highlight.js/lib/highlight.js');
import hljs from 'highlight.js/lib/highlight';
import php from 'highlight.js/lib/languages/php';
import twig from 'highlight.js/lib/languages/twig';

hljs.configure({
languages: ['twig', 'php']
});
hljs.registerLanguage('php', php);
hljs.registerLanguage('twig', twig);

hljs.initHighlightingOnLoad();

module.exports = hljs;
1 change: 1 addition & 0 deletions app/Resources/assets/scss/admin.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import "~bootswatch/flatly/variables";
@import "~eonasdan-bootstrap-datetimepicker/src/sass/bootstrap-datetimepicker-build.scss";
@import "bootstrap-tagsinput.scss";

/* Page: 'Backend post index'
------------------------------------------------------------------------- */
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,11 @@
"node-sass": "^4.5.3",
"sass-loader": "^6.0.5",
"typeahead.js": "^0.11.1"
},
"scripts": {
"dev-server": "./node_modules/.bin/encore dev-server",
"dev": "./node_modules/.bin/encore dev",
"watch": "./node_modules/.bin/encore dev --watch",
"build": "./node_modules/.bin/encore production"
}
}
12 changes: 11 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
var Encore = require('@symfony/webpack-encore');
var webpack = require('webpack');

Encore
.setOutputPath('web/build/')
.setPublicPath('/build')
.cleanupOutputBeforeBuild()
.autoProvidejQuery()
.autoProvideVariables({
"window.jQuery": "jquery",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a PR on webpack-encore to provide this automatically

"window.Bloodhound": require.resolve('bloodhound-js'),
"jQuery.tagsinput": "bootstrap-tagsinput"
})
.enableSassLoader()
.enableVersioning(false)
.createSharedEntry('js/common', ['jquery'])
Expand All @@ -15,4 +21,8 @@ Encore
.addStyleEntry('css/admin', ['./app/Resources/assets/scss/admin.scss'])
;

module.exports = Encore.getWebpackConfig();
var config = Encore.getWebpackConfig();

config.plugins.push(new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/));

module.exports = config;