Commit 04066bc1 authored by Thomas Randolph's avatar Thomas Randolph Committed by Amy Qualls

Add documentation of RFC 20

parent d967565a
...@@ -136,24 +136,40 @@ the class name with `js-`. ...@@ -136,24 +136,40 @@ the class name with `js-`.
## ES Module Syntax ## ES Module Syntax
Use ES module syntax to import modules: For most JavaScript files, use ES module syntax to import or export from modules.
Prefer named exports, as they improve name consistency.
```javascript ```javascript
// bad // bad (with exceptions, see below)
const SomeClass = require('some_class'); export default SomeClass;
import SomeClass from 'file';
// good // good
import SomeClass from 'some_class'; export { SomeClass };
import { SomeClass } from 'file';
```
Using default exports is acceptable in a few particular circumstances:
- Vue Single File Components (SFCs)
- Vuex mutation files
For more information, see [RFC 20](https://gitlab.com/gitlab-org/frontend/rfcs/-/issues/20).
## CommonJS Module Syntax
Our Node configuration requires CommonJS module syntax. Prefer named exports.
```javascript
// bad // bad
module.exports = SomeClass; module.exports = SomeClass;
const SomeClass = require('./some_class');
// good // good
export default SomeClass; module.exports = { SomeClass };
const { SomeClass } = require('./some_class');
``` ```
We still use `require` in `scripts/` and `config/` files.
## Absolute vs relative paths for modules ## Absolute vs relative paths for modules
Use relative paths if the module you are importing is less than two levels up. Use relative paths if the module you are importing is less than two levels up.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment