Skip to content

Proofreading webpack.config.js for clarity #440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
1 commit merged into from
Jul 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions symfony/webpack-encore-pack/1.0/assets/css/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
background-color: lightgray;
}
14 changes: 14 additions & 0 deletions symfony/webpack-encore-pack/1.0/assets/js/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Welcome to your app's main JavaScript file!
*
* We recommend including the built version of this JavaScript file
* (and its CSS file) in your base layout (base.html.twig).
*/

// any CSS you require will output into a single css file (app.css in this case)
require('../css/app.css');

// Need jQuery? Install it with "yarn add jquery", then uncomment to require it.
// var $ = require('jquery');

console.log('Hello Webpack Encore! Edit me in assets/js/app.js');
3 changes: 2 additions & 1 deletion symfony/webpack-encore-pack/1.0/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"devDependencies": {
"@symfony/webpack-encore": "^0.19.0"
"@symfony/webpack-encore": "^0.19.0",
"webpack-notifier": "^1.6.0"
},
"license": "UNLICENSED",
"private": true,
Expand Down
44 changes: 30 additions & 14 deletions symfony/webpack-encore-pack/1.0/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,46 @@
var Encore = require('@symfony/webpack-encore');

Encore
// the project directory where compiled assets will be stored
// directory where compiled assets will be stored
.setOutputPath('public/build/')
// the public path used by the web server to access the previous directory
// public path used by the web server to access the output path
.setPublicPath('/build')
// the public path you will use in Symfony's asset() function - e.g. asset('build/some_file.js')
.setManifestKeyPrefix('build/')

// only needed for CDN's or sub-directory deploy
//.setManifestKeyPrefix('build/')

/*
* ENTRY CONFIG
*
* Add 1 entry for each "page" of your app
* (including one that's included on every page - e.g. "app")
*
* Each entry will result in one JavaScript file (e.g. app.js)
* and one CSS file (e.g. app.css) if you JavaScript imports CSS.
*/
.addEntry('app', './assets/js/app.js')
//.addEntry('page1', './assets/js/page1.js')
//.addEntry('page2', './assets/js/page2.js')

/*
* FEATURE CONFIG
*
* Enable & configure other features below. For a full
* list of features, see:
* https://symfony.com/doc/current/frontend.html#adding-more-features
*/
.cleanupOutputBeforeBuild()
.enableBuildNotifications()
.enableSourceMaps(!Encore.isProduction())

// the following line enables hashed filenames (e.g. app.abc123.css)
// enables hashed filenames (e.g. app.abc123.css)
.enableVersioning(Encore.isProduction())

// uncomment to define the assets of the project
//.addEntry('js/app', './assets/js/app.js')
//.addStyleEntry('css/app', './assets/css/app.scss')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you added a default JS entry, why not add one for CSS too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addStyleEntry is kind of an anti-pattern. So, I doc'ed it, but people shouldn't really need to use it, if they want to do things correctly.

// enables Sass/SCSS support
//.enableSassLoader()

// uncomment if you use TypeScript
//.enableTypeScriptLoader()

// uncomment if you use Sass/SCSS files
//.enableSassLoader()

// uncomment for legacy applications that require $/jQuery as a global variable
// uncomment if you're having problems with a jQuery plugin
//.autoProvidejQuery()
;

Expand Down