Skip to content

Commit 5b3f005

Browse files
author
Nano Vazquez
committed
fix(build): Use "umd" as library target for libraries
1 parent f880b26 commit 5b3f005

File tree

6 files changed

+27
-22
lines changed

6 files changed

+27
-22
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ You can modify the configuration of all the scripts this way (`lint`, `start`, `
7676

7777
### Start
7878

79-
It spins up a [Webpack DevServer[(https://webpack.js.org/configuration/dev-server/)] with your web app, configured with [Hot Module replacement](https://webpack.js.org/concepts/hot-module-replacement/) and [Cheap Module Source maps](https://webpack.js.org/configuration/devtool/).
79+
It spins up a [Webpack DevServer](https://webpack.js.org/configuration/dev-server/)] with your web app, configured with [Hot Module replacement](https://webpack.js.org/concepts/hot-module-replacement/) and [Cheap Module Source maps](https://webpack.js.org/configuration/devtool/).
8080

8181
It supports [React](https://reactjs.org/), [TypeScript](https://www.typescriptlang.org/), [SCSS](https://sass-lang.com/guide) and [CSS Modules](https://github.com/css-modules/css-modules). Plus, it automatically types your style files by using the [typings-for-css-modules-loader](https://github.com/TeamSupercell/typings-for-css-modules-loader) library.
8282

src/scripts/lint/lint.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ console.log(filesToUse !== defaultFilesToUse ? `Found custom rule to identify fi
7070
process.exit(1);
7171
}
7272

73+
// Only fail because of warnings if --max-warnings is sent
74+
// See https://eslint.org/docs/user-guide/command-line-interface#-max-warnings
7375
const maxWarnings = getArgumentValue(process.argv, 'max-warnings', '-1');
7476
if (maxWarnings !== '-1' && globalResults.warningCount > parseInt(maxWarnings, 10)) {
7577
process.exit(1);

src/webpack/resolveExternals.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import type webpack from 'webpack';
22

33
export default (isLibrary: boolean): webpack.ExternalsElement => {
4-
if (isLibrary) {
5-
// UMD only supports an object
6-
return {
7-
react: {
8-
amd: 'react',
9-
commonjs: 'react',
10-
commonjs2: 'react',
11-
root: 'React',
12-
},
13-
'react-dom': {
14-
amd: 'react-dom',
15-
commonjs: 'react-dom',
16-
commonjs2: 'react-dom',
17-
root: 'ReactDOM',
18-
},
19-
};
20-
}
4+
// if (isLibrary) {
5+
// // UMD only supports an object
6+
// return {
7+
// react: {
8+
// amd: 'react',
9+
// commonjs: 'react',
10+
// commonjs2: 'react',
11+
// root: 'React',
12+
// },
13+
// 'react-dom': {
14+
// amd: 'react-dom',
15+
// commonjs: 'react-dom',
16+
// commonjs2: 'react-dom',
17+
// root: 'ReactDOM',
18+
// },
19+
// };
20+
// }
2121

2222
return {
2323
react: 'React',

src/webpack/webpack.config.app.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ const webpackConfig: webpack.Configuration = {
3131

3232
externals: resolveExternals(false),
3333

34+
target: 'web',
35+
3436
mode: isDevelopment ? 'development' : 'production',
3537

3638
entry: {

src/webpack/webpack.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import type webpack from 'webpack';
22
import webpackConfigApp from './webpack.config.app';
3-
import webpackConfigLibrary from './webpack.config.library';
3+
import webpackConfigUiLibrary from './webpack.config.uiLibrary';
44

55
// TODO: move this to the main file and convert the webpack to a function
66
import getArgumentValue from '../common/getArgumentValue';
77

8-
const isLibrary = getArgumentValue(process.argv, 'type').toLowerCase() === 'library';
8+
const isLibrary = getArgumentValue(process.argv, 'type').toLowerCase() === 'ui-library';
99

10-
const config: webpack.Configuration = isLibrary ? webpackConfigLibrary : webpackConfigApp;
10+
const config: webpack.Configuration = isLibrary ? webpackConfigUiLibrary : webpackConfigApp;
1111
export default config;

src/webpack/webpack.config.library.ts renamed to src/webpack/webpack.config.uiLibrary.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ const webpackConfig: webpack.Configuration = {
1919

2020
externals: resolveExternals(true),
2121

22+
target: 'web',
23+
2224
mode: isDevelopment ? 'development' : 'production',
2325

2426
entry: {
@@ -28,7 +30,6 @@ const webpackConfig: webpack.Configuration = {
2830
output: {
2931
filename: '[name].min.js',
3032
path: OUTPUT_PATH,
31-
libraryTarget: 'commonjs2',
3233
},
3334

3435
resolve: {

0 commit comments

Comments
 (0)