diff --git a/packages/cli/src/commands/plugin/serve/index.ts b/packages/cli/src/commands/plugin/serve.ts similarity index 88% rename from packages/cli/src/commands/plugin/serve/index.ts rename to packages/cli/src/commands/plugin/serve.ts index 9bdd46dc84..fb95d5e02b 100644 --- a/packages/cli/src/commands/plugin/serve/index.ts +++ b/packages/cli/src/commands/plugin/serve.ts @@ -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 }); diff --git a/packages/cli/src/commands/plugin/serve/config.ts b/packages/cli/src/lib/bundle/config.ts similarity index 94% rename from packages/cli/src/commands/plugin/serve/config.ts rename to packages/cli/src/lib/bundle/config.ts index 47d7918270..b802712a52 100644 --- a/packages/cli/src/commands/plugin/serve/config.ts +++ b/packages/cli/src/lib/bundle/config.ts @@ -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, diff --git a/packages/cli/src/lib/bundle/index.ts b/packages/cli/src/lib/bundle/index.ts new file mode 100644 index 0000000000..e304e1d00d --- /dev/null +++ b/packages/cli/src/lib/bundle/index.ts @@ -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'; diff --git a/packages/cli/src/commands/plugin/serve/paths.ts b/packages/cli/src/lib/bundle/paths.ts similarity index 91% rename from packages/cli/src/commands/plugin/serve/paths.ts rename to packages/cli/src/lib/bundle/paths.ts index 56c3f6ffb7..d98f7ed5de 100644 --- a/packages/cli/src/commands/plugin/serve/paths.ts +++ b/packages/cli/src/lib/bundle/paths.ts @@ -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; +export type BundlingPaths = ReturnType; diff --git a/packages/cli/src/commands/plugin/serve/server.ts b/packages/cli/src/lib/bundle/server.ts similarity index 92% rename from packages/cli/src/commands/plugin/serve/server.ts rename to packages/cli/src/lib/bundle/server.ts index 066f741406..2dcd3b3a8a 100644 --- a/packages/cli/src/commands/plugin/serve/server.ts +++ b/packages/cli/src/lib/bundle/server.ts @@ -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,