Skip to content

Commit 63489e0

Browse files
committed
feature #587 Enhance the webpack-encore integration (alOneh)
This PR was squashed before being merged into the master branch (closes #587). Discussion ---------- Enhance the webpack-encore integration This enhance the first integration (#586) of webpack-encore. Fixes : * jquery issue * typeahead issue * delete modal issue - [ ] Add build sources - [ ] Update webpack-encore version Commits ------- 13d02c1 Enhance the webpack-encore integration
2 parents dc47290 + 13d02c1 commit 63489e0

File tree

6 files changed

+34
-20
lines changed

6 files changed

+34
-20
lines changed

app/Resources/assets/js/admin.js

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
require('eonasdan-bootstrap-datetimepicker');
2-
3-
require('imports-loader?define=>false!typeahead.js/dist/typeahead.jquery.min.js');
4-
const Bloodhound = require('imports-loader?define=>false!typeahead.js/dist/bloodhound.js');
5-
window.Bloodhound = Bloodhound;
6-
require('../scss/bootstrap-tagsinput.scss');
7-
require('bootstrap-tagsinput');
1+
import 'eonasdan-bootstrap-datetimepicker';
2+
import 'typeahead.js';
3+
import Bloodhound from "bloodhound-js";
4+
import 'bootstrap-tagsinput';
85

96
$(function() {
107
// Datetime picker initialization.
@@ -33,16 +30,17 @@ $(function() {
3330
datumTokenizer: Bloodhound.tokenizers.whitespace
3431
});
3532
source.initialize();
33+
3634
$input.tagsinput({
3735
trimValue: true,
3836
focusClass: 'focus',
39-
typeahead: {
37+
typeaheadjs: {
4038
name: 'tags',
4139
source: source.ttAdapter()
4240
}
4341
});
4442
}
45-
})
43+
});
4644

4745
// Handling the modal confirmation message.
4846
$(document).on('submit', 'form[data-confirmation]', function (event) {

app/Resources/assets/js/app.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// loads the Bootstrap jQuery plugins
2-
require('bootstrap-sass/assets/javascripts/bootstrap/dropdown.js');
3-
require('bootstrap-sass/assets/javascripts/bootstrap/modal.js');
4-
require('bootstrap-sass/assets/javascripts/bootstrap/transition.js');
2+
import 'bootstrap-sass/assets/javascripts/bootstrap/dropdown.js';
3+
import 'bootstrap-sass/assets/javascripts/bootstrap/modal.js';
4+
import 'bootstrap-sass/assets/javascripts/bootstrap/transition.js';
55

66
// loads the code syntax highlighting library
7-
require('./highlight.js');
7+
import './highlight.js';

app/Resources/assets/js/highlight.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
var hljs = require('highlight.js/lib/highlight.js');
1+
import hljs from 'highlight.js/lib/highlight';
2+
import php from 'highlight.js/lib/languages/php';
3+
import twig from 'highlight.js/lib/languages/twig';
24

3-
hljs.configure({
4-
languages: ['twig', 'php']
5-
});
5+
hljs.registerLanguage('php', php);
6+
hljs.registerLanguage('twig', twig);
67

78
hljs.initHighlightingOnLoad();
8-
9-
module.exports = hljs;

app/Resources/assets/scss/admin.scss

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@import "~bootswatch/flatly/variables";
22
@import "~eonasdan-bootstrap-datetimepicker/src/sass/bootstrap-datetimepicker-build.scss";
3+
@import "bootstrap-tagsinput.scss";
34

45
/* Page: 'Backend post index'
56
------------------------------------------------------------------------- */

package.json

+6
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,11 @@
1414
"node-sass": "^4.5.3",
1515
"sass-loader": "^6.0.5",
1616
"typeahead.js": "^0.11.1"
17+
},
18+
"scripts": {
19+
"dev-server": "./node_modules/.bin/encore dev-server",
20+
"dev": "./node_modules/.bin/encore dev",
21+
"watch": "./node_modules/.bin/encore dev --watch",
22+
"build": "./node_modules/.bin/encore production"
1723
}
1824
}

webpack.config.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
var Encore = require('@symfony/webpack-encore');
2+
var webpack = require('webpack');
23

34
Encore
45
.setOutputPath('web/build/')
56
.setPublicPath('/build')
67
.cleanupOutputBeforeBuild()
78
.autoProvidejQuery()
9+
.autoProvideVariables({
10+
"window.jQuery": "jquery",
11+
"window.Bloodhound": require.resolve('bloodhound-js'),
12+
"jQuery.tagsinput": "bootstrap-tagsinput"
13+
})
814
.enableSassLoader()
915
.enableVersioning(false)
1016
.createSharedEntry('js/common', ['jquery'])
@@ -15,4 +21,8 @@ Encore
1521
.addStyleEntry('css/admin', ['./app/Resources/assets/scss/admin.scss'])
1622
;
1723

18-
module.exports = Encore.getWebpackConfig();
24+
var config = Encore.getWebpackConfig();
25+
26+
config.plugins.push(new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/));
27+
28+
module.exports = config;

0 commit comments

Comments
 (0)