build: support source map in build and dev scripts

This commit is contained in:
Evan You 2020-01-28 10:28:40 -05:00
parent 827fd05644
commit 78beed2574
4 changed files with 18 additions and 4 deletions

View File

@ -106,9 +106,13 @@ Multiple formats can be specified as a comma-separated list:
yarn build runtime-core -f esm,cjs yarn build runtime-core -f esm,cjs
``` ```
#### Build with Source Maps
Use the `--sourcemap` or `-s` flag to build with source maps. Note this will make the build much slower.
#### Build with Type Declarations #### Build with Type Declarations
The `--types` flag will generate type declarations during the build and in addition: The `--types` or `-t` flag will generate type declarations during the build and in addition:
- Roll the declarations into a single `.dts` file for each package; - Roll the declarations into a single `.dts` file for each package;
- Generate an API report in `<projectRoot>/temp/<packageName>.api.md`. This report contains potential warnings emitted by [api-extractor](https://api-extractor.com/). - Generate an API report in `<projectRoot>/temp/<packageName>.api.md`. This report contains potential warnings emitted by [api-extractor](https://api-extractor.com/).
@ -129,6 +133,8 @@ $ yarn dev
- The `dev` script supports specifying build format via the `-f` flag just like the `build` script. - The `dev` script supports specifying build format via the `-f` flag just like the `build` script.
- The `dev` script also supports the `-s` flag for generating source maps, but it will make rebuilds slower.
### `yarn test` ### `yarn test`
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: 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:

View File

@ -73,6 +73,7 @@ function createConfig(format, output, plugins = []) {
process.exit(1) process.exit(1)
} }
output.sourcemap = !!process.env.SOURCE_MAP
output.externalLiveBindings = false output.externalLiveBindings = false
const isProductionBuild = const isProductionBuild =
@ -98,6 +99,7 @@ function createConfig(format, output, plugins = []) {
cacheRoot: path.resolve(__dirname, 'node_modules/.rts2_cache'), cacheRoot: path.resolve(__dirname, 'node_modules/.rts2_cache'),
tsconfigOverride: { tsconfigOverride: {
compilerOptions: { compilerOptions: {
sourceMap: output.sourcemap,
declaration: shouldEmitDeclarations, declaration: shouldEmitDeclarations,
declarationMap: shouldEmitDeclarations declarationMap: shouldEmitDeclarations
}, },

View File

@ -27,6 +27,7 @@ const targets = args._
const formats = args.formats || args.f const formats = args.formats || args.f
const devOnly = args.devOnly || args.d const devOnly = args.devOnly || args.d
const prodOnly = !devOnly && (args.prodOnly || args.p) const prodOnly = !devOnly && (args.prodOnly || args.p)
const sourceMap = args.sourcemap || args.s
const isRelease = args.release const isRelease = args.release
const buildTypes = args.t || args.types || isRelease const buildTypes = args.t || args.types || isRelease
const buildAllMatching = args.all || args.a const buildAllMatching = args.all || args.a
@ -80,7 +81,8 @@ async function build(target) {
formats ? `FORMATS:${formats}` : ``, formats ? `FORMATS:${formats}` : ``,
buildTypes ? `TYPES:true` : ``, buildTypes ? `TYPES:true` : ``,
prodOnly ? `PROD_ONLY:true` : ``, prodOnly ? `PROD_ONLY:true` : ``,
lean ? `LEAN:true` : `` lean ? `LEAN:true` : ``,
sourceMap ? `SOURCE_MAP:true` : ``
] ]
.filter(Boolean) .filter(Boolean)
.join(',') .join(',')

View File

@ -21,6 +21,7 @@ const { fuzzyMatchTarget } = require('./utils')
const args = require('minimist')(process.argv.slice(2)) const args = require('minimist')(process.argv.slice(2))
const target = args._.length ? fuzzyMatchTarget(args._)[0] : 'vue' const target = args._.length ? fuzzyMatchTarget(args._)[0] : 'vue'
const formats = args.formats || args.f const formats = args.formats || args.f
const sourceMap = args.sourcemap || args.s
const commit = execa.sync('git', ['rev-parse', 'HEAD']).stdout.slice(0, 7) const commit = execa.sync('git', ['rev-parse', 'HEAD']).stdout.slice(0, 7)
execa( execa(
@ -31,8 +32,11 @@ execa(
[ [
`COMMIT:${commit}`, `COMMIT:${commit}`,
`TARGET:${target}`, `TARGET:${target}`,
`FORMATS:${formats || 'global'}` `FORMATS:${formats || 'global'}`,
].join(',') sourceMap ? `SOURCE_MAP:true` : ``
]
.filter(Boolean)
.join(',')
], ],
{ {
stdio: 'inherit' stdio: 'inherit'