Code Monkey home page Code Monkey logo

wl-web-configs's Introduction

wl-web-configs

Common configurations for building web apps at Workleap.

License CI

Packages

Name NPM
@workleap/browserslist-config npm version
@workleap/eslint-plugin npm version
@workleap/postcss-configs npm version
@workleap/stylelint-plugin npm version
@workleap/typescript-configs npm version
@workleap/tsup-configs npm version
@workleap/swc-configs npm version
@workleap/webpack-configs npm version

Have a question or found an issue?

To ask a question or propose an idea, feel free to start a new discussion. If you found a bug, please open an issue.

Documentation

View the user's documentation.

🤝 Contributing

View the contributors documentation.

License

Copyright © 2023, Workleap This code is licensed under the Apache License, Version 2.0. You may obtain a copy of this license at https://github.com/gsoft-inc/workleap-license/blob/master/LICENSE.

wl-web-configs's People

Contributors

alexasselin008 avatar bsokol-wl avatar github-actions[bot] avatar ofrogon avatar patricklafrance avatar tjosepo avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

wl-web-configs's Issues

Remove the "jsx" field from "react.json" TS config

According to TSC documentation, the jsx field is only related to emitting code.

As we don't use TSC to emit code, we should remove the jsx field.

Controls how JSX constructs are emitted in JavaScript files. This only affects output of JS files that started in .tsx files.

react: Emit .js files with JSX changed to the equivalent React.createElement calls
react-jsx: Emit .js files with the JSX changed to _jsx calls
react-jsxdev: Emit .js files with the JSX changed to _jsx calls
preserve: Emit .jsx files with the JSX unchanged
react-native: Emit .js files with the JSX unchanged

Source: https://www.typescriptlang.org/tsconfig#jsx

Allow publicPath value "auto"

Hard-coding a publicPath value into a bundle is not very robust, as it makes the page fail to load scripts whenever the publicPath value is different from the URL the page is running on.

Setting it to "auto" will make Webpack use document.currentScript to resolve scripts in the bundle, which is useful in micro-frontend setups, and will work when the page is hosted on any URL.

We could define a list of public path and create a different build for each environemnts, but using "auto" is simpler and lets us re-use a single configuration across environments.

Add a config for tsup

I believe that we now know enough about tsup to add a shared config to this project.

The shared config should strictly target TS libraries. We have a few examples in squide.

I really like tsup's native defineConfig function. I believe we should develop something around this.

We could either export our own defineConfig function pre-configured with our defaults or a JSON config that the end user would have to pass to tsup's native defineConfig function.

Add a tsup package config

tsup configs should be provided by this monorepo as a standalone package.

The tsup CLI support TypeScript configuration file so maybe they don't required a transpilation before being packaged?

2 configs should be offered:

  • dev with a config named dev.ts
  • build with a config named build.ts

I really like tsup's native defineConfig function. I believe we should develop something around this.

We could either export our own defineConfig function pre-configured with our defaults or a JSON config that the end user would have to pass to tsup's native defineConfig function.

When using `@workleap/eslint-plugin` and extends `@workleap/web-application` in `.eslintrc.json` we get error about missing rule definition

When configuring EsLint for the project and using @workleap/eslint-plugin, in the .eslintrc.json like this:

{
    "$schema": "https://json.schemastore.org/eslintrc",
    "root": true,
    "extends": "plugin:@workleap/web-application"
}

As it is documented here. But I get this error from EsLint for each file:

ESLint: Definition for rule '@workleap/strict-css-modules-names' was not found.(@workleap/strict-css-modules-names)

Some more information:

  • Package manager: PNPM v8.4.0
  • Node: v18.16.0
  • EsLint: v8.40.0
  • OS: Win 10

Warning when linting

When I execute the following script: "eslint --ext .js,.ts,.tsx . --max-warnings=-1 --cache --cache-location node_modules/.cache/eslint" I get the following warning:

Warning: React version not specified in eslint-plugin-react settings. See https://github.com/jsx-eslint/eslint-plugin-react#configuration .

number-max-precision leads to odd px values

In some situations rounding rem values in CSS leads to non precise values in pixel.

When there's a need for a value with a .5px in rem the value is: 0.03125 which triggers a linting error, rounding to 0.03123 would compute a value of 0.5008px if 1 rem = 16px. This can lead to problematic values when dealing with line-height.

clean, test and lint:types scripts shouldn't be delegated to packages

clean, ``test and lint:types scripts should be handled by the monorepo root scripts instead of being delegated to packages.

Since PNPM is not hoisting packages, it would be expected to add jest and typescript as devDependencies to every package otherwise.

Furthermore, it's repetitive and can be avoided by using pnpm exec.

In the monorepo root scripts you could have:

Extra stylistic eslint rule

Demand coming from slack:

Add eslint rules for stylistic rules, such as:

  • no extra spacing
  • extra line before if/for operators

ESLINT configs that changes recommended from error to warn no longuer required

