Skip to content

Commit

Permalink
Add Webpack Encore
Browse files Browse the repository at this point in the history
  • Loading branch information
kulczy committed Nov 6, 2019
1 parent 4ddc064 commit 031f94c
Show file tree
Hide file tree
Showing 18 changed files with 4,634 additions and 87 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/public/css
/public/js
/public/media
/public/build
!/public/media/image/.gitkeep

/app/config/parameters.yml
Expand Down Expand Up @@ -40,3 +41,8 @@
###> phpunit/phpunit ###
/phpunit.xml
###< phpunit/phpunit ###

###> symfony/webpack-encore-bundle ###
/npm-debug.log
/yarn-error.log
###< symfony/webpack-encore-bundle ###
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"symfony/translation": "^3.4|^4.3",
"symfony/twig-bundle": "^3.4|^4.3",
"symfony/validator": "^3.4|^4.3",
"symfony/webpack-encore-bundle": "^1.7",
"symfony/yaml": "^3.4|^4.3",
"twig/extensions": "^1.4",
"twig/twig": "^2.6",
Expand Down
1 change: 1 addition & 0 deletions config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@
Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true],
FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle::class => ['test' => true, 'test_cached' => true],
Sylius\Behat\Application\SyliusTestPlugin\SyliusTestPlugin::class => ['test' => true, 'test_cached' => true],
Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true],
];
7 changes: 7 additions & 0 deletions config/packages/assets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
framework:
assets:
packages:
shop:
json_manifest_path: '%kernel.project_dir%/public/build/shop/manifest.json'
admin:
json_manifest_path: '%kernel.project_dir%/public/build/admin/manifest.json'
Empty file.
5 changes: 5 additions & 0 deletions config/packages/webpack_encore.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
webpack_encore:
output_path: '%kernel.project_dir%/public/build/default'
builds:
shop: '%kernel.project_dir%/public/build/shop'
admin: '%kernel.project_dir%/public/build/admin'
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"semantic-ui-css": "^2.2.0"
},
"devDependencies": {
"@symfony/webpack-encore": "^0.28.0",
"babel-core": "^6.26.3",
"babel-plugin-external-helpers": "^6.22.0",
"babel-plugin-module-resolver": "^3.1.1",
Expand Down Expand Up @@ -36,6 +37,7 @@
"rollup-plugin-inject": "^2.0.0",
"rollup-plugin-node-resolve": "^3.3.0",
"rollup-plugin-uglify": "^4.0.0",
"sass-loader": "^7.0.1",
"upath": "^1.1.0",
"yargs": "^6.4.0"
},
Expand Down
13 changes: 13 additions & 0 deletions src/Sylius/Bundle/AdminBundle/Resources/private/entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import './js/shim/shim-jquery';
import './js/shim/shim-semantic-ui';

import 'semantic-ui-css/semantic.css';

import 'sylius/ui-resources/js/app';
import './js/app';

import 'sylius/ui-resources/sass/main.scss';
import './sass/main.scss';

import './img/admin-logo.svg';
import 'sylius/ui-resources/img/logo.png';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% include '@SyliusUi/_javascripts.html.twig' with {'path': 'assets/admin/js/app.js'} %}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% include '@SyliusUi/_stylesheets.html.twig' with {'path': 'assets/admin/css/style.css'} %}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block title %} | Sylius{% endblock %}

{% block stylesheets %}
{% include '@SyliusUi/_stylesheets.html.twig' with {'path': 'assets/admin/css/style.css'} %}
{% include '@SyliusAdmin/_styles.html.twig' %}

{{ sonata_block_render_event('sylius.admin.layout.stylesheets') }}
{% endblock %}
Expand Down Expand Up @@ -49,7 +49,7 @@
{% endblock %}

{% block javascripts %}
{% include '@SyliusUi/_javascripts.html.twig' with {'path': 'assets/admin/js/app.js'} %}
{% include '@SyliusAdmin/_scripts.html.twig' %}

{{ sonata_block_render_event('sylius.admin.layout.javascripts') }}
{% endblock %}
15 changes: 15 additions & 0 deletions src/Sylius/Bundle/ShopBundle/Resources/private/entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import './js/shim/shim-jquery';
import './js/shim/shim-lightbox';
import './js/shim/shim-semantic-ui';

