Skip to content

Commit bc40a86

Browse files
committed
build: add __VUE_2__ variable to replace plugin
1 parent d45d492 commit bc40a86

File tree

6 files changed

+25
-9
lines changed

6 files changed

+25
-9
lines changed

CHANGELOG.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,17 @@
33
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
44
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
55

6-
<!-- ## [Unreleased]
6+
## [Unreleased]
77

8-
--- -->
8+
---
9+
10+
## Fixes
11+
12+
- Build wrongly outputting `__VUE_2__` env variable instead of replacing
13+
14+
## Added
15+
16+
- Export `COMMIT`, `VERSION` and `VUE_VERSION` in the `index.ts`
917

1018
## 1.0.0-dev.29
1119

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ Check out the [examples folder](examples) or start hacking on [codesandbox](http
127127
> New packages needed
128128
129129
- [Axios](https://pikax.me/vue-composable/composable/external/axios) - [@vue-composable/axios](https://www.npmjs.com/package/@vue-composable/axios) reactive `axios` wrapper client
130-
- [makeAxios](https://pikax.me/vue-composable/composable/external/makeAxios) - [@vue-composable/makeAxios](https://www.npmjs.com/package/@vue-composable/axios) wrap your `axios` instance
130+
- [makeAxios](https://pikax.me/vue-composable/composable/external/makeAxios) - [@vue-composable/axios](https://www.npmjs.com/package/@vue-composable/axios) wrap your `axios` instance
131131

132132
## Usage
133133

packages/global.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Global compile-time constants
22
declare var __DEV__: boolean;
33
declare var __JSDOM__: boolean;
4+
declare var __COMMIT__: string;
45
declare var __VERSION__: string;
56
declare var __VUE_2__: boolean;

packages/vue-composable/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ export * from "./date";
1212
export * from "./format";
1313
export * from "./validation";
1414
export * from "./i18n";
15+
16+
export const VERSION = __VERSION__;
17+
export const VUE_VERSION: "2" | "3" = __VUE_2__ ? "2" : "3";
18+
export const COMMIT = __COMMIT__;

rollup.config.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ if (!process.env.TARGET) {
99
throw new Error("TARGET package must be specified via --environment flag.");
1010
}
1111

12-
const masterVersion = require("./package.json").version;
1312
const packagesDir = path.resolve(__dirname, "packages");
1413
const packageDir = path.resolve(packagesDir, process.env.TARGET);
1514
const name = path.basename(packageDir);
@@ -168,7 +167,7 @@ function createReplacePlugin(
168167
) {
169168
return replace({
170169
__COMMIT__: `"${process.env.COMMIT}"`,
171-
__VERSION__: `"${masterVersion}"`,
170+
__VERSION__: `"${process.env.VERSION}"`,
172171
__DEV__: isBundlerESMBuild
173172
? // preserve to be handled by bundlers
174173
`(process.env.NODE_ENV !== 'production')`
@@ -184,7 +183,9 @@ function createReplacePlugin(
184183
// the lean build drops options related code with buildOptions.lean: true
185184
"process.env.NODE_ENV": isBundlerESMBuild
186185
? `process.env.NODE_ENV`
187-
: "'production'"
186+
: "'production'",
187+
188+
__VUE_2__: process.env.VUE_VERSION === "2"
188189
});
189190
}
190191

scripts/build.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ async function build(target, targetVersion) {
5757
const majorVersion = mainPkg.version.split("-")[0];
5858

5959
const tempVersion = targetVersion === 3 ? "alpha" : "dev";
60-
const version = `${majorVersion}-${tempVersion}.${currentMinor}`;
60+
const pkgVersion = `${majorVersion}-${tempVersion}.${currentMinor}`;
6161

6262
const peerDependencies =
6363
targetVersion === 2 ? pkg.peerDependencies2 : pkg.peerDependencies3;
@@ -66,7 +66,7 @@ async function build(target, targetVersion) {
6666
pkg.dependencies && pkg.dependencies["vue-composable"]
6767
? {
6868
...pkg.dependencies,
69-
"vue-composable": `^${version}`
69+
"vue-composable": `^${pkgVersion}`
7070
}
7171
: pkg.dependencies;
7272

@@ -102,7 +102,9 @@ async function build(target, targetVersion) {
102102
`TARGET:${target}`,
103103
formats ? `FORMATS:${formats}` : ``,
104104
buildTypes ? `TYPES:true` : ``,
105-
prodOnly ? `PROD_ONLY:true` : ``
105+
prodOnly ? `PROD_ONLY:true` : ``,
106+
`VERSION:${pkgVersion}`,
107+
`VUE_VERSION:${version}`
106108
]
107109
.filter(Boolean)
108110
.join(",")

0 commit comments

Comments
 (0)