@teambit/ui 0.0.555 → 0.0.556

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.
@@ -1,336 +0,0 @@
1
- import { ProvidePlugin } from 'webpack';
2
- import * as stylesRegexps from '@teambit/webpack.modules.style-regexps';
3
- import { pathNormalizeToLinux } from '@teambit/legacy/dist/utils';
4
- import { WebpackConfigWithDevServer } from '@teambit/webpack';
5
-
6
- import HtmlWebpackPlugin from 'html-webpack-plugin';
7
- import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
8
- import errorOverlayMiddleware from 'react-dev-utils/errorOverlayMiddleware';
9
- import evalSourceMapMiddleware from 'react-dev-utils/evalSourceMapMiddleware';
10
- import noopServiceWorkerMiddleware from 'react-dev-utils/noopServiceWorkerMiddleware';
11
- import redirectServedPath from 'react-dev-utils/redirectServedPathMiddleware';
12
- import getPublicUrlOrPath from 'react-dev-utils/getPublicUrlOrPath';
13
- import path from 'path';
14
- import { html } from './html';
15
-
16
- /*
17
- * Webpack config for the bit ui
18
- * i.e. `bit start --dev`,
19
- */
20
-
21
- const clientHost = process.env.WDS_SOCKET_HOST;
22
- const clientPath = process.env.WDS_SOCKET_PATH; // default is '/sockjs-node';
23
- const port = process.env.WDS_SOCKET_PORT;
24
-
25
- // const reactRefreshRuntimeEntry = require.resolve('react-refresh/runtime');
26
- // const reactRefreshWebpackPluginRuntimeEntry = require.resolve(
27
- // '@pmmmwh/react-refresh-webpack-plugin/lib/runtime/RefreshUtils'
28
- // );
29
-
30
- const publicUrlOrPath = getPublicUrlOrPath(process.env.NODE_ENV === 'development', '/', '/public');
31
-
32
- const moduleFileExtensions = [
33
- 'web.mjs',
34
- 'mjs',
35
- 'web.js',
36
- 'js',
37
- 'web.ts',
38
- 'ts',
39
- 'web.tsx',
40
- 'tsx',
41
- 'json',
42
- 'web.jsx',
43
- 'jsx',
44
- ];
45
-
46
- export function devConfig(workspaceDir, entryFiles, title, aspectPaths): WebpackConfigWithDevServer {
47
- const resolveWorkspacePath = (relativePath) => path.resolve(workspaceDir, relativePath);
48
-
49
- // Host
50
- const host = process.env.HOST || 'localhost';
51
-
52
- // Required for babel-preset-react-app
53
- process.env.NODE_ENV = 'development';
54
-
55
- return {
56
- // Environment mode
57
- mode: 'development',
58
- // improves HMR - assume node_modules might change
59
- snapshot: { managedPaths: [] },
60
-
61
- devtool: 'inline-source-map',
62
-
63
- // Entry point of app
64
- entry: {
65
- main: entryFiles,
66
- },
67
-
68
- output: {
69
- // Development filename output
70
- filename: 'static/js/[name].bundle.js',
71
-
72
- pathinfo: true,
73
-
74
- path: resolveWorkspacePath('/'),
75
-
76
- publicPath: publicUrlOrPath,
77
-
78
- chunkFilename: 'static/js/[name].chunk.js',
79
-
80
- // point sourcemap entries to original disk locations (format as URL on windows)
81
- devtoolModuleFilenameTemplate: (info) => pathNormalizeToLinux(path.resolve(info.absoluteResourcePath)),
82
-
83
- // this defaults to 'window', but by setting it to 'this' then
84
- // module chunks which are built will work in web workers as well.
85
- // Commented out to use the default (self) as according to tobias with webpack5 self is working with workers as well
86
- // globalObject: 'this',
87
- },
88
-
89
- infrastructureLogging: {
90
- level: 'error',
91
- },
92
-
93
- stats: 'errors-only',
94
-
95
- devServer: {
96
- allowedHosts: 'all',
97
-
98
- static: [
99
- {
100
- directory: resolveWorkspacePath(publicUrlOrPath),
101
- staticOptions: {},
102
- // Don't be confused with `dev.publicPath`, it is `publicPath` for static directory
103
- // Can be:
104
- // publicPath: ['/static-public-path-one/', '/static-public-path-two/'],
105
- publicPath: publicUrlOrPath,
106
- // Can be:
107
- // serveIndex: {} (options for the `serveIndex` option you can find https://github.com/expressjs/serve-index)
108
- serveIndex: true,
109
- // Can be:
110
- // watch: {} (options for the `watch` option you can find https://github.com/paulmillr/chokidar)
111
- watch: true,
112
- },
113
- ],
114
-
115
- // Enable compression
116
- compress: true,
117
-
118
- // Enable hot reloading
119
- hot: true,
120
-
121
- host,
122
-
123
- historyApiFallback: {
124
- disableDotRule: true,
125
- index: publicUrlOrPath,
126
- },
127
-
128
- client: {
129
- webSocketURL: {
130
- hostname: clientHost,
131
- pathname: clientPath,
132
- port,
133
- },
134
- },
135
-
136
- onBeforeSetupMiddleware({ app, server }) {
137
- // Keep `evalSourceMapMiddleware` and `errorOverlayMiddleware`
138
- // middlewares before `redirectServedPath` otherwise will not have any effect
139
- // This lets us fetch source contents from webpack for the error overlay
140
- app.use(evalSourceMapMiddleware(server));
141
- // This lets us open files from the runtime error overlay.
142
- app.use(errorOverlayMiddleware());
143
- },
144
-
145
- onAfterSetupMiddleware({ app }) {
146
- // Redirect to `PUBLIC_URL` or `homepage` from `package.json` if url not match
147
- app.use(redirectServedPath(publicUrlOrPath));
148
-
149
- // This service worker file is effectively a 'no-op' that will reset any
150
- // previous service worker registered for the same host:port combination.
151
- // We do this in development to avoid hitting the production cache if
152
- // it used the same host and port.
153
- // https://github.com/facebook/create-react-app/issues/2272#issuecomment-302832432
154
- app.use(noopServiceWorkerMiddleware(publicUrlOrPath));
155
- },
156
-
157
- devMiddleware: {
158
- // forward static files
159
- publicPath: publicUrlOrPath.slice(0, -1),
160
- },
161
- },
162
-
163
- resolve: {
164
- // These are the reasonable defaults supported by the Node ecosystem.
165
- // We also include JSX as a common component filename extension to support
166
- // some tools, although we do not recommend using it, see:
167
- // https://github.com/facebook/create-react-app/issues/290
168
- // `web` extension prefixes have been added for better support
169
- // for React Native Web.
170
- extensions: moduleFileExtensions.map((ext) => `.${ext}`),
171
- alias: {
172
- react: require.resolve('react'),
173
- 'react-dom/server': require.resolve('react-dom/server'),
174
- 'react-dom': require.resolve('react-dom'),
175
- // 'react-refresh/runtime': require.resolve('react-refresh/runtime'),
176
- },
177
- fallback: {
178
- fs: false,
179
- path: require.resolve('path-browserify'),
180
- stream: false,
181
- process: false,
182
- },
183
- },
184
-
185
- module: {
186
- // Webpack by default includes node_modules under its managed paths which cause the whole directory to be cached
187
- // Watch mode requires us to turn off unsafeCache as well
188
- // this de-optimizes the dev build but ensures hmr works when writing/linking into node modules.
189
- // However we do not lose the caching entirely like cache: false
190
- unsafeCache: false,
191
- rules: [
192
- {
193
- test: /\.m?js/,
194
- resolve: {
195
- fullySpecified: false,
196
- },
197
- },
198
- {
199
- test: /\.js$/,
200
- enforce: 'pre',
201
- include: /node_modules/,
202
- // only apply to packages with componentId in their package.json (ie. bit components)
203
- descriptionData: { componentId: (value) => !!value },
204
- use: [require.resolve('source-map-loader')],
205
- },
206
- {
207
- test: /\.(js|jsx|tsx|ts)$/,
208
- exclude: /node_modules/,
209
- include: workspaceDir,
210
- loader: require.resolve('babel-loader'),
211
- options: {
212
- configFile: false,
213
- babelrc: false,
214
- presets: [
215
- // Preset includes JSX, TypeScript, and some ESnext features
216
- require.resolve('babel-preset-react-app'),
217
- ],
218
- plugins: [require.resolve('react-refresh/babel')],
219
- },
220
- },
221
- {
222
- test: stylesRegexps.sassModuleRegex,
223
- use: [
224
- require.resolve('style-loader'),
225
- {
226
- loader: require.resolve('css-loader'),
227
- options: {
228
- modules: {
229
- localIdentName: '[name]__[local]--[hash:base64:5]',
230
- },
231
- sourceMap: true,
232
- },
233
- },
234
- {
235
- loader: require.resolve('sass-loader'),
236
- options: {
237
- sourceMap: true,
238
- },
239
- },
240
- ],
241
- },
242
- {
243
- test: stylesRegexps.sassNoModuleRegex,
244
- use: [
245
- require.resolve('style-loader'),
246
- require.resolve('css-loader'),
247
- {
248
- loader: require.resolve('sass-loader'),
249
- options: {
250
- sourceMap: true,
251
- },
252
- },
253
- ],
254
- },
255
- {
256
- test: stylesRegexps.lessModuleRegex,
257
- use: [
258
- require.resolve('style-loader'),
259
- {
260
- loader: require.resolve('css-loader'),
261
- options: {
262
- modules: {
263
- localIdentName: '[name]__[local]--[hash:base64:5]',
264
- },
265
- sourceMap: true,
266
- },
267
- },
268
- {
269
- loader: require.resolve('less-loader'),
270
- options: {
271
- sourceMap: true,
272
- },
273
- },
274
- ],
275
- },
276
- {
277
- test: stylesRegexps.lessNoModuleRegex,
278
- use: [
279
- require.resolve('style-loader'),
280
- require.resolve('css-loader'),
281
- {
282
- loader: require.resolve('less-loader'),
283
- options: {
284
- sourceMap: true,
285
- },
286
- },
287
- ],
288
- },
289
- {
290
- test: stylesRegexps.cssModuleRegex,
291
- use: [
292
- require.resolve('style-loader'),
293
- {
294
- loader: require.resolve('css-loader'),
295
- options: {
296
- modules: {
297
- localIdentName: '[name]__[local]--[hash:base64:5]',
298
- },
299
- sourceMap: true,
300
- },
301
- },
302
- ],
303
- },
304
- {
305
- test: stylesRegexps.cssNoModulesRegex,
306
- use: [require.resolve('style-loader'), require.resolve('css-loader')],
307
- },
308
- ],
309
- },
310
-
311
- plugins: [
312
- new ReactRefreshWebpackPlugin({
313
- include: aspectPaths, // original default value was /\.([cm]js|[jt]sx?|flow)$/i
314
- // replaces the default value of `/node_modules/`
315
- exclude: [
316
- /react-refresh-webpack-plugin/i,
317
- // file type filtering was done by `include`, so need to negative-filter them out here
318
- // A lookbehind assertion (`?<!`) has to be fixed width
319
- /(?<!\.jsx)(?<!\.js)(?<!\.tsx)(?<!\.ts)$/i,
320
- ],
321
- }),
322
- // Re-generate index.html with injected script tag.
323
- // The injected script tag contains a src value of the
324
- // filename output defined above.
325
- new HtmlWebpackPlugin({
326
- inject: true,
327
- templateContent: html(title || 'My component workspace'),
328
- chunks: ['main'],
329
- filename: 'index.html',
330
- }),
331
- new ProvidePlugin({
332
- process: require.resolve('process/browser'),
333
- }),
334
- ],
335
- };
336
- }
@@ -1,38 +0,0 @@
1
- import { Configuration } from 'webpack';
2
- import path from 'path';
3
- import { merge } from 'webpack-merge';
4
-
5
- import createBaseConfig from './webpack.base.config';
6
-
7
- export default function createWebpackConfig(
8
- workspaceDir: string,
9
- entryFiles: string[],
10
- publicDir: string
11
- ): Configuration {
12
- const baseConfig = createBaseConfig(workspaceDir, entryFiles);
13
- const ssrConfig = createSsrConfig(workspaceDir, publicDir);
14
-
15
- const combined = merge(baseConfig, ssrConfig);
16
-
17
- return combined;
18
- }
19
-
20
- function createSsrConfig(workspaceDir: string, publicDir: string) {
21
- const ssrConfig: Configuration = {
22
- target: 'node',
23
- devtool: 'eval-cheap-source-map', // TODO
24
-
25
- output: {
26
- path: path.resolve(workspaceDir, publicDir, 'ssr'),
27
- publicPath: '/public/ssr/',
28
- libraryTarget: 'commonjs',
29
- filename: 'index.js',
30
- },
31
-
32
- // // no optimizations for ssr at this point,
33
- // // especially no chunks.
34
- // optimization: { },
35
- };
36
-
37
- return ssrConfig;
38
- }