import 'semantic-ui-css/semantic.css';
import 'lightbox2/dist/css/lightbox.min.css';

import 'sylius/ui-resources/js/app';
import './js/app';

import 'sylius/ui-resources/sass/main.scss';
import './scss/style.scss';

import 'sylius/ui-resources/img/logo.png';
import 'sylius/ui-resources/img/avatar.png';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% include '@SyliusUi/_javascripts.html.twig' with {'path': 'assets/shop/js/app.js'} %}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% include '@SyliusUi/_stylesheets.html.twig' with {'path': 'assets/shop/css/style.css'} %}
4 changes: 2 additions & 2 deletions src/Sylius/Bundle/ShopBundle/Resources/views/layout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->

{% include '@SyliusUi/_stylesheets.html.twig' with {'path': 'assets/shop/css/style.css'} %}
{% include '@SyliusShop/_styles.html.twig' %}

{{ sonata_block_render_event('sylius.shop.layout.stylesheets') }}
{% endblock %}
Expand Down Expand Up @@ -71,7 +71,7 @@
</div>

{% block javascripts %}
{% include '@SyliusUi/_javascripts.html.twig' with {'path': 'assets/shop/js/app.js'} %}
{% include '@SyliusShop/_scripts.html.twig' %}

{{ sonata_block_render_event('sylius.shop.layout.javascripts') }}
{% endblock %}
Expand Down
18 changes: 18 additions & 0 deletions symfony.lock
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,24 @@
"ref": "dae9b39fd6717970be7601101ce5aa960bf53d9a"
}
},
"symfony/webpack-encore-bundle": {
"version": "1.0",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "1.0",
"ref": "d3b160b9799c91cbfc3df6f018c795f3bf88698a"
},
"files": [
"assets/css/app.css",
"assets/js/app.js",
"config/packages/assets.yaml",
"config/packages/prod/webpack_encore.yaml",
"config/packages/webpack_encore.yaml",
"package.json",
"webpack.config.js"
]
},
"symfony/yaml": {
"version": "v4.1.3"
},
Expand Down
44 changes: 44 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const path = require('path');
const Encore = require('@symfony/webpack-encore');

const uiBundleScripts = path.resolve(__dirname, 'src/Sylius/Bundle/UiBundle/Resources/private/js/');
const uiBundleResources = path.resolve(__dirname, 'src/Sylius/Bundle/UiBundle/Resources/private/');

// Shop config
Encore
.setOutputPath('public/build/shop/')
.setPublicPath('/build/shop')
.addEntry('shop-entry', './src/Sylius/Bundle/ShopBundle/Resources/private/entry.js')
.disableSingleRuntimeChunk()
.cleanupOutputBeforeBuild()
.enableSourceMaps(!Encore.isProduction())
.enableVersioning(Encore.isProduction())
.enableSassLoader();

const shopConfig = Encore.getWebpackConfig();

shopConfig.resolve.alias['sylius/ui'] = uiBundleScripts;
shopConfig.resolve.alias['sylius/ui-resources'] = uiBundleResources;
shopConfig.name = 'shop';

Encore.reset();

// Admin config
Encore
.setOutputPath('public/build/admin/')
.setPublicPath('/build/admin')
.addEntry('admin-entry', './src/Sylius/Bundle/AdminBundle/Resources/private/entry.js')
.disableSingleRuntimeChunk()
.cleanupOutputBeforeBuild()
.enableSourceMaps(!Encore.isProduction())
.enableVersioning(Encore.isProduction())
.enableSassLoader();

const adminConfig = Encore.getWebpackConfig();

adminConfig.resolve.alias['sylius/ui'] = uiBundleScripts;
adminConfig.resolve.alias['sylius/ui-resources'] = uiBundleResources;
adminConfig.externals = Object.assign({}, adminConfig.externals, { window: 'window', document: 'document' });
adminConfig.name = 'admin';

module.exports = [shopConfig, adminConfig];
Loading

0 comments on commit 031f94c

Please sign in to comment.