-
-
Notifications
You must be signed in to change notification settings - Fork 201
Browser sync #145
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
Browser sync #145
Changes from all commits
a6c13a3
18cdc59
be76aee
6e46049
30c8298
7c372cc
126fefc
cfdfe95
f7e9514
4203c04
52ee7bb
34c4c2f
2cbc8b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules/ | ||
npm-debug.log* | ||
/test_tmp | ||
.idea |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -173,6 +173,11 @@ class WebpackConfig { | |
this.terserPluginOptionsCallback = () => {}; | ||
this.optimizeCssPluginOptionsCallback = () => {}; | ||
this.notifierPluginOptionsCallback = () => {}; | ||
this.useImagesLoader = true; | ||
this.useFontsLoader = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line and the one above it already exist at the beginning of the More generally, the settings have been divided into categories (flags, options, callback), so you'll also have to move |
||
this.useBrowserSync = false; | ||
this.browserSyncOptionsCallback = () => {}; | ||
this.browserSyncOptions = {}; | ||
} | ||
|
||
getContext() { | ||
|
@@ -708,6 +713,17 @@ class WebpackConfig { | |
this.handlebarsConfigurationCallback = callback; | ||
} | ||
|
||
enableBrowserSync(paths, browserSyncOptionsCallback = () => {}) { | ||
this.useBrowserSync = true; | ||
this.browserSyncOptions.paths = paths; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we also check if |
||
|
||
if (typeof browserSyncOptionsCallback !== 'function') { | ||
throw new Error('Argument 2 to enableBrowserSync() must be a callback function.'); | ||
} | ||
|
||
this.browserSyncOptionsCallback = browserSyncOptionsCallback; | ||
} | ||
|
||
disableImagesLoader() { | ||
this.useImagesLoader = false; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,6 +128,15 @@ const features = { | |
{ name: 'handlebars-loader', enforce_version: true } | ||
], | ||
description: 'load Handlebars files' | ||
}, | ||
browsersync: { | ||
method: 'enableBrowserSync()', | ||
packages: [ | ||
{ name: 'browser-sync' }, | ||
{ name: 'browser-sync-webpack-plugin' }, | ||
{ name: 'url' } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is that package really needed? I don't see it being used anywhere else. |
||
], | ||
description: 'use browser-sync for live reload' | ||
} | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* This file is part of the Symfony Webpack Encore package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const loaderFeatures = require('../features'); | ||
const PluginPriorities = require('./plugin-priorities'); | ||
|
||
/** | ||
* @param {Array} plugins | ||
* @param {WebpackConfig} webpackConfig | ||
* @returns {void} | ||
*/ | ||
module.exports = function(plugins, webpackConfig) { | ||
|
||
if (!webpackConfig.useBrowserSync) { | ||
return; | ||
} | ||
|
||
loaderFeatures.ensurePackagesExistAndAreCorrectVersion('browsersync'); | ||
const BrowserSyncPlugin = require('browser-sync-webpack-plugin'); | ||
|
||
let browserSyncOptions = { | ||
files: [ | ||
{ | ||
match: webpackConfig.browserSyncOptions.paths, | ||
fn: function(event, file) { | ||
if (event === 'change') { | ||
// get the named instance | ||
const bs = require('browser-sync').get('bs-webpack-plugin'); | ||
bs.reload(); | ||
} | ||
} | ||
} | ||
] | ||
}; | ||
|
||
let browserSyncPluginOptions = { | ||
reload: false, | ||
name: 'bs-webpack-plugin' // same as used require('browser-sync').get() | ||
}; | ||
|
||
// allow to overwrite values by user | ||
webpackConfig.browserSyncOptionsCallback.apply(null, | ||
[browserSyncOptions, browserSyncPluginOptions] | ||
); | ||
|
||
webpackConfig.plugins.push({ | ||
plugin: new BrowserSyncPlugin(browserSyncOptions, browserSyncPluginOptions), | ||
priority: PluginPriorities.BrowserSyncPlugin | ||
}); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,8 @@ | |
"@babel/preset-env": "^7.4.0", | ||
"assets-webpack-plugin": "^3.9.7", | ||
"babel-loader": "^8.0.0", | ||
"browser-sync": "^2.18.13", | ||
"browser-sync-webpack-plugin": "^2.2.2", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 browser-sync is a package aimed for development. not a big issue to fix this, too |
||
"chalk": "^2.4.1", | ||
"clean-webpack-plugin": "^0.1.19", | ||
"css-loader": "^2.1.1", | ||
|
@@ -62,6 +64,8 @@ | |
"@vue/babel-preset-jsx": "^1.0.0-beta.3", | ||
"autoprefixer": "^8.5.0", | ||
"babel-eslint": "^10.0.1", | ||
"browser-sync": "^2.18.13", | ||
"browser-sync-webpack-plugin": "^2.2.2", | ||
"chai": "^3.5.0", | ||
"chai-fs": "^1.0.0", | ||
"core-js": "^3.0.0", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* This file is part of the Symfony Webpack Encore package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const expect = require('chai').expect; | ||
const WebpackConfig = require('../../lib/WebpackConfig'); | ||
const RuntimeConfig = require('../../lib/config/RuntimeConfig'); | ||
const BrowserSyncPlugin = require('browser-sync-webpack-plugin'); | ||
|
||
function createConfig() { | ||
const runtimeConfig = new RuntimeConfig(); | ||
runtimeConfig.context = __dirname; | ||
runtimeConfig.babelRcFileExists = false; | ||
|
||
return new WebpackConfig(runtimeConfig); | ||
} | ||
|
||
describe('plugins/browser-sync', () => { | ||
it('getPlugins() basic usage', () => { | ||
const config = createConfig(); | ||
config.enableBrowserSync(['./src/*.php']); | ||
|
||
expect(config.plugins).to.have.lengthOf(0); | ||
const browserSync = require('../../lib/plugins/browser-sync'); | ||
browserSync(config.plugins,config); | ||
expect(config.plugins).to.have.lengthOf(1); | ||
const pluginInstance = config.plugins[0]; | ||
expect(pluginInstance.plugin).to.be.an.instanceof(BrowserSyncPlugin); | ||
|
||
expect(pluginInstance.plugin.options.reload).to.equal(false); | ||
expect(pluginInstance.plugin.options.name).to.equal('bs-webpack-plugin'); | ||
}); | ||
|
||
it('getPlugins() default proxy port', () => { | ||
const config = createConfig(); | ||
config.enableBrowserSync(['./src/*.php']); | ||
|
||
expect(config.plugins).to.have.lengthOf(0); | ||
const browserSync = require('../../lib/plugins/browser-sync'); | ||
browserSync(config.plugins,config); | ||
expect(config.plugins).to.have.lengthOf(1); | ||
const pluginInstance = config.plugins[0]; | ||
expect(pluginInstance.plugin).to.be.an.instanceof(BrowserSyncPlugin); | ||
|
||
expect(pluginInstance.plugin.options.reload).to.equal(false); | ||
expect(pluginInstance.plugin.options.name).to.equal('bs-webpack-plugin'); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're talking about
backendUrl
here and a bit below but no actual option is called like that, so it's a bit confusing. Did you meanproxy
?