From 8e8808993c4c7a6b65250fbd543d5d31af58d127 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Sat, 16 May 2020 16:41:03 +0200 Subject: [PATCH] packages/cli: split bundle loaders into separate module --- packages/cli/src/lib/bundle/config.ts | 40 +----------------- packages/cli/src/lib/bundle/loaders.ts | 58 ++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 38 deletions(-) create mode 100644 packages/cli/src/lib/bundle/loaders.ts diff --git a/packages/cli/src/lib/bundle/config.ts b/packages/cli/src/lib/bundle/config.ts index 277a5d6684..11b9e7aa2f 100644 --- a/packages/cli/src/lib/bundle/config.ts +++ b/packages/cli/src/lib/bundle/config.ts @@ -19,6 +19,7 @@ import HtmlWebpackPlugin from 'html-webpack-plugin'; import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'; import ModuleScopePlugin from 'react-dev-utils/ModuleScopePlugin'; import { BundlingPaths } from './paths'; +import { loaders } from './loaders'; // import checkRequiredFiles from 'react-dev-utils/checkRequiredFiles'; // import ModuleNotFoundPlugin from 'react-dev-utils/ModuleNotFoundPlugin'; // import errorOverlayMiddleware from 'react-dev-utils/errorOverlayMiddleware'; @@ -53,44 +54,7 @@ export function createConfig(options: BundlingOptions): webpack.Configuration { }, }, module: { - rules: [ - { - test: /\.(tsx?)$/, - exclude: /node_modules/, - loader: '@sucrase/webpack-loader', - options: { - transforms: ['typescript', 'jsx', 'react-hot-loader'], - }, - }, - { - test: /\.(jsx?|mjs)$/, - exclude: /node_modules/, - loader: '@sucrase/webpack-loader', - options: { - transforms: ['jsx', 'react-hot-loader'], - }, - }, - { - test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/, /\.frag/, /\.xml/], - loader: 'url-loader', - options: { - limit: 10000, - name: 'static/media/[name].[hash:8].[ext]', - }, - }, - { - test: /\.ya?ml$/, - use: 'yml-loader', - }, - { - include: /\.(md)$/, - use: 'raw-loader', - }, - { - test: /\.css$/i, - use: ['style-loader', 'css-loader'], - }, - ], + rules: loaders(), }, output: { publicPath: '/', diff --git a/packages/cli/src/lib/bundle/loaders.ts b/packages/cli/src/lib/bundle/loaders.ts new file mode 100644 index 0000000000..173776272a --- /dev/null +++ b/packages/cli/src/lib/bundle/loaders.ts @@ -0,0 +1,58 @@ +/* + * 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. + */ + +import { Module } from 'webpack'; + +export const loaders = (): Module['rules'] => { + return [ + { + test: /\.(tsx?)$/, + exclude: /node_modules/, + loader: '@sucrase/webpack-loader', + options: { + transforms: ['typescript', 'jsx', 'react-hot-loader'], + }, + }, + { + test: /\.(jsx?|mjs)$/, + exclude: /node_modules/, + loader: '@sucrase/webpack-loader', + options: { + transforms: ['jsx', 'react-hot-loader'], + }, + }, + { + test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/, /\.frag/, /\.xml/], + loader: 'url-loader', + options: { + limit: 10000, + name: 'static/media/[name].[hash:8].[ext]', + }, + }, + { + test: /\.ya?ml$/, + use: 'yml-loader', + }, + { + include: /\.(md)$/, + use: 'raw-loader', + }, + { + test: /\.css$/i, + use: ['style-loader', 'css-loader'], + }, + ]; +};