forked from roots/sage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
154 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const qs = require('qs'); | ||
|
||
/** | ||
* Loop through webpack entry | ||
* and add the hot middleware | ||
* @param {Object} entry webpack entry | ||
* @return {Object} entry with hot middleware | ||
*/ | ||
module.exports = (entry) => { | ||
const results = {}; | ||
const hotMiddlewareScript = `webpack-hot-middleware/client?${qs.stringify({ | ||
timeout: 20000, | ||
reload: false, | ||
})}`; | ||
|
||
Object.keys(entry).forEach(name => { | ||
results[name] = Array.isArray(entry[name]) ? entry[name].slice(0) : [entry[name]]; | ||
results[name].push(hotMiddlewareScript); | ||
}); | ||
return results; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const path = require('path'); | ||
|
||
/** | ||
* Process AssetsPlugin output and format it | ||
* for Sage: {"[name].[ext]":"[name]_[hash].[ext]"} | ||
* @param {Object} assets passed by processOutput | ||
* @return {String} JSON | ||
*/ | ||
module.exports = (assets) => { | ||
const results = {}; | ||
Object.keys(assets).forEach(name => { | ||
Object.keys(assets[name]).forEach(ext => { | ||
const filename = `${path.dirname(assets[name][ext])}/${path.basename(`${name}.${ext}`)}`; | ||
results[filename] = assets[name][ext]; | ||
}); | ||
}); | ||
return JSON.stringify(results); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,24 @@ | ||
const BrowserSyncPlugin = require('browser-sync-webpack-plugin'); | ||
const url = require('url'); | ||
const webpack = require('webpack'); | ||
const BrowserSyncPlugin = require('./webpack.plugin.browsersync'); | ||
|
||
const config = require('./config'); | ||
|
||
module.exports = { | ||
output: { pathinfo: true }, | ||
debug: true, | ||
devTool: 'cheap-module-source-map', | ||
devtool: '#cheap-module-source-map', | ||
plugins: [ | ||
new webpack.optimize.OccurrenceOrderPlugin(), | ||
new webpack.HotModuleReplacementPlugin(), | ||
new webpack.NoErrorsPlugin(), | ||
new webpack.DefinePlugin({ | ||
WEBPACK_PUBLIC_PATH: JSON.stringify(config.publicPath), | ||
}), | ||
new BrowserSyncPlugin({ | ||
host: url.parse(config.proxyUrl).hostname, | ||
port: url.parse(config.proxyUrl).port, | ||
proxy: config.devUrl, | ||
files: [ | ||
'templates/**/*.php', | ||
'src/**/*.php', | ||
], | ||
target: config.devUrl, | ||
publicPath: config.publicPath, | ||
proxyUrl: config.proxyUrl, | ||
browserSyncOptions: { files: config.watch }, | ||
}), | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
'use strict'; // eslint-disable-line strict | ||
|
||
const webpackDevMiddleware = require('webpack-dev-middleware'); | ||
const webpackHotMiddleware = require('webpack-hot-middleware'); | ||
const browserSync = require('browser-sync'); | ||
const url = require('url'); | ||
|
||
const mergeWithConcat = require('./util/mergeWithConcat'); | ||
|
||
module.exports = class { | ||
constructor(options) { | ||
this.watcher = null; | ||
this.compiler = null; | ||
this.options = mergeWithConcat({ | ||
proxyUrl: 'https://localhost:3000', | ||
callback() {}, | ||
}, options); | ||
} | ||
apply(compiler) { | ||
if (this.options.disable) { | ||
return; | ||
} | ||
this.compiler = compiler; | ||
compiler.plugin('done', this.doneCompiling); | ||
} | ||
doneCompiling() { | ||
if (!this.watcher) { | ||
this.watcher = browserSync.create(); | ||
this.compiler.plugin('compilation', () => this.watcher.notify('Rebuilding...')); | ||
this.start(); | ||
} | ||
// Optionally add logic for this.watcher.reload() | ||
} | ||
start() { | ||
const watcherConfig = mergeWithConcat({ | ||
host: url.parse(this.options.proxyUrl).hostname, | ||
port: url.parse(this.options.proxyUrl).port, | ||
proxy: { | ||
target: this.options.target, | ||
middleware: this.middleware(), | ||
}, | ||
}, this.options.browserSyncOptions); | ||
this.watcher.init(watcherConfig, this.options.callback.bind(this)); | ||
} | ||
middleware() { | ||
this.webpackDevMiddleware = webpackDevMiddleware(this.compiler, { | ||
publicPath: this.options.publicPath, | ||
stats: { colors: true }, | ||
}); | ||
this.webpackHotMiddleware = webpackHotMiddleware(this.compiler, { | ||
log: this.watcher.notify.bind(this.watcher), | ||
}); | ||
return [this.webpackDevMiddleware, this.webpackHotMiddleware]; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters