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

Webpack: Support .cjs extension #18502

Merged
merged 4 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ const newWebpackConfiguration = (
rules: [{ keepBaseRule: true } as any],
},
resolve: {
extensions: ['.mjs', '.js', '.jsx', '.ts', '.tsx', '.json', '.cjs'],
extensions: ['.cjs', '.mjs', '.js', '.jsx', '.ts', '.tsx', '.json'],
ddalpange marked this conversation as resolved.
Show resolved Hide resolved
modules: ['node_modules'],
mainFields: ['browser', 'main'],
alias: {
Expand Down
2 changes: 1 addition & 1 deletion app/react/src/server/framework-preset-react-docs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('framework-preset-react-docgen', () => {
presets: ['env', 'foo-preset'],
overrides: [
{
test: /\.(mjs|tsx?|jsx?)$/,
test: /\.(cjs|mjs|tsx?|jsx?)$/,
plugins: [
[
babelPluginReactDocgenPath,
Expand Down
2 changes: 1 addition & 1 deletion app/react/src/server/framework-preset-react-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function babel(config: TransformOptions, options: Options) {
overrides: [
...(config?.overrides || []),
{
test: reactDocgen === 'react-docgen' ? /\.(mjs|tsx?|jsx?)$/ : /\.(mjs|jsx?)$/,
test: reactDocgen === 'react-docgen' ? /\.(cjs|mjs|tsx?|jsx?)$/ : /\.(cjs|mjs|jsx?)$/,
plugins: [
[
require.resolve('babel-plugin-react-docgen'),
Expand Down
2 changes: 1 addition & 1 deletion lib/builder-webpack4/src/preview/babel-loader-preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getProjectRoot } from '@storybook/core-common';
import { useBaseTsSupport } from './useBaseTsSupport';

export const createBabelLoader = (options: any, framework: string) => ({
test: useBaseTsSupport(framework) ? /\.(mjs|tsx?|jsx?)$/ : /\.(mjs|jsx?)$/,
test: useBaseTsSupport(framework) ? /\.(cjs|mjs|tsx?|jsx?)$/ : /\.(cjs|mjs|jsx?)$/,
use: [
{
loader: require.resolve('babel-loader'),
Expand Down
2 changes: 1 addition & 1 deletion lib/builder-webpack4/src/preview/iframe-webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export default async (options: Options & Record<string, any>): Promise<Configura
],
},
resolve: {
extensions: ['.mjs', '.js', '.jsx', '.ts', '.tsx', '.json', '.cjs'],
extensions: ['.cjs', '.mjs', '.js', '.jsx', '.ts', '.tsx', '.json'],
ddalpange marked this conversation as resolved.
Show resolved Hide resolved
modules: ['node_modules'].concat(envs.NODE_PATH || []),
mainFields: [modern ? 'sbmodern' : null, 'browser', 'module', 'main'].filter(Boolean),
alias: {
Expand Down
2 changes: 1 addition & 1 deletion lib/builder-webpack5/src/preview/babel-loader-preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const useBaseTsSupport = (framework: string) => {
};

export const createBabelLoader = (options: any, framework: string) => ({
test: useBaseTsSupport(framework) ? /\.(mjs|tsx?|jsx?)$/ : /\.(mjs|jsx?)$/,
test: useBaseTsSupport(framework) ? /\.(cjs|mjs|tsx?|jsx?)$/ : /\.(cjs|mjs|jsx?)$/,
use: [
{
loader: require.resolve('babel-loader'),
Expand Down
2 changes: 1 addition & 1 deletion lib/builder-webpack5/src/preview/iframe-webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export default async (options: Options & Record<string, any>): Promise<Configura
],
},
resolve: {
extensions: ['.mjs', '.js', '.jsx', '.ts', '.tsx', '.json', '.cjs'],
extensions: ['.cjs', '.mjs', '.js', '.jsx', '.ts', '.tsx', '.json', '.cjs'],
ddalpange marked this conversation as resolved.
Show resolved Hide resolved
modules: ['node_modules'].concat(envs.NODE_PATH || []),
mainFields: [modern ? 'sbmodern' : null, 'browser', 'module', 'main'].filter(Boolean),
alias: {
Expand Down
2 changes: 1 addition & 1 deletion lib/manager-webpack4/src/presets/babel-loader-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const babelLoader = () => {
const { plugins, presets } = getStorybookBabelConfig();

return {
test: /\.(mjs|tsx?|jsx?)$/,
test: /\.(cjs|mjs|tsx?|jsx?)$/,
use: [
{
loader: require.resolve('babel-loader'),
Expand Down
2 changes: 1 addition & 1 deletion lib/manager-webpack4/src/presets/manager-preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export async function managerWebpack(
],
},
resolve: {
extensions: ['.mjs', '.js', '.jsx', '.json', '.cjs', '.ts', '.tsx'],
extensions: ['.cjs', '.mjs', '.js', '.jsx', '.json', '.cjs', '.ts', '.tsx'],
ddalpange marked this conversation as resolved.
Show resolved Hide resolved
modules: ['node_modules'].concat(envs.NODE_PATH || []),
mainFields: [modern ? 'sbmodern' : null, 'browser', 'module', 'main'].filter(Boolean),
alias: {
Expand Down
2 changes: 1 addition & 1 deletion lib/manager-webpack5/src/presets/babel-loader-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const babelLoader = () => {
const { plugins, presets } = getStorybookBabelConfig();

return {
test: /\.(mjs|tsx?|jsx?)$/,
test: /\.(cjs|mjs|tsx?|jsx?)$/,
use: [
{
loader: require.resolve('babel-loader'),
Expand Down
2 changes: 1 addition & 1 deletion lib/manager-webpack5/src/presets/manager-preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export async function managerWebpack(
],
},
resolve: {
extensions: ['.mjs', '.js', '.jsx', '.json', '.cjs', '.ts', '.tsx'],
extensions: ['.cjs', '.mjs', '.js', '.jsx', '.json', '.cjs', '.ts', '.tsx'],
ddalpange marked this conversation as resolved.
Show resolved Hide resolved
modules: ['node_modules'].concat(envs.NODE_PATH || []),
mainFields: [modern ? 'sbmodern' : null, 'browser', 'module', 'main'].filter(Boolean),
alias: {
Expand Down