For a long time, when using CRA, if we had errors, it would stop the linting and only display the most recent error instead of listing them all.

In order to be able to see all the eslint errors in the dev server, we changed all our errors to warnings instead. This way eslint lists all the lint warning instead of only the first one.

Now that we are back to using eslint's cli, i don't think we should use "warn" anymore for our configs. We should extends eslint:recommended, and add our custom rules as errors

TS monorepo-root config docs should specify to exclude the package folder by default

To prevent new projects from linting twice their codebase when using the TypeScript monorepo-root config, the documentation should mention that without an excluded it will happen.

The docs sample should probably exclude the package folder by default:

{
    "extends": "@workleap/typescript-configs/monorepo-root.json",
    "exclude": ["packages", "node_modules"]
}

Most project will probably get a TS18003 error with the exclusion thought. My current solution is to add an ignore-18003.ts file at the root of my monorepo.

Issue with TypeScript Monorepo docs example

There are a few issue with this docs example for TypeScript monorepo config:

image

  • Monorepo setup doesn't have a ./src folder at the root
  • baseUrl is only needed when aliases are specified (should also be fixed for other TypeScript configs docs example)
  • pretty sure node_modules folder is excluded by default

Since we are not expecting to transpile files with tsc, from what I experienced with my latest repo, all is needed in the tsconfig.json at the root is:

{
    "extends": "@workleap/typescript-configs/monorepo-root.json"
}

(It's probably similar for the other TypeScript config files as well)

[stylelint-configs] Support prettier v3.0.0

Currently, using stylelint-configs with prettier =>3.0.0 causes the following error:

TypeError: prettier.resolveConfig.sync is not a function

The error seems to be caused by stylelint-prettier. They don't seems to have updated their package to support prettier v3.0.0 yet.

In the meantime, products should stay on prettier v2.8.8

Fix ESLint env settings

Turns out that ESLint overrides doesn't seem to merge the env settings.

In core.ts we have:

    env: {
        es6: true,
        node: true,
        commonjs : true
    },

And in react.ts we have:

            env: {
                browser: true
            },

As a consumer, in my application, when using plugin:@workleap/web-application, the node settings is not true anymore.

clean script != reset script

There's usually a difference between the clean and the reset scripts as they fulfill different purpose.

clean is used to delete cache files, the dist folder and other similar artifacts while the reset script is used to clean but also reset the whole solutions by deleting the node_modules folder and the package manager .lock files.

It's an important distinct as deleting the node_modules folder everytime you to reset the package outputs (deleting the dist folder) is frustrating.

Missing a CONTRIBUTORS documentation

Adding a very simple CONTTRIBUTORS documentation would help to get future maintainers started.

  • How to setup the project
  • How to start developping
  • How to release
  • Anything specific that a maintainer should be aware of

Webpack test RegEx are too lenient

The test RegEx used by Webpack are too lenient and can target the wrong file extensions:

See: https://github.com/gsoft-inc/wl-web-configs/blob/main/packages/webpack-configs/src/dev.ts

{
    test: /\.(js|jsx|ts|tsx)/i,
    exclude: /node_modules/,
    loader: require.resolve("swc-loader"),
    options: trySetSwcFastRefresh(swcConfig, fastRefresh !== false)
},

The ReGex /\.(js|jsx|ts|tsx)/i is missing the end-of-string $ token.

Because of this, the ReGex incorrectly matches .json files, which breaks json-loading in Webpack.

tsup OOM Error

Using tsup to build our app, we see a huge memory leak in the process.

Locally, the node.js JavaScript Runtime gets increasingly bigger until it reaches 4GB of Memory, and then it crashed. The crash occurs in 30sec to 1 minute after launching the app, and doing nothing at all with it.
image

In the CI pipeline, we increased the max memory size to 8GB using NODE_OPTIONS: --max_old_space_size=8192, which did the job...

We have been experimenting with using the tsup --experimental-dts to replace the normal --dts. So far, the app memory is stable around 600MB locally, and build 3 times faster in the CI pipeline (30s, down from 1min30s).

So far, no issues with the new tsup config. We will continue to monitor the effects of the new config.

Removed "target" and "sourceMaps" from TS configs

Since we only lint with tsc and use tsup to transpile code, I don't think we need the target and sourceMaps fields in our TS configs as they are strictly related to transpilation.

Therefore, we should remove them.

Should we minify our library packages?

I wonder whether we should add or not minify: true to our tsup config?

Most libraries we used ship unminified. It does help because it's easy to open the source code and understand how it works and even add debugging instructions.

What do you think?

The downside is that the applications build scripts will have to minify the code which might increase the build time. Still, I am not sure if application build scripts minification process ignore "already minified" libraries.

tsup setup

Similarly to our other tools, tsup should have it's own tsup.config.js or tsup.config.json file instead of being configured in the package.json file.

Furthermore, since we are using PNPM, devDependencies should be declared in every package instead of the monorepo root. tsup dependency is currently problematic.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.