From 3ea13af2b607b988e861c6318cbd7b0b3622e0f6 Mon Sep 17 00:00:00 2001 From: Hippolyte Alain Date: Tue, 13 Jun 2017 14:23:12 +0200 Subject: [PATCH 1/5] Enhance the webpack-encore integration --- app/Resources/assets/js/admin.js | 6 ++---- app/Resources/assets/scss/admin.scss | 1 + package.json | 6 ++++++ webpack.config.js | 5 +++++ 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/Resources/assets/js/admin.js b/app/Resources/assets/js/admin.js index 2338c09e2..d4642a9c5 100644 --- a/app/Resources/assets/js/admin.js +++ b/app/Resources/assets/js/admin.js @@ -1,9 +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'); +import typeahead from "typeahead.js"; +import Bloodhound from "bloodhound-js"; require('bootstrap-tagsinput'); $(function() { diff --git a/app/Resources/assets/scss/admin.scss b/app/Resources/assets/scss/admin.scss index a9a96fde2..c145f454f 100644 --- a/app/Resources/assets/scss/admin.scss +++ b/app/Resources/assets/scss/admin.scss @@ -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' ------------------------------------------------------------------------- */ diff --git a/package.json b/package.json index db6aa4e02..a080aad3f 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/webpack.config.js b/webpack.config.js index abf9317ba..2abbedf48 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -5,6 +5,11 @@ Encore .setPublicPath('/build') .cleanupOutputBeforeBuild() .autoProvidejQuery() + .autoProvideVariables({ + "window.jQuery": "jquery", + "window.Bloodhound": require.resolve('bloodhound-js'), + "jQuery.tagsinput": "bootstrap-tagsinput" + }) .enableSassLoader() .enableVersioning(false) .createSharedEntry('js/common', ['jquery']) From 080b79a6b19397a6c3dd6dea4bde2394d12ca235 Mon Sep 17 00:00:00 2001 From: Hippolyte Alain Date: Tue, 13 Jun 2017 15:34:41 +0200 Subject: [PATCH 2/5] Fix highlight colors in modal --- app/Resources/assets/js/app.js | 8 ++++---- app/Resources/assets/js/highlight.js | 11 +++++------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/app/Resources/assets/js/app.js b/app/Resources/assets/js/app.js index d572dd7a4..8029f3c0a 100644 --- a/app/Resources/assets/js/app.js +++ b/app/Resources/assets/js/app.js @@ -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'; diff --git a/app/Resources/assets/js/highlight.js b/app/Resources/assets/js/highlight.js index 4fa7cf841..76bf5e2f2 100644 --- a/app/Resources/assets/js/highlight.js +++ b/app/Resources/assets/js/highlight.js @@ -1,9 +1,8 @@ -var hljs = require('highlight.js/lib/highlight.js'); +import hljs from 'highlight.js'; +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; From da3a8646cc3df70ef490343cb1810b04e894f0d8 Mon Sep 17 00:00:00 2001 From: Hippolyte Alain Date: Tue, 13 Jun 2017 16:10:02 +0200 Subject: [PATCH 3/5] Fix label autocompletion --- app/Resources/assets/js/admin.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/Resources/assets/js/admin.js b/app/Resources/assets/js/admin.js index d4642a9c5..f2bab3762 100644 --- a/app/Resources/assets/js/admin.js +++ b/app/Resources/assets/js/admin.js @@ -1,8 +1,7 @@ -require('eonasdan-bootstrap-datetimepicker'); - -import typeahead from "typeahead.js"; +import 'eonasdan-bootstrap-datetimepicker'; +import 'typeahead.js'; import Bloodhound from "bloodhound-js"; -require('bootstrap-tagsinput'); +import 'bootstrap-tagsinput'; $(function() { // Datetime picker initialization. @@ -31,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) { From beda0c662464326d89526d1f4c6b6321fe55bbf7 Mon Sep 17 00:00:00 2001 From: Hippolyte Alain Date: Tue, 13 Jun 2017 18:01:32 +0200 Subject: [PATCH 4/5] Reduce the app.js size --- app/Resources/assets/js/highlight.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Resources/assets/js/highlight.js b/app/Resources/assets/js/highlight.js index 76bf5e2f2..b20bb11a0 100644 --- a/app/Resources/assets/js/highlight.js +++ b/app/Resources/assets/js/highlight.js @@ -1,4 +1,4 @@ -import hljs from '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'; From 71f145b740be29cf448295a74782037fc3d2add6 Mon Sep 17 00:00:00 2001 From: Hippolyte Alain Date: Wed, 14 Jun 2017 11:09:25 +0200 Subject: [PATCH 5/5] Remove moment.js locale from build --- webpack.config.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/webpack.config.js b/webpack.config.js index 2abbedf48..801b8a0d6 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,4 +1,5 @@ var Encore = require('@symfony/webpack-encore'); +var webpack = require('webpack'); Encore .setOutputPath('web/build/') @@ -20,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;