@teambit/react 0.0.568 → 0.0.572
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compositions-app.tsx +31 -0
- package/highlighter-widget.tsx +19 -0
- package/mount.tsx +17 -0
- package/package-tar/teambit-react-0.0.572.tgz +0 -0
- package/package.json +44 -59
- package/react.composition.tsx +7 -0
- package/react.ui.runtime.tsx +35 -0
- package/templates/react-app/files/app-root.ts +10 -0
- package/templates/react-app/files/app.ts +30 -0
- package/templates/react-app/files/aspect.ts +10 -0
- package/templates/react-app/files/compositions.ts +11 -0
- package/templates/react-app/files/doc.ts +29 -0
- package/templates/react-app/files/index.ts +10 -0
- package/templates/react-app/files/main.runtime.ts +22 -0
- package/templates/react-app/index.ts +47 -0
- package/templates/react-component/files/component.ts +25 -0
- package/templates/react-component/files/composition.ts +16 -0
- package/templates/react-component/files/docs.ts +32 -0
- package/templates/react-component/files/test.ts +19 -0
- package/templates/react-component/index.ts +40 -0
- package/templates/react-component-js/files/component.ts +18 -0
- package/templates/react-component-js/files/composition.ts +16 -0
- package/templates/react-component-js/files/docs.ts +32 -0
- package/templates/react-component-js/files/test.ts +21 -0
- package/templates/react-component-js/index.ts +38 -0
- package/templates/react-context/files/composition.ts +27 -0
- package/templates/react-context/files/context-provider.ts +27 -0
- package/templates/react-context/files/context.ts +21 -0
- package/templates/react-context/files/docs.ts +51 -0
- package/templates/react-context/files/test.ts +18 -0
- package/templates/react-context/index.ts +32 -0
- package/templates/react-env/files/aspect.ts +10 -0
- package/templates/react-env/files/doc.ts +163 -0
- package/templates/react-env/files/index.ts +10 -0
- package/templates/react-env/files/jest.config.ts +21 -0
- package/templates/react-env/files/main.runtime.ts +84 -0
- package/templates/react-env/files/preview.runtime.ts +27 -0
- package/templates/react-env/files/typescript.config.ts +21 -0
- package/templates/react-env/files/webpack.config.ts +48 -0
- package/templates/react-env/index.ts +51 -0
- package/templates/react-hook/files/component.ts +16 -0
- package/templates/react-hook/files/composition.ts +23 -0
- package/templates/react-hook/files/docs.ts +33 -0
- package/templates/react-hook/files/test.ts +20 -0
- package/templates/react-hook/index.ts +21 -0
- package/templates/react-workspace/index.ts +27 -0
- package/templates/react-workspace-app/index.ts +20 -0
- package/templates/react-workspace-deprecated/index.ts +28 -0
- package/templates/react-workspace-lib/index.ts +21 -0
- package/templates/workspace-common/files/eslint-config.ts +6 -0
- package/templates/workspace-common/files/git-ignore.ts +113 -0
- package/templates/workspace-common/files/prettier-config.ts +5 -0
- package/templates/workspace-common/files/readme-file.ts +36 -0
- package/templates/workspace-common/files/ts-config.ts +7 -0
- package/templates/workspace-common/files/types/asset.ts +28 -0
- package/templates/workspace-common/files/types/style.ts +43 -0
- package/templates/workspace-common/files/workspace-config.ts +58 -0
- package/templates/workspace-common/generate-files.ts +51 -0
- package/templates/workspace-common/index.ts +1 -0
- package/types/asset.d.ts +29 -0
- package/types/style.d.ts +42 -0
- package/typescript/asset.d.ts +29 -0
- package/typescript/style.d.ts +42 -0
- package/webpack/postcss.config.ts +21 -0
- package/webpack/webpack.config.base.prod.ts +123 -0
- package/webpack/webpack.config.base.ts +365 -0
- package/webpack/webpack.config.component.dev.ts +99 -0
- package/webpack/webpack.config.component.prod.ts +39 -0
- package/webpack/webpack.config.env.dev.ts +21 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
declare module '*.module.css' {
|
|
2
|
+
const classes: { readonly [key: string]: string };
|
|
3
|
+
export default classes;
|
|
4
|
+
}
|
|
5
|
+
declare module '*.module.scss' {
|
|
6
|
+
const classes: { readonly [key: string]: string };
|
|
7
|
+
export default classes;
|
|
8
|
+
}
|
|
9
|
+
declare module '*.module.sass' {
|
|
10
|
+
const classes: { readonly [key: string]: string };
|
|
11
|
+
export default classes;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare module '*.module.less' {
|
|
15
|
+
const classes: { readonly [key: string]: string };
|
|
16
|
+
export default classes;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
declare module '*.less' {
|
|
20
|
+
const classes: { readonly [key: string]: string };
|
|
21
|
+
export default classes;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare module '*.css' {
|
|
25
|
+
const classes: { readonly [key: string]: string };
|
|
26
|
+
export default classes;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
declare module '*.sass' {
|
|
30
|
+
const classes: { readonly [key: string]: string };
|
|
31
|
+
export default classes;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare module '*.scss' {
|
|
35
|
+
const classes: { readonly [key: string]: string };
|
|
36
|
+
export default classes;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
declare module '*.mdx' {
|
|
40
|
+
const component: any;
|
|
41
|
+
export default component;
|
|
42
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
|
|
2
|
+
export const postCssConfig = {
|
|
3
|
+
// Necessary for external CSS imports to work
|
|
4
|
+
// https://github.com/facebook/create-react-app/issues/2677
|
|
5
|
+
ident: 'postcss',
|
|
6
|
+
plugins: [
|
|
7
|
+
// eslint-disable-next-line global-require
|
|
8
|
+
require.resolve('postcss-flexbugs-fixes'),
|
|
9
|
+
// eslint-disable-next-line global-require
|
|
10
|
+
require('postcss-preset-env')({
|
|
11
|
+
autoprefixer: {
|
|
12
|
+
flexbox: 'no-2009',
|
|
13
|
+
},
|
|
14
|
+
stage: 3,
|
|
15
|
+
}),
|
|
16
|
+
// Adds PostCSS Normalize as the reset css with default options,
|
|
17
|
+
// so that it honors browserslist config in package.json
|
|
18
|
+
// which in turn let's users customize the target behavior as per their needs.
|
|
19
|
+
require.resolve('postcss-normalize'),
|
|
20
|
+
],
|
|
21
|
+
};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import WorkboxWebpackPlugin from 'workbox-webpack-plugin';
|
|
2
|
+
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
|
|
3
|
+
import TerserPlugin from 'terser-webpack-plugin';
|
|
4
|
+
import { Configuration } from 'webpack';
|
|
5
|
+
import { WebpackManifestPlugin } from 'webpack-manifest-plugin';
|
|
6
|
+
|
|
7
|
+
// This is the production and development configuration.
|
|
8
|
+
// It is focused on developer experience, fast rebuilds, and a minimal bundle.
|
|
9
|
+
// eslint-disable-next-line complexity
|
|
10
|
+
export default function (): Configuration {
|
|
11
|
+
return {
|
|
12
|
+
optimization: {
|
|
13
|
+
minimize: true,
|
|
14
|
+
minimizer: [
|
|
15
|
+
// This is only used in production mode
|
|
16
|
+
new TerserPlugin({
|
|
17
|
+
terserOptions: {
|
|
18
|
+
parse: {
|
|
19
|
+
// We want terser to parse ecma 8 code. However, we don't want it
|
|
20
|
+
// to apply any minification steps that turns valid ecma 5 code
|
|
21
|
+
// into invalid ecma 5 code. This is why the 'compress' and 'output'
|
|
22
|
+
// sections only apply transformations that are ecma 5 safe
|
|
23
|
+
// https://github.com/facebook/create-react-app/pull/4234
|
|
24
|
+
ecma: 8,
|
|
25
|
+
},
|
|
26
|
+
compress: {
|
|
27
|
+
ecma: 5,
|
|
28
|
+
warnings: false,
|
|
29
|
+
// Disabled because of an issue with Uglify breaking seemingly valid code:
|
|
30
|
+
// https://github.com/facebook/create-react-app/issues/2376
|
|
31
|
+
// Pending further investigation:
|
|
32
|
+
// https://github.com/mishoo/UglifyJS2/issues/2011
|
|
33
|
+
comparisons: false,
|
|
34
|
+
// Disabled because of an issue with Terser breaking valid code:
|
|
35
|
+
// https://github.com/facebook/create-react-app/issues/5250
|
|
36
|
+
// Pending further investigation:
|
|
37
|
+
// https://github.com/terser-js/terser/issues/120
|
|
38
|
+
inline: 2,
|
|
39
|
+
},
|
|
40
|
+
mangle: {
|
|
41
|
+
safari10: true,
|
|
42
|
+
},
|
|
43
|
+
output: {
|
|
44
|
+
ecma: 5,
|
|
45
|
+
comments: false,
|
|
46
|
+
// Turned on because emoji and regex is not minified properly using default
|
|
47
|
+
// https://github.com/facebook/create-react-app/issues/2488
|
|
48
|
+
ascii_only: true,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
}),
|
|
52
|
+
new CssMinimizerPlugin({
|
|
53
|
+
minimizerOptions: {
|
|
54
|
+
preset: [
|
|
55
|
+
'default',
|
|
56
|
+
{
|
|
57
|
+
minifyFontValues: { removeQuotes: false },
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
}),
|
|
62
|
+
],
|
|
63
|
+
// Automatically split vendor and commons
|
|
64
|
+
// https://twitter.com/wSokra/status/969633336732905474
|
|
65
|
+
// https://medium.com/webpack/webpack-4-code-splitting-chunk-graph-and-the-splitchunks-optimization-be739a861366
|
|
66
|
+
splitChunks: {
|
|
67
|
+
chunks: 'all',
|
|
68
|
+
// name: false,
|
|
69
|
+
},
|
|
70
|
+
// Keep the runtime chunk separated to enable long term caching
|
|
71
|
+
// https://twitter.com/wSokra/status/969679223278505985
|
|
72
|
+
// https://github.com/facebook/create-react-app/issues/5358
|
|
73
|
+
runtimeChunk: {
|
|
74
|
+
name: (entrypoint) => `runtime-${entrypoint.name}`,
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
plugins: [
|
|
79
|
+
// Generate an asset manifest file with the following content:
|
|
80
|
+
// - "files" key: Mapping of all asset filenames to their corresponding
|
|
81
|
+
// output file so that tools can pick it up without having to parse
|
|
82
|
+
// `index.html`
|
|
83
|
+
// can be used to reconstruct the HTML if necessary
|
|
84
|
+
new WebpackManifestPlugin({
|
|
85
|
+
fileName: 'asset-manifest.json',
|
|
86
|
+
publicPath: 'public',
|
|
87
|
+
generate: (seed, files, entrypoints) => {
|
|
88
|
+
const manifestFiles = files.reduce((manifest, file) => {
|
|
89
|
+
manifest[file.name] = file.path;
|
|
90
|
+
return manifest;
|
|
91
|
+
}, seed);
|
|
92
|
+
const entrypointFiles = entrypoints.main.filter((fileName) => !fileName.endsWith('.map'));
|
|
93
|
+
|
|
94
|
+
// @ts-ignore - https://github.com/shellscape/webpack-manifest-plugin/issues/276
|
|
95
|
+
return {
|
|
96
|
+
files: manifestFiles,
|
|
97
|
+
entrypoints: entrypointFiles,
|
|
98
|
+
} as Record<string, string>;
|
|
99
|
+
},
|
|
100
|
+
}),
|
|
101
|
+
// Generate a service worker script that will precache, and keep up to date,
|
|
102
|
+
// the HTML & assets that are part of the webpack build.
|
|
103
|
+
new WorkboxWebpackPlugin.GenerateSW({
|
|
104
|
+
clientsClaim: true,
|
|
105
|
+
exclude: [/\.map$/, /asset-manifest\.json$/],
|
|
106
|
+
// importWorkboxFrom: 'cdn',
|
|
107
|
+
navigateFallback: 'public/index.html',
|
|
108
|
+
navigateFallbackDenylist: [
|
|
109
|
+
// Exclude URLs starting with /_, as they're likely an API call
|
|
110
|
+
new RegExp('^/_'),
|
|
111
|
+
// Exclude any URLs whose last part seems to be a file extension
|
|
112
|
+
// as they're likely a resource and not a SPA route.
|
|
113
|
+
// URLs containing a "?" character won't be blacklisted as they're likely
|
|
114
|
+
// a route with query params (e.g. auth callbacks).
|
|
115
|
+
new RegExp('/[^/?]+\\.[^/]+$'),
|
|
116
|
+
],
|
|
117
|
+
}),
|
|
118
|
+
].filter(Boolean),
|
|
119
|
+
// Turn off performance processing because we utilize
|
|
120
|
+
// our own hints via the FileSizeReporter
|
|
121
|
+
performance: false,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
import { merge } from 'lodash';
|
|
2
|
+
import 'style-loader';
|
|
3
|
+
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
|
4
|
+
import getCSSModuleLocalIdent from 'react-dev-utils/getCSSModuleLocalIdent';
|
|
5
|
+
import { Configuration, IgnorePlugin } from 'webpack';
|
|
6
|
+
import * as stylesRegexps from '@teambit/webpack.modules.style-regexps';
|
|
7
|
+
import { generateStyleLoaders } from '@teambit/webpack.modules.generate-style-loaders';
|
|
8
|
+
import { postCssConfig } from './postcss.config';
|
|
9
|
+
// Make sure the bit-react-transformer is a dependency
|
|
10
|
+
// TODO: remove it once we can set policy from component to component then set it via the component.json
|
|
11
|
+
import '@teambit/react.babel.bit-react-transformer';
|
|
12
|
+
// Make sure the mdx-loader is a dependency
|
|
13
|
+
import '@teambit/mdx.modules.mdx-loader';
|
|
14
|
+
|
|
15
|
+
const styleLoaderPath = require.resolve('style-loader');
|
|
16
|
+
|
|
17
|
+
const moduleFileExtensions = [
|
|
18
|
+
'web.mjs',
|
|
19
|
+
'mjs',
|
|
20
|
+
'web.js',
|
|
21
|
+
'js',
|
|
22
|
+
'web.ts',
|
|
23
|
+
'ts',
|
|
24
|
+
'web.tsx',
|
|
25
|
+
'tsx',
|
|
26
|
+
'json',
|
|
27
|
+
'web.jsx',
|
|
28
|
+
'jsx',
|
|
29
|
+
'mdx',
|
|
30
|
+
'md',
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
// Source maps are resource heavy and can cause out of memory issue for large source files.
|
|
34
|
+
const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
|
|
35
|
+
|
|
36
|
+
const imageInlineSizeLimit = parseInt(process.env.IMAGE_INLINE_SIZE_LIMIT || '10000');
|
|
37
|
+
|
|
38
|
+
// This is the production and development configuration.
|
|
39
|
+
// It is focused on developer experience, fast rebuilds, and a minimal bundle.
|
|
40
|
+
// eslint-disable-next-line complexity
|
|
41
|
+
export default function (isEnvProduction = false): Configuration {
|
|
42
|
+
// Variable used for enabling profiling in Production
|
|
43
|
+
// passed into alias object. Uses a flag if passed into the build command
|
|
44
|
+
const isEnvProductionProfile = process.argv.includes('--profile');
|
|
45
|
+
|
|
46
|
+
const baseStyleLoadersOptions = {
|
|
47
|
+
injectingLoader: isEnvProduction ? MiniCssExtractPlugin.loader : styleLoaderPath,
|
|
48
|
+
cssLoaderPath: require.resolve('css-loader'),
|
|
49
|
+
postCssLoaderPath: require.resolve('postcss-loader'),
|
|
50
|
+
postCssConfig,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// We will provide `paths.publicUrlOrPath` to our app
|
|
54
|
+
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
|
|
55
|
+
// Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
|
|
56
|
+
// Get environment variables to inject into our app.
|
|
57
|
+
// const env = getClientEnvironment(publicUrlOrPath.slice(0, -1));
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
resolve: {
|
|
61
|
+
// These are the reasonable defaults supported by the Node ecosystem.
|
|
62
|
+
// We also include JSX as a common component filename extension to support
|
|
63
|
+
// some tools, although we do not recommend using it, see:
|
|
64
|
+
// https://github.com/facebook/create-react-app/issues/290
|
|
65
|
+
// `web` extension prefixes have been added for better support
|
|
66
|
+
// for React Native Web.
|
|
67
|
+
extensions: moduleFileExtensions.map((ext) => `.${ext}`),
|
|
68
|
+
|
|
69
|
+
alias: {
|
|
70
|
+
'react/jsx-dev-runtime': require.resolve('react/jsx-dev-runtime.js'),
|
|
71
|
+
'react/jsx-runtime': require.resolve('react/jsx-runtime.js'),
|
|
72
|
+
// Support React Native Web
|
|
73
|
+
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
|
|
74
|
+
// TODO: @uri please remember to remove after publishing evangelist and base-ui
|
|
75
|
+
react: require.resolve('react'),
|
|
76
|
+
'@teambit/mdx.ui.mdx-scope-context': require.resolve('@teambit/mdx.ui.mdx-scope-context'),
|
|
77
|
+
'react-dom/server': require.resolve('react-dom/server'),
|
|
78
|
+
'react-dom': require.resolve('react-dom'),
|
|
79
|
+
'@mdx-js/react': require.resolve('@mdx-js/react'),
|
|
80
|
+
|
|
81
|
+
// Allows for better profiling with ReactDevTools
|
|
82
|
+
...(isEnvProductionProfile && {
|
|
83
|
+
'react-dom$': 'react-dom/profiling',
|
|
84
|
+
'scheduler/tracing': 'scheduler/tracing-profiling',
|
|
85
|
+
}),
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
module: {
|
|
89
|
+
strictExportPresence: true,
|
|
90
|
+
rules: [
|
|
91
|
+
{
|
|
92
|
+
test: /\.m?js/,
|
|
93
|
+
resolve: {
|
|
94
|
+
fullySpecified: false,
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
// "oneOf" will traverse all following loaders until one will
|
|
99
|
+
// match the requirements. When no loader matches it will fall
|
|
100
|
+
// back to the "file" loader at the end of the loader list.
|
|
101
|
+
oneOf: [
|
|
102
|
+
// "postcss" loader applies autoprefixer to our CSS.
|
|
103
|
+
// "css" loader resolves paths in CSS and adds assets as dependencies.
|
|
104
|
+
// "style" loader turns CSS into JS modules that inject <style> tags.
|
|
105
|
+
// In production, we use MiniCSSExtractPlugin to extract that CSS
|
|
106
|
+
// to a file, but in development "style" loader enables hot editing
|
|
107
|
+
// of CSS.
|
|
108
|
+
// By default we support CSS Modules with the extension .module.css
|
|
109
|
+
{
|
|
110
|
+
test: stylesRegexps.cssNoModulesRegex,
|
|
111
|
+
use: generateStyleLoaders(
|
|
112
|
+
merge({}, baseStyleLoadersOptions, {
|
|
113
|
+
cssLoaderOpts: {
|
|
114
|
+
importLoaders: 1,
|
|
115
|
+
sourceMap: isEnvProduction || shouldUseSourceMap,
|
|
116
|
+
},
|
|
117
|
+
})
|
|
118
|
+
),
|
|
119
|
+
// Don't consider CSS imports dead code even if the
|
|
120
|
+
// containing package claims to have no side effects.
|
|
121
|
+
// Remove this when webpack adds a warning or an error for this.
|
|
122
|
+
// See https://github.com/webpack/webpack/issues/6571
|
|
123
|
+
sideEffects: true,
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
// Process application JS with Babel.
|
|
127
|
+
// The preset includes JSX, Flow, TypeScript, and some ESnext features.
|
|
128
|
+
{
|
|
129
|
+
test: /\.(js|mjs|jsx|ts|tsx)$/,
|
|
130
|
+
exclude: [/node_modules/, /\/dist\//],
|
|
131
|
+
// consider: limit loader to files only in a capsule that has bitid in package.json
|
|
132
|
+
// descriptionData: { componentId: ComponentID.isValidObject },
|
|
133
|
+
// // or
|
|
134
|
+
// include: capsulePaths
|
|
135
|
+
loader: require.resolve('babel-loader'),
|
|
136
|
+
options: {
|
|
137
|
+
babelrc: false,
|
|
138
|
+
configFile: false,
|
|
139
|
+
customize: require.resolve('babel-preset-react-app/webpack-overrides'),
|
|
140
|
+
presets: [require.resolve('@babel/preset-react')],
|
|
141
|
+
// This is a feature of `babel-loader` for webpack (not Babel itself).
|
|
142
|
+
// It enables caching results in ./node_modules/.cache/babel-loader/
|
|
143
|
+
// directory for faster rebuilds.
|
|
144
|
+
cacheDirectory: true,
|
|
145
|
+
// See #6846 for context on why cacheCompression is disabled
|
|
146
|
+
cacheCompression: false,
|
|
147
|
+
compact: isEnvProduction,
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
// Process any JS outside of the app with Babel.
|
|
151
|
+
// Unlike the application JS, we only compile the standard ES features.
|
|
152
|
+
// Probably not needed in our use case
|
|
153
|
+
// {
|
|
154
|
+
// test: /\.(js|mjs)$/,
|
|
155
|
+
// exclude: /@babel(?:\/|\\{1,2})runtime/,
|
|
156
|
+
// loader: require.resolve('babel-loader'),
|
|
157
|
+
// options: {
|
|
158
|
+
// babelrc: false,
|
|
159
|
+
// configFile: false,
|
|
160
|
+
// compact: false,
|
|
161
|
+
// presets: [[require.resolve('babel-preset-react-app/dependencies'), { helpers: true }]],
|
|
162
|
+
// cacheDirectory: true,
|
|
163
|
+
// // See #6846 for context on why cacheCompression is disabled
|
|
164
|
+
// cacheCompression: false,
|
|
165
|
+
|
|
166
|
+
// // Babel sourcemaps are needed for debugging into node_modules
|
|
167
|
+
// // code. Without the options below, debuggers like VSCode
|
|
168
|
+
// // show incorrect code and set breakpoints on the wrong lines.
|
|
169
|
+
// sourceMaps: shouldUseSourceMap,
|
|
170
|
+
// inputSourceMap: shouldUseSourceMap,
|
|
171
|
+
// },
|
|
172
|
+
// },
|
|
173
|
+
// MDX support (move to the mdx aspect and extend from there)
|
|
174
|
+
{
|
|
175
|
+
test: /\.mdx?$/,
|
|
176
|
+
exclude: [/node_modules/],
|
|
177
|
+
use: [
|
|
178
|
+
{
|
|
179
|
+
loader: require.resolve('babel-loader'),
|
|
180
|
+
options: {
|
|
181
|
+
babelrc: false,
|
|
182
|
+
configFile: false,
|
|
183
|
+
presets: [require.resolve('@babel/preset-react'), require.resolve('@babel/preset-env')],
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
loader: require.resolve('@teambit/mdx.modules.mdx-loader'),
|
|
188
|
+
},
|
|
189
|
+
],
|
|
190
|
+
},
|
|
191
|
+
// Adds support for CSS Modules (https://github.com/css-modules/css-modules)
|
|
192
|
+
// using the extension .module.css
|
|
193
|
+
{
|
|
194
|
+
test: stylesRegexps.cssModuleRegex,
|
|
195
|
+
use: generateStyleLoaders(
|
|
196
|
+
merge({}, baseStyleLoadersOptions, {
|
|
197
|
+
cssLoaderOpts: {
|
|
198
|
+
importLoaders: 1,
|
|
199
|
+
sourceMap: isEnvProduction || shouldUseSourceMap,
|
|
200
|
+
modules: {
|
|
201
|
+
getLocalIdent: getCSSModuleLocalIdent,
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
shouldUseSourceMap: isEnvProduction || shouldUseSourceMap,
|
|
205
|
+
})
|
|
206
|
+
),
|
|
207
|
+
},
|
|
208
|
+
// Opt-in support for SASS (using .scss or .sass extensions).
|
|
209
|
+
// By default we support SASS Modules with the
|
|
210
|
+
// extensions .module.scss or .module.sass
|
|
211
|
+
{
|
|
212
|
+
test: stylesRegexps.sassNoModuleRegex,
|
|
213
|
+
use: generateStyleLoaders(
|
|
214
|
+
merge({}, baseStyleLoadersOptions, {
|
|
215
|
+
cssLoaderOpts: {
|
|
216
|
+
importLoaders: 3,
|
|
217
|
+
sourceMap: isEnvProduction || shouldUseSourceMap,
|
|
218
|
+
},
|
|
219
|
+
shouldUseSourceMap: isEnvProduction || shouldUseSourceMap,
|
|
220
|
+
preProcessOptions: {
|
|
221
|
+
resolveUrlLoaderPath: require.resolve('resolve-url-loader'),
|
|
222
|
+
preProcessorPath: require.resolve('sass-loader'),
|
|
223
|
+
},
|
|
224
|
+
})
|
|
225
|
+
),
|
|
226
|
+
// Don't consider CSS imports dead code even if the
|
|
227
|
+
// containing package claims to have no side effects.
|
|
228
|
+
// Remove this when webpack adds a warning or an error for this.
|
|
229
|
+
// See https://github.com/webpack/webpack/issues/6571
|
|
230
|
+
sideEffects: true,
|
|
231
|
+
},
|
|
232
|
+
// Adds support for CSS Modules, but using SASS
|
|
233
|
+
// using the extension .module.scss or .module.sass
|
|
234
|
+
{
|
|
235
|
+
test: stylesRegexps.sassModuleRegex,
|
|
236
|
+
use: generateStyleLoaders(
|
|
237
|
+
merge({}, baseStyleLoadersOptions, {
|
|
238
|
+
cssLoaderOpts: {
|
|
239
|
+
importLoaders: 3,
|
|
240
|
+
sourceMap: isEnvProduction || shouldUseSourceMap,
|
|
241
|
+
modules: {
|
|
242
|
+
getLocalIdent: getCSSModuleLocalIdent,
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
shouldUseSourceMap: isEnvProduction || shouldUseSourceMap,
|
|
246
|
+
preProcessOptions: {
|
|
247
|
+
resolveUrlLoaderPath: require.resolve('resolve-url-loader'),
|
|
248
|
+
preProcessorPath: require.resolve('sass-loader'),
|
|
249
|
+
},
|
|
250
|
+
})
|
|
251
|
+
),
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
test: stylesRegexps.lessNoModuleRegex,
|
|
255
|
+
use: generateStyleLoaders(
|
|
256
|
+
merge({}, baseStyleLoadersOptions, {
|
|
257
|
+
cssLoaderOpts: {
|
|
258
|
+
importLoaders: 1,
|
|
259
|
+
sourceMap: isEnvProduction || shouldUseSourceMap,
|
|
260
|
+
},
|
|
261
|
+
shouldUseSourceMap: isEnvProduction || shouldUseSourceMap,
|
|
262
|
+
preProcessOptions: {
|
|
263
|
+
resolveUrlLoaderPath: require.resolve('resolve-url-loader'),
|
|
264
|
+
preProcessorPath: require.resolve('less-loader'),
|
|
265
|
+
},
|
|
266
|
+
})
|
|
267
|
+
),
|
|
268
|
+
// Don't consider CSS imports dead code even if the
|
|
269
|
+
// containing package claims to have no side effects.
|
|
270
|
+
// Remove this when webpack adds a warning or an error for this.
|
|
271
|
+
// See https://github.com/webpack/webpack/issues/6571
|
|
272
|
+
sideEffects: true,
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
test: stylesRegexps.lessModuleRegex,
|
|
276
|
+
use: generateStyleLoaders(
|
|
277
|
+
merge({}, baseStyleLoadersOptions, {
|
|
278
|
+
cssLoaderOpts: {
|
|
279
|
+
importLoaders: 1,
|
|
280
|
+
sourceMap: isEnvProduction || shouldUseSourceMap,
|
|
281
|
+
modules: {
|
|
282
|
+
getLocalIdent: getCSSModuleLocalIdent,
|
|
283
|
+
},
|
|
284
|
+
},
|
|
285
|
+
shouldUseSourceMap: isEnvProduction || shouldUseSourceMap,
|
|
286
|
+
preProcessOptions: {
|
|
287
|
+
resolveUrlLoaderPath: require.resolve('resolve-url-loader'),
|
|
288
|
+
preProcessorPath: require.resolve('less-loader'),
|
|
289
|
+
},
|
|
290
|
+
})
|
|
291
|
+
),
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
|
|
295
|
+
type: 'asset',
|
|
296
|
+
parser: {
|
|
297
|
+
dataUrlCondition: {
|
|
298
|
+
maxSize: imageInlineSizeLimit,
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
},
|
|
302
|
+
{
|
|
303
|
+
// loads svg as both inlineUrl and react component, like:
|
|
304
|
+
// import starUrl, { ReactComponent as StarIcon } from './star.svg';
|
|
305
|
+
// (remove when there is native support for both opitons from webpack5 / svgr)
|
|
306
|
+
test: /\.svg$/,
|
|
307
|
+
oneOf: [
|
|
308
|
+
{
|
|
309
|
+
dependency: { not: ['url'] }, // exclude new URL calls
|
|
310
|
+
use: [
|
|
311
|
+
{
|
|
312
|
+
loader: require.resolve('@svgr/webpack'),
|
|
313
|
+
options: { titleProp: true, ref: true },
|
|
314
|
+
},
|
|
315
|
+
require.resolve('new-url-loader'),
|
|
316
|
+
],
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
type: 'asset', // export a data URI or emit a separate file
|
|
320
|
+
},
|
|
321
|
+
],
|
|
322
|
+
},
|
|
323
|
+
// "file" loader makes sure those assets get served by WebpackDevServer.
|
|
324
|
+
// When you `import` an asset, you get its (virtual) filename.
|
|
325
|
+
// In production, they would get copied to the `build` folder.
|
|
326
|
+
// This loader doesn't use a "test" so it will catch all modules
|
|
327
|
+
// that fall through the other loaders.
|
|
328
|
+
{
|
|
329
|
+
// Exclude `js` files to keep "css" loader working as it injects
|
|
330
|
+
// its runtime that would otherwise be processed through "file" loader.
|
|
331
|
+
// Also exclude `html` and `json` extensions so they get processed
|
|
332
|
+
// by webpacks internal loaders.
|
|
333
|
+
exclude: [/\.(js|mjs|jsx|ts|tsx)$/, /\.html$/, /\.mdx?/, /\.json$/, /\.css$/],
|
|
334
|
+
type: 'asset',
|
|
335
|
+
},
|
|
336
|
+
// ** STOP ** Are you adding a new loader?
|
|
337
|
+
// Make sure to add the new loader(s) before the "type:asset" loader.
|
|
338
|
+
],
|
|
339
|
+
},
|
|
340
|
+
],
|
|
341
|
+
},
|
|
342
|
+
// @ts-ignore
|
|
343
|
+
plugins: [
|
|
344
|
+
isEnvProduction &&
|
|
345
|
+
new MiniCssExtractPlugin({
|
|
346
|
+
// Options similar to the same options in webpackOptions.output
|
|
347
|
+
// both options are optional
|
|
348
|
+
filename: 'static/css/[name].[contenthash:8].css',
|
|
349
|
+
chunkFilename: 'static/css/[name].[contenthash:8].chunk.css',
|
|
350
|
+
}),
|
|
351
|
+
// Moment.js is an extremely popular library that bundles large locale files
|
|
352
|
+
// by default due to how webpack interprets its code. This is a practical
|
|
353
|
+
// solution that requires the user to opt into importing specific locales.
|
|
354
|
+
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
|
|
355
|
+
// You can remove this if you don't use Moment.js:
|
|
356
|
+
new IgnorePlugin({
|
|
357
|
+
resourceRegExp: /^\.\/locale$/,
|
|
358
|
+
contextRegExp: /moment$/,
|
|
359
|
+
}),
|
|
360
|
+
].filter(Boolean),
|
|
361
|
+
// Turn off performance processing because we utilize
|
|
362
|
+
// our own hints via the FileSizeReporter
|
|
363
|
+
performance: false,
|
|
364
|
+
};
|
|
365
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { Configuration } from 'webpack';
|
|
3
|
+
import { ComponentID } from '@teambit/component-id';
|
|
4
|
+
// Make sure the bit-react-transformer is a dependency
|
|
5
|
+
// TODO: remove it once we can set policy from component to component then set it via the component.json
|
|
6
|
+
import '@teambit/react.babel.bit-react-transformer';
|
|
7
|
+
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
|
|
8
|
+
|
|
9
|
+
const matchNothingRegex = 'a^';
|
|
10
|
+
|
|
11
|
+
// This is the production and development configuration.
|
|
12
|
+
// It is focused on developer experience, fast rebuilds, and a minimal bundle.
|
|
13
|
+
// eslint-disable-next-line complexity
|
|
14
|
+
// export default function (workDir: string, envId: string): Configuration {
|
|
15
|
+
export default function (workDir: string, envId: string): Configuration {
|
|
16
|
+
return {
|
|
17
|
+
module: {
|
|
18
|
+
rules: [
|
|
19
|
+
{
|
|
20
|
+
test: /\.js$/,
|
|
21
|
+
enforce: 'pre',
|
|
22
|
+
// limit loader to files in the current project,
|
|
23
|
+
// to skip any files linked from other projects (like Bit itself)
|
|
24
|
+
include: path.join(workDir, 'node_modules'),
|
|
25
|
+
// only apply to packages with componentId in their package.json (ie. bit components)
|
|
26
|
+
descriptionData: { componentId: (value) => !!value },
|
|
27
|
+
use: [require.resolve('source-map-loader')],
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
test: /\.js$/,
|
|
31
|
+
// limit loader to files in the current project,
|
|
32
|
+
// to skip any files linked from other projects (like Bit itself)
|
|
33
|
+
include: path.join(workDir, 'node_modules'),
|
|
34
|
+
// only apply to packages with componentId in their package.json (ie. bit components)
|
|
35
|
+
descriptionData: { componentId: ComponentID.isValidObject },
|
|
36
|
+
use: [
|
|
37
|
+
require.resolve('@pmmmwh/react-refresh-webpack-plugin/loader'),
|
|
38
|
+
{
|
|
39
|
+
loader: require.resolve('babel-loader'),
|
|
40
|
+
options: {
|
|
41
|
+
babelrc: false,
|
|
42
|
+
configFile: false,
|
|
43
|
+
plugins: [
|
|
44
|
+
require.resolve('react-refresh/babel'),
|
|
45
|
+
// for component highlighting in preview.
|
|
46
|
+
[require.resolve('@teambit/react.babel.bit-react-transformer')],
|
|
47
|
+
],
|
|
48
|
+
// turn off all optimizations (only slow down for node_modules)
|
|
49
|
+
compact: false,
|
|
50
|
+
minified: false,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
// MDX support (move to the mdx aspect and extend from there)
|
|
56
|
+
{
|
|
57
|
+
test: /\.mdx?$/,
|
|
58
|
+
// to skip any files linked from other projects (like Bit itself)
|
|
59
|
+
include: path.join(workDir, 'node_modules'),
|
|
60
|
+
// only apply to packages with componentId in their package.json (ie. bit components)
|
|
61
|
+
descriptionData: { componentId: (value) => !!value },
|
|
62
|
+
use: [
|
|
63
|
+
require.resolve('@pmmmwh/react-refresh-webpack-plugin/loader'),
|
|
64
|
+
{
|
|
65
|
+
loader: require.resolve('babel-loader'),
|
|
66
|
+
options: {
|
|
67
|
+
babelrc: false,
|
|
68
|
+
configFile: false,
|
|
69
|
+
presets: [require.resolve('@babel/preset-react'), require.resolve('@babel/preset-env')],
|
|
70
|
+
plugins: [require.resolve('react-refresh/babel')],
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
loader: require.resolve('@teambit/mdx.modules.mdx-loader'),
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
},
|
|
80
|
+
plugins: [
|
|
81
|
+
// No need here as we have `hot: true` in the dev server
|
|
82
|
+
// new webpack.HotModuleReplacementPlugin({}),
|
|
83
|
+
new ReactRefreshWebpackPlugin({
|
|
84
|
+
overlay: {
|
|
85
|
+
sockPath: `_hmr/${envId}`,
|
|
86
|
+
// TODO: check why webpackHotDevClient and react-error-overlay are not responding for runtime
|
|
87
|
+
// errors
|
|
88
|
+
entry: require.resolve('./react-hot-dev-client'),
|
|
89
|
+
module: require.resolve('./refresh'),
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
// we use '@pmmmwh/react-refresh-webpack-plugin/loader' directly where relevant.
|
|
93
|
+
// FYI, original defaults of the plugin are:
|
|
94
|
+
// include: /\.([cm]js|[jt]sx?|flow)$/i, exclude: /node_modules/,
|
|
95
|
+
include: matchNothingRegex,
|
|
96
|
+
}),
|
|
97
|
+
],
|
|
98
|
+
};
|
|
99
|
+
}
|