From 13d02c104abf847f412bcf309886367263ca54d0 Mon Sep 17 00:00:00 2001 From: Hippolyte Alain Date: Tue, 13 Jun 2017 14:23:12 +0200 Subject: [PATCH] Enhance the webpack-encore integration --- app/Resources/assets/js/admin.js | 16 +++++++--------- app/Resources/assets/js/app.js | 8 ++++---- app/Resources/assets/js/highlight.js | 11 +++++------ app/Resources/assets/scss/admin.scss | 1 + package.json | 6 ++++++ webpack.config.js | 12 +++++++++++- 6 files changed, 34 insertions(+), 20 deletions(-) diff --git a/app/Resources/assets/js/admin.js b/app/Resources/assets/js/admin.js index 2338c09e2..f2bab3762 100644 --- a/app/Resources/assets/js/admin.js +++ b/app/Resources/assets/js/admin.js @@ -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. @@ -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) { 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..b20bb11a0 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/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; 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..801b8a0d6 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -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", + "window.Bloodhound": require.resolve('bloodhound-js'), + "jQuery.tagsinput": "bootstrap-tagsinput" + }) .enableSassLoader() .enableVersioning(false) .createSharedEntry('js/common', ['jquery']) @@ -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;