Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'webpack-4'
  • Loading branch information
SpaceK33z committed Feb 25, 2018
2 parents ab4eeb0 + dbea323 commit 7378e3e
Show file tree
Hide file tree
Showing 18 changed files with 4,885 additions and 2,806 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -28,6 +28,8 @@ the [`before`](https://webpack.js.org/configuration/dev-server/#devserver-before
and [`after`](https://webpack.js.org/configuration/dev-server/#devserver-after)
hooks in the documentation.

Use [webpack-serve](https://github.com/webpack-contrib/webpack-serve) for a fast alternative. Use webpack-dev-server if you need to test on old browsers.

## Getting Started

First thing's first, install the module:
Expand Down
16 changes: 13 additions & 3 deletions bin/webpack-dev-server.js
Expand Up @@ -2,7 +2,7 @@

'use strict';

/* eslint global-require: off, import/order: off, no-console: off */
/* eslint global-require: off, import/order: off, no-console: off, import/no-extraneous-dependencies: off */
require('../lib/polyfills');

const debug = require('debug')('webpack-dev-server');
Expand All @@ -24,6 +24,16 @@ if (importLocal(__filename)) {
const Server = require('../lib/Server');
const webpack = require('webpack'); // eslint-disable-line

try {
require.resolve('webpack-cli');
} catch (e) {
console.error('The CLI moved into a separate package: webpack-cli.');
console.error("Please install 'webpack-cli' in addition to webpack itself to use the CLI.");
console.error('-> When using npm: npm install webpack-cli -D');
console.error('-> When using yarn: yarn add webpack-cli -D');
process.exitCode = 1;
}

function versionInfo() {
return `webpack-dev-server ${require('../package.json').version}\n` +
`webpack ${require('webpack/package.json').version}`;
Expand Down Expand Up @@ -51,7 +61,7 @@ const defaultTo = (value, def) => value == null ? def : value;
const yargs = require('yargs')
.usage(`${versionInfo()}\nUsage: https://webpack.js.org/configuration/dev-server/`);

require('webpack/bin/config-yargs')(yargs);
require('webpack-cli/bin/config-yargs')(yargs);

// It is important that this is done after the webpack yargs config,
// so it overrides webpack's version info.
Expand Down Expand Up @@ -220,7 +230,7 @@ yargs.options({
});

const argv = yargs.argv;
const wpOpt = require('webpack/bin/convert-argv')(yargs, argv, {
const wpOpt = require('webpack-cli/bin/convert-argv')(yargs, argv, {
outputFilename: '/bundle.js'
});

Expand Down
8 changes: 2 additions & 6 deletions client-src/default/webpack.config.js
@@ -1,8 +1,7 @@
'use strict';

const UglifyJSPlugin = require('uglifyjs-webpack-plugin');

module.exports = {
mode: 'production',
module: {
rules: [
{
Expand All @@ -15,8 +14,5 @@ module.exports = {
]
}
]
},
plugins: [
new UglifyJSPlugin()
]
}
};
2 changes: 1 addition & 1 deletion client-src/live/index.js
Expand Up @@ -11,7 +11,7 @@ let hot = false;
let currentHash = '';

$(() => {
$('body').html(require('./page.pug')());
$('body').html(require('./page.html')());
const status = $('#status');
const okness = $('#okness');
const $errors = $('#errors');
Expand Down
7 changes: 7 additions & 0 deletions client-src/live/page.html
@@ -0,0 +1,7 @@
<div class="header">
<span id="okness"></span>
<span id="status"></span>
</div>
<pre id="errors"></pre>
<div id="warnings"></div>
<iframe id="iframe" src="javascript:;" allowfullscreen="allowfullscreen"></iframe>
7 changes: 0 additions & 7 deletions client-src/live/page.pug

This file was deleted.

9 changes: 3 additions & 6 deletions client-src/live/webpack.config.js
@@ -1,10 +1,10 @@
'use strict';

const path = require('path');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');

module.exports = {
mode: 'production',
module: {
rules: [
{
Expand All @@ -17,10 +17,8 @@ module.exports = {
]
},
{
test: /\.pug$/,
use: [
'pug-loader?self'
]
test: /\.html$/,
use: ['html-loader']
},
{
test: /\.css$/,
Expand All @@ -32,7 +30,6 @@ module.exports = {
]
},
plugins: [
new UglifyJSPlugin(),
new CopyPlugin([{
from: path.resolve(__dirname, 'live.html'),
to: path.resolve(__dirname, '../../client/live.html')
Expand Down
9 changes: 2 additions & 7 deletions client-src/sockjs/webpack.config.js
@@ -1,14 +1,9 @@
'use strict';

// eslint-disable-next-line
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');

module.exports = {
mode: 'production',
output: {
library: 'SockJS',
libraryTarget: 'umd'
},
plugins: [
new UglifyJSPlugin()
]
}
};
2 changes: 1 addition & 1 deletion examples/api/middleware/webpack.config.js
Expand Up @@ -6,7 +6,7 @@ const { setup } = require('../../util');

module.exports = setup({
context: __dirname,
entry: ['./app.js', '../../client/index.js?http://localhost:8080/'],
entry: ['./app.js', '../../../client/index.js?http://localhost:8080/'],
output: {
filename: 'bundle.js'
}
Expand Down
2 changes: 1 addition & 1 deletion examples/util.js
Expand Up @@ -10,7 +10,7 @@ const webpack = require('webpack');

module.exports = {
setup(config) {
const defaults = { plugins: [], devServer: {} };
const defaults = { mode: 'development', plugins: [], devServer: {} };
const result = Object.assign(defaults, config);
const before = function before(app) {
app.get('/.assets/*', (req, res) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/optionsSchema.json
Expand Up @@ -303,7 +303,7 @@
"description": "Customize what the console displays when compiling.",
"instanceof": "Function"
},
"reportTime": {
"logTime": {
"description": "Report time before and after compiling in console displays.",
"type": "boolean"
},
Expand Down
22 changes: 14 additions & 8 deletions lib/util/addDevServerEntrypoints.js
Expand Up @@ -19,16 +19,22 @@ module.exports = function addDevServerEntrypoints(webpackOptions, devServerOptio

if (devServerOptions.hotOnly) { devClient.push('webpack/hot/only-dev-server'); } else if (devServerOptions.hot) { devClient.push('webpack/hot/dev-server'); }

[].concat(webpackOptions).forEach((wpOpt) => {
if (typeof wpOpt.entry === 'object' && !Array.isArray(wpOpt.entry)) {
Object.keys(wpOpt.entry).forEach((key) => {
wpOpt.entry[key] = devClient.concat(wpOpt.entry[key]);
const prependDevClient = (entry) => {
if (typeof entry === 'function') {
return () => Promise.resolve(entry()).then(prependDevClient);
}
if (typeof entry === 'object' && !Array.isArray(entry)) {
const entryClone = {};
Object.keys(entry).forEach((key) => {
entryClone[key] = devClient.concat(entry[key]);
});
} else if (typeof wpOpt.entry === 'function') {
wpOpt.entry = wpOpt.entry(devClient);
} else {
wpOpt.entry = devClient.concat(wpOpt.entry);
return entryClone;
}
return devClient.concat(entry);
};

[].concat(webpackOptions).forEach((wpOpt) => {
wpOpt.entry = prependDevClient(wpOpt.entry || './src');
});
}
};

0 comments on commit 7378e3e

Please sign in to comment.