Skip to content

Commit 15b24a1

Browse files
committed
Add webpack plugin update deps and compile with gulp-typescript (no need for babel)
1 parent c9efaf8 commit 15b24a1

File tree

9 files changed

+397
-364
lines changed

9 files changed

+397
-364
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
/vendor/
55
/node_modules/
66
/.phpunit/
7-
/.phpunit.result.cache
7+
/.phpunit.result.cache
8+
.idea

Resources/doc/installation.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,9 @@ Execute the following command to publish the assets required by the bundle:
5555
$ php bin/console assets:install --symlink public
5656
5757
.. _`installation chapter`: https://getcomposer.org/doc/00-intro.md
58+
59+
Step 5: If you are using webpack, install the npm package locally
60+
-----------------------------------------------------------------
61+
.. code-block:: bash
62+
63+
$ yarn add -D ./vendor/friendsofsymfony/jsrouting-bundle/Resources/

Resources/doc/usage.rst

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,24 @@ In applications not using webpack add these two lines in your layout:
2323
the two JavaScript files above loaded at some point in your web page.
2424

2525

26-
If you are using webpack and Encore to package your assets you will need to use the dump command
26+
If you are using webpack and Encore to package your assets you can use the webpack plugin included in this package
27+
28+
.. code-block:: js
29+
30+
const FosRouting = require('fos-router/webpack/FosRouting');
31+
//...
32+
Encore
33+
.addPlugin(new FosRouting())
34+
35+
Then use it simply by importing ``import Routing from 'fos-router';`` in your js or ts code
36+
37+
38+
Alternatively you can use the dump command
2739
and export your routes to json, this command will create a json file into the ``web/js`` folder:
2840

2941
.. code-block:: bash
3042
31-
bin/console fos:js-routing:dump --format=json
43+
bin/console fos:js-routing:dump --format=json --target=assets/js/routes.json
3244
3345
If you are using Flex, probably you want to dump your routes into the ``public`` folder
3446
instead of ``web``, to achieve this you can set the ``target`` parameter:

Resources/gulpfile.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
const gulp = require('gulp');
2-
const babel = require('gulp-babel');
32
const rename = require('gulp-rename');
43
const uglify = require('gulp-uglify');
54
const wrap = require('gulp-wrap');
5+
const ts = require('gulp-typescript')
66

7-
gulp.task('js', function() {
7+
gulp.task('ts', function() {
88
return gulp.src('js/router.ts')
9-
.pipe(babel({
10-
presets: ["@babel/preset-env", "@babel/preset-typescript"],
11-
plugins: ["@babel/plugin-transform-object-assign"]
9+
.pipe(ts({
10+
noImplicitAny: true,
1211
}))
12+
.pipe(gulp.dest('public/js'));
13+
});
14+
15+
gulp.task('min', function() {
16+
return gulp.src('public/js/!(*.min).js')
1317
.pipe(wrap({ src: 'js/router.template.js' }))
1418
.pipe(gulp.dest('public/js'))
1519
.pipe(rename({ extname: '.min.js' }))
1620
.pipe(uglify())
1721
.pipe(gulp.dest('public/js'));
1822
});
1923

20-
gulp.task('default', gulp.series('js'));
24+
gulp.task('default', gulp.series('ts', 'min'));

Resources/js/router.template.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
var exports = {};
2020
<%= contents %>
2121

22-
return { Router: Router, Routing: Routing };
22+
return { Router: exports.Router, Routing: exports.Routing };
2323
}));

Resources/package.json

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fos-router",
3-
"version": "2.2.0",
3+
"version": "2.4.3",
44
"description": "A pretty nice way to use the routes generated by the FOSJsRoutingBundle in your JavaScript.",
55
"keywords": [
66
"router",
@@ -23,33 +23,32 @@
2323
],
2424
"main": "public/js/router.js",
2525
"files": [
26+
"webpack/FosRouting.js",
2627
"public/js/router.js",
2728
"public/js/router.min.js",
2829
"ts/router.d.ts"
2930
],
3031
"types": "ts/router.d.ts",
3132
"devDependencies": {
32-
"@babel/core": "^7.14.0",
33-
"@babel/plugin-transform-object-assign": "^7.12.13",
34-
"@babel/polyfill": "^7.12.1",
35-
"@babel/preset-env": "^7.14.1",
36-
"@babel/preset-typescript": "^7.13.0",
37-
"@types/node": "^14.14.44",
38-
"google-closure-library": "^20171203.0.0",
33+
"@types/node": "^14.18.10",
34+
"google-closure-library": "^20220104.0.0",
3935
"gulp": "^4.0.2",
40-
"gulp-babel": "^8.0.0",
41-
"gulp-rename": "^1.2.2",
42-
"gulp-uglify": "^1.5.4",
43-
"gulp-wrap": "^0.13.0",
44-
"jasmine": "^2.4.1",
45-
"tsd": "^0.14.0",
46-
"typescript": "^4.2.4"
36+
"gulp-rename": "^2.0.0",
37+
"gulp-uglify": "^3.0.2",
38+
"gulp-typescript": "^6.0.0-alpha.1",
39+
"gulp-wrap": "^0.15.0",
40+
"jasmine": "^4.0.2",
41+
"tsd": "^0.19.1",
42+
"typescript": "^4.5.5"
4743
},
4844
"scripts": {
4945
"build": "gulp && npm run build:types",
5046
"build:types": "tsc --declaration --emitDeclarationOnly",
5147
"test": "npm run build && npm run test:types && phantomjs js/run_jsunit.js js/router_test.html",
52-
"test:types": "tsd"
48+
"test:types": "tsd",
49+
"prepublish": "npm run build"
5350
},
54-
"dependencies": {}
51+
"dependencies": {
52+
"webpack-inject-plugin": "^1.5.5"
53+
}
5554
}

0 commit comments

Comments
 (0)