Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
04066bc1
Commit
04066bc1
authored
Jan 31, 2022
by
Thomas Randolph
Committed by
Amy Qualls
Jan 31, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add documentation of RFC 20
parent
d967565a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
7 deletions
+23
-7
doc/development/fe_guide/style/javascript.md
doc/development/fe_guide/style/javascript.md
+23
-7
No files found.
doc/development/fe_guide/style/javascript.md
View file @
04066bc1
...
...
@@ -136,24 +136,40 @@ the class name with `js-`.
## 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
// bad
const
SomeClass
=
require
(
'
some_class
'
);
// bad (with exceptions, see below)
export
default
SomeClass
;
import
SomeClass
from
'
file
'
;
// 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
module
.
exports
=
SomeClass
;
const
SomeClass
=
require
(
'
./some_class
'
);
// 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
Use relative paths if the module you are importing is less than two levels up.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment