Skip to content
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

feat: serve integration #1712

Merged
merged 25 commits into from Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6d67bec
feat: add serve to webpack-cli
rishabh3112 Jul 31, 2020
3a50303
tests: add basic integartion tests
rishabh3112 Jul 31, 2020
a4e46d2
chore: update path
rishabh3112 Jul 31, 2020
f600956
chore: check dev-server
rishabh3112 Aug 2, 2020
7746ece
chore: fix lint
rishabh3112 Aug 2, 2020
6bfbaa5
Merge branch 'next' into feat/serve-integration
rishabh3112 Aug 2, 2020
e6b2226
chore: lint package json
rishabh3112 Aug 2, 2020
19c65d7
Merge branch 'feat/serve-integration' of https://github.com/webpack/w…
rishabh3112 Aug 2, 2020
c387a85
Merge branch 'next' into feat/serve-integration
rishabh3112 Aug 6, 2020
233e7c8
chore: add check in serve itself
rishabh3112 Aug 6, 2020
4de1ab3
chore: add error handling into the package
rishabh3112 Aug 10, 2020
bb4a8cc
chore: add error handling into the package
rishabh3112 Aug 10, 2020
359796f
Merge branch 'next' into feat/serve-integration
rishabh3112 Aug 10, 2020
4f6e559
chore: shift import location
rishabh3112 Aug 10, 2020
5a7e513
Merge branch 'feat/serve-integration' of https://github.com/webpack/w…
rishabh3112 Aug 10, 2020
6bb75d3
chore: remove redundant error handling
rishabh3112 Aug 10, 2020
5ed3f0b
chore: early return on windows
rishabh3112 Aug 13, 2020
c18d6eb
chore: add dummy tests
rishabh3112 Aug 13, 2020
cdf8be2
Merge branch 'next' into feat/serve-integration
rishabh3112 Aug 13, 2020
39a0601
Merge branch 'next' into feat/serve-integration
snitin315 Aug 14, 2020
7431ec6
chore: ignore integration test
rishabh3112 Aug 16, 2020
55867d5
Merge branch 'feat/serve-integration' of https://github.com/webpack/w…
rishabh3112 Aug 16, 2020
9185904
chore: add integration test
rishabh3112 Aug 16, 2020
5534914
chore: update tests
rishabh3112 Aug 16, 2020
af9fdb7
chore: skip test on windows
rishabh3112 Aug 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 42 additions & 7 deletions packages/serve/src/index.ts
@@ -1,10 +1,45 @@
// Test dev-server availability before importing it
import WebpackCLI from 'webpack-cli';
import logger from 'webpack-cli/lib/utils/logger';
import startDevServer from './startDevServer';

let devServerFlags: object[];
try {
// eslint-disable-next-line node/no-extraneous-require
require.resolve('webpack-dev-server');
} catch (error) {
throw new Error(`You need to install 'webpack-dev-server' for running 'webpack serve'.\n${error}`);
devServerFlags = require('webpack-dev-server/bin/cli-flags').devServer;
} catch (err) {
throw new Error(`You need to install 'webpack-dev-server' for running 'webpack serve'.\n${err}`);
rishabh3112 marked this conversation as resolved.
Show resolved Hide resolved
}

import serve from './serve';
export default serve;
/**
*
* Creates a webpack compiler and runs the devServer
*
* @param {String[]} args - args processed from the CLI
* @returns {Function} invokes the devServer API
*/
export default function serve(...args: string[]): void {
const cli = new WebpackCLI();
const core = cli.getCoreFlags();

const parsedDevServerArgs = cli.argParser(devServerFlags, args, true);
const devServerArgs = parsedDevServerArgs.opts;
const parsedWebpackArgs = cli.argParser(core, parsedDevServerArgs.unknownArgs, true, process.title);
const webpackArgs = parsedWebpackArgs.opts;

// pass along the 'hot' argument to the dev server if it exists
if (webpackArgs && webpackArgs.hot !== undefined) {
devServerArgs['hot'] = webpackArgs.hot;
}

if (parsedWebpackArgs.unknownArgs.length > 0) {
parsedWebpackArgs.unknownArgs
.filter((e) => e)
.forEach((unknown) => {
logger.warn('Unknown argument:', unknown);
});
return;
}

cli.getCompiler(webpackArgs, core).then((compiler): void => {
startDevServer(compiler, devServerArgs);
});
}
39 changes: 0 additions & 39 deletions packages/serve/src/serve.ts

This file was deleted.

8 changes: 7 additions & 1 deletion packages/serve/src/startDevServer.ts
@@ -1,4 +1,10 @@
import Server from 'webpack-dev-server/lib/Server';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let Server: any;
try {
Server = require('webpack-dev-server/lib/Server');
} catch (err) {
throw new Error(`You need to install 'webpack-dev-server' for running 'webpack serve'.\n${err}`);
}

/**
*
Expand Down