You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .github/CONTRIBUTING.md
+83-19
Original file line number
Diff line number
Diff line change
@@ -86,32 +86,57 @@ A high level overview of tools used:
86
86
87
87
### `yarn build`
88
88
89
-
The `build` script builds all build formats.
89
+
The `build` script builds all public packages (packages without `private: true` in their `package.json`).
90
+
91
+
Packages to build can be specified with fuzzy matching:
92
+
93
+
```bash
94
+
# build compiler only
95
+
yarn build compiler
96
+
97
+
# build all packages
98
+
yarn build --all
99
+
```
90
100
91
101
#### Build Formats
92
102
93
-
-**`global`**:
103
+
By default, each package will be built in multiple distribution formats as specified in the `buildOptions.formats` field in its `package.json`. These can be overwritten via the `-f` flag. The following formats are supported:
104
+
105
+
-**`global`**
94
106
95
107
- For direct use via `<script>` in the browser.
96
108
- Note: global builds are not [UMD](https://github.com/umdjs/umd) builds. Instead they are built as [IIFEs](https://developer.mozilla.org/en-US/docs/Glossary/IIFE).
97
109
98
-
-**`esm-bundler`**:
110
+
-**`esm-bundler`**
99
111
100
112
- Leaves prod/dev branches with `process.env.NODE_ENV` guards (to be replaced by bundler)
101
113
- Does not ship a minified build (to be done together with the rest of the code after bundling)
102
114
- For use with bundlers like `webpack`, `rollup` and `parcel`.
103
115
104
-
-**`esm-browser`**:
116
+
-**`esm-browser`**
105
117
106
118
- For usage via native ES modules imports (in browser via `<script type="module">`, or via Node.js native ES modules support in the future)
107
119
- Inlines all dependencies - i.e. it's a single ES module with no imports from other files
108
120
- This means you **must** import everything from this file and this file only to ensure you are getting the same instance of code.
109
121
- Hard-coded prod/dev branches, and the prod build is pre-minified (you will have to use different paths/aliases for dev/prod)
110
122
111
-
-**`cjs`**:
123
+
-**`cjs`**
124
+
112
125
- For use in Node.js server-side rendering via `require()`.
113
126
- The dev/prod files are pre-built, but are dynamically required based on `process.env.NODE_ENV` in `index.js`, which is the default entry when you do `require('vue-i18n')`.
114
127
128
+
For example, to build `compiler` with the global build only:
129
+
130
+
```bash
131
+
yarn build compiler -f global
132
+
```
133
+
134
+
Multiple formats can be specified as a comma-separated list:
135
+
136
+
```bash
137
+
yarn build compiler -f esm-browser,cjs
138
+
```
139
+
115
140
#### Build with Source Maps
116
141
117
142
Use the `--sourcemap` or `-s` flag to build with source maps. Note this will make the build much slower.
@@ -120,34 +145,73 @@ Use the `--sourcemap` or `-s` flag to build with source maps. Note this will mak
120
145
121
146
The `--types` or `-t` flag will generate type declarations during the build and in addition:
122
147
123
-
- Roll the declarations into a single `.d.ts` file.
124
-
- Generate an API report in `<projectRoot>/temp/vue-i18n.api.md`. This report contains potential warnings emitted by [api-extractor](https://api-extractor.com/).
125
-
- Generate an API model json in `<projectRoot>/temp/vue-i18n.api.json`. This file can be used to generate a Markdown version of the exported APIs.
148
+
- Roll the declarations into a single `.d.ts` file for each package;
149
+
- Generate an API report in `<projectRoot>/temp/<packageName>.api.md`. This report contains potential warnings emitted by [api-extractor](https://api-extractor.com/).
150
+
- Generate an API model json in `<projectRoot>/temp/<packageName>.api.json`. This file can be used to generate a Markdown version of the exported APIs.
151
+
152
+
### `yarn dev`
153
+
154
+
The `dev` script bundles a target package (default: `vue-i18n`) in a specified format (default: `global`) in dev mode and watches for changes. This is useful when you want to load up a build in an HTML page for quick debugging:
- The `dev` script also supports fuzzy match for the target package, but will only match the first package matched.
164
+
165
+
- The `dev` script supports specifying build format via the `-f` flag just like the `build` script.
166
+
167
+
- The `dev` script also supports the `-s` flag for generating source maps, but it will make rebuilds slower.
126
168
127
169
### `yarn test`
128
170
129
-
The `yarn test` script simply calls the `jest` binary, so all [Jest CLI Options](https://jestjs.io/docs/en/cli) can be used. Some examples:
171
+
The `test` script simply calls the `jest` binary, so all [Jest CLI Options](https://jestjs.io/docs/en/cli) can be used. Some examples:
130
172
131
173
```bash
132
174
# run all tests
133
175
$ yarn test
134
176
135
-
# run unit tests
136
-
$ yarn test:unit
177
+
# run tests in watch mode
178
+
$ yarn test --watch
137
179
138
-
# run unit test coverages
139
-
$ yarn test:coverage
180
+
# run all tests under the runtime-core package
181
+
$ yarn test compiler
140
182
141
-
# run unit tests in watch mode
142
-
$ yarn test:watch
183
+
# run tests in a specific file
184
+
$ yarn test fileName
143
185
144
-
# run type tests
145
-
$ yarn test:type
186
+
# run a specific test in a specific file
187
+
$ yarn test fileName -t 'test name'
188
+
```
189
+
190
+
## Project Structure
191
+
192
+
This repository employs a [monorepo](https://en.wikipedia.org/wiki/Monorepo) setup which hosts a number of associated packages under the `packages` directory:
193
+
194
+
-`shared`: Internal utilities shared across multiple packages.
195
+
-`message-resolver`: The message resolver.
196
+
-`message-compiler`: The message format compiler.
197
+
-`runtime`: The intlify runtime
198
+
-`core`: The intlify core.
199
+
-`vue-i18n`: The public facing "full build" which includes both the runtime AND the compiler.
146
200
147
-
# run e2e tests
148
-
$ yarn test:e2e
201
+
### Importing Packages
202
+
203
+
The packages can import each other directly using their package names. Note that when importing a package, the name listed in its `package.json` should be used. Most of the time the `@intlify/` prefix is needed:
204
+
205
+
```js
206
+
import { baseCompile } from'@intlify/compiler'
149
207
```
150
208
209
+
This is made possible via several configurations:
210
+
211
+
- For TypeScript, `compilerOptions.path` in `tsconfig.json`
212
+
- For Jest, `moduleNameMapper` in `jest.config.js`
213
+
- For plain Node.js, they are linked using [Yarn Workspaces](https://yarnpkg.com/blog/2017/08/02/introducing-workspaces/).
214
+
151
215
## Contributing Tests
152
216
153
217
Unit tests are collocated with directories named `test`. Consult the [Jest docs](https://jestjs.io/docs/en/using-matchers) and existing test cases for how to write new test specs. Here are some additional guidelines:
0 commit comments