packages/cli: move plugin serve config into lib
This commit is contained in:
+2
-2
@@ -14,8 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { startDevServer } from './server';
|
||||
import { watchDeps } from '../../../lib/watchDeps';
|
||||
import { startDevServer } from '../../lib/bundle';
|
||||
import { watchDeps } from '../../lib/watchDeps';
|
||||
|
||||
export default async () => {
|
||||
await watchDeps({ build: true });
|
||||
+8
-2
@@ -18,14 +18,20 @@ import webpack from 'webpack';
|
||||
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
||||
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
|
||||
import ModuleScopePlugin from 'react-dev-utils/ModuleScopePlugin';
|
||||
import { Paths } from './paths';
|
||||
import { BundlingPaths } from './paths';
|
||||
// import checkRequiredFiles from 'react-dev-utils/checkRequiredFiles';
|
||||
// import ModuleNotFoundPlugin from 'react-dev-utils/ModuleNotFoundPlugin';
|
||||
// import errorOverlayMiddleware from 'react-dev-utils/errorOverlayMiddleware';
|
||||
// import evalSourceMapMiddleware from 'react-dev-utils/evalSourceMapMiddleware';
|
||||
// import WatchMissingNodeModulesPlugin from 'react-dev-utils/WatchMissingNodeModulesPlugin';
|
||||
|
||||
export function createConfig(paths: Paths): webpack.Configuration {
|
||||
type BundlingOptions = {
|
||||
paths: BundlingPaths;
|
||||
};
|
||||
|
||||
export function createConfig(options: BundlingOptions): webpack.Configuration {
|
||||
const { paths } = options;
|
||||
|
||||
return {
|
||||
mode: 'development',
|
||||
profile: false,
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2020 Spotify AB
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export * from './server';
|
||||
+3
-3
@@ -15,9 +15,9 @@
|
||||
*/
|
||||
|
||||
import { existsSync } from 'fs';
|
||||
import { paths } from '../../../lib/paths';
|
||||
import { paths } from '../paths';
|
||||
|
||||
export function getPaths() {
|
||||
export function resolveBundlingPaths() {
|
||||
const resolveTargetModule = (path: string) => {
|
||||
for (const ext of ['mjs', 'js', 'ts', 'tsx', 'jsx']) {
|
||||
const filePath = paths.resolveTarget(`${path}.${ext}`);
|
||||
@@ -46,4 +46,4 @@ export function getPaths() {
|
||||
};
|
||||
}
|
||||
|
||||
export type Paths = ReturnType<typeof getPaths>;
|
||||
export type BundlingPaths = ReturnType<typeof resolveBundlingPaths>;
|
||||
+3
-3
@@ -18,7 +18,7 @@ import webpack from 'webpack';
|
||||
import WebpackDevServer from 'webpack-dev-server';
|
||||
import openBrowser from 'react-dev-utils/openBrowser';
|
||||
import { choosePort, prepareUrls } from 'react-dev-utils/WebpackDevServerUtils';
|
||||
import { getPaths } from './paths';
|
||||
import { resolveBundlingPaths } from './paths';
|
||||
import { createConfig } from './config';
|
||||
|
||||
export async function startDevServer() {
|
||||
@@ -33,8 +33,8 @@ export async function startDevServer() {
|
||||
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
|
||||
const urls = prepareUrls(protocol, host, port);
|
||||
|
||||
const paths = getPaths();
|
||||
const config = createConfig(paths);
|
||||
const paths = resolveBundlingPaths();
|
||||
const config = createConfig({ paths });
|
||||
const compiler = webpack(config);
|
||||
const server = new WebpackDevServer(compiler, {
|
||||
hot: true,
|
||||
Reference in New Issue
Block a user