Skip to content

Commit 358723a

Browse files
Add typescript support to webpack (#3)
* Setup webpack typescript * fix errors * target es5
1 parent d74dc62 commit 358723a

File tree

5 files changed

+70
-13
lines changed

5 files changed

+70
-13
lines changed

integrations/clicky/lib/index.js renamed to integrations/clicky/lib/index.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var Clicky = (module.exports = integration('Clicky')
3131

3232
Clicky.prototype.initialize = function() {
3333
var user = this.analytics.user();
34-
window.clicky_site_ids = window.clicky_site_ids || [this.options.siteId];
34+
window["clicky_site_ids"] = window["clicky_site_ids"] || [this.options.siteId];
3535
this.identify(
3636
new Identify({
3737
userId: user.id(),
@@ -49,7 +49,7 @@ Clicky.prototype.initialize = function() {
4949
*/
5050

5151
Clicky.prototype.loaded = function() {
52-
return isObject(window.clicky);
52+
return isObject(window["clicky"]);
5353
};
5454

5555
/**
@@ -64,7 +64,7 @@ Clicky.prototype.loaded = function() {
6464
Clicky.prototype.page = function(page) {
6565
var properties = page.properties();
6666
var name = page.fullName();
67-
window.clicky.log(properties.path, name || properties.title);
67+
window["clicky"].log(properties.path, name || properties.title);
6868
};
6969

7070
/**
@@ -75,8 +75,8 @@ Clicky.prototype.page = function(page) {
7575
*/
7676

7777
Clicky.prototype.identify = function(identify) {
78-
window.clicky_custom = window.clicky_custom || {};
79-
window.clicky_custom.session = window.clicky_custom.session || {};
78+
window["clicky_custom"] = window["clicky_custom"] || {};
79+
window["clicky_custom"].session = window["clicky_custom"].session || {};
8080
var traits = identify.traits();
8181

8282
var username = identify.username();
@@ -85,7 +85,7 @@ Clicky.prototype.identify = function(identify) {
8585

8686
if (username || email || name) traits.username = username || email || name;
8787

88-
extend(window.clicky_custom.session, traits);
88+
extend(window["clicky_custom"].session, traits);
8989
};
9090

9191
/**
@@ -98,5 +98,5 @@ Clicky.prototype.identify = function(identify) {
9898
*/
9999

100100
Clicky.prototype.track = function(track) {
101-
window.clicky.goal(track.event(), track.revenue());
101+
window["clicky"].goal(track.event(), track.revenue());
102102
};

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"lint-staged": "^8.2.1",
4545
"prettier": "^1.18.2",
4646
"terser-webpack-plugin": "^4.2.1",
47+
"ts-loader": "^8.0.4",
4748
"ts-node": "^9.0.0",
4849
"typescript": "^4.0.3",
4950
"webpack": "^4.44.1",

tsconfig.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"target": "es5",
5+
"declaration": true,
6+
"moduleResolution": "node",
7+
"esModuleInterop": true,
8+
"resolveJsonModule": true,
9+
"sourceMap": true,
10+
"incremental": true,
11+
"outDir": "dist",
12+
"noUnusedLocals": true,
13+
"noUnusedParameters": true,
14+
"lib": ["es2020", "DOM"],
15+
"baseUrl": "./node_modules/",
16+
"paths": {
17+
"@/*": ["./*"]
18+
}
19+
},
20+
"exclude": ["node_modules", "dist"],
21+
"include": ["integrations"]
22+
}

webpack.config.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ var entries = {};
1818
files.forEach(function(file) {
1919
var filePath = './integrations/' + file + '/lib/index.js';
2020
if (!fs.existsSync(filePath)) {
21-
return;
21+
filePath = './integrations/' + file + '/lib/index.ts';
22+
if (!fs.existsSync(filePath)) {
23+
return;
24+
}
2225
}
2326
entries[file] = filePath;
2427
});
@@ -46,6 +49,18 @@ module.exports = {
4649
libraryTarget: 'umd',
4750
publicPath: publicPath
4851
},
52+
module: {
53+
rules: [
54+
{
55+
test: /\.tsx?$/,
56+
use: 'ts-loader',
57+
exclude: /node_modules/
58+
}
59+
]
60+
},
61+
resolve: {
62+
extensions: ['.ts', '.js']
63+
},
4964
devServer: {
5065
contentBase: path.resolve(__dirname, 'build')
5166
},

yarn.lock

+24-5
Original file line numberDiff line numberDiff line change
@@ -2414,7 +2414,7 @@ braces@^2.3.1, braces@^2.3.2:
24142414
split-string "^3.0.2"
24152415
to-regex "^3.0.1"
24162416

2417-
braces@~3.0.2:
2417+
braces@^3.0.1, braces@~3.0.2:
24182418
version "3.0.2"
24192419
resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107"
24202420
integrity sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==
@@ -2918,7 +2918,7 @@ chalk@^1.0.0, chalk@^1.1.1, chalk@^1.1.3:
29182918
strip-ansi "^3.0.0"
29192919
supports-color "^2.0.0"
29202920

2921-
"chalk@^1.1.3 || 2.x", chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.3.1, chalk@^2.4.0, chalk@^2.4.1, chalk@^2.4.2:
2921+
"chalk@^1.1.3 || 2.x", chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.3.0, chalk@^2.3.1, chalk@^2.4.0, chalk@^2.4.1, chalk@^2.4.2:
29222922
version "2.4.2"
29232923
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424"
29242924
integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==
@@ -4310,7 +4310,7 @@ engine.io@~3.2.0:
43104310
engine.io-parser "~2.1.0"
43114311
ws "~3.3.1"
43124312

4313-
enhanced-resolve@^4.1.1, enhanced-resolve@^4.3.0:
4313+
enhanced-resolve@^4.0.0, enhanced-resolve@^4.1.1, enhanced-resolve@^4.3.0:
43144314
version "4.3.0"
43154315
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-4.3.0.tgz#3b806f3bfafc1ec7de69551ef93cca46c1704126"
43164316
integrity sha512-3e87LvavsdxyoCfGusJnrZ5G8SLPOFeHSNpZI/ATL9a5leXo2k0w6MKnbqhdBad9qTobSfB20Ld7UmgoNbAZkQ==
@@ -7139,7 +7139,7 @@ loader-runner@^2.4.0:
71397139
resolved "https://registry.yarnpkg.com/loader-runner/-/loader-runner-2.4.0.tgz#ed47066bfe534d7e84c4c7b9998c2a75607d9357"
71407140
integrity sha512-Jsmr89RcXGIwivFY21FcRrisYZfvLMTWx5kOLc+JTxtpBOG6xML0vzbc6SEQG2FO9/4Fc3wW4LVcB5DmGflaRw==
71417141

7142-
loader-utils@^1.2.3, loader-utils@^1.4.0:
7142+
loader-utils@^1.0.2, loader-utils@^1.2.3, loader-utils@^1.4.0:
71437143
version "1.4.0"
71447144
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.4.0.tgz#c579b5e34cb34b1a74edc6c1fb36bfa371d5a613"
71457145
integrity sha512-qH0WSMBtn/oHuwjy/NucEgbx5dbxxnxup9s4PVXJUDHZBQY+s0NWA9rJf53RBnQZxfch7euUui7hpoAPvALZdA==
@@ -7552,6 +7552,14 @@ micromatch@^3.0.4, micromatch@^3.1.10, micromatch@^3.1.4, micromatch@^3.1.8:
75527552
snapdragon "^0.8.1"
75537553
to-regex "^3.0.2"
75547554

7555+
micromatch@^4.0.0:
7556+
version "4.0.2"
7557+
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.2.tgz#4fcb0999bf9fbc2fcbdd212f6d629b9a56c39259"
7558+
integrity sha512-y7FpHSbMUMoyPbYUSzO6PaZ6FyRnQOpHuKwbo1G+Knck95XVU4QAiKdGEnj5wwoS7PlOgthX/09u5iFJ+aYf5Q==
7559+
dependencies:
7560+
braces "^3.0.1"
7561+
picomatch "^2.0.5"
7562+
75557563
miller-rabin@^4.0.0:
75567564
version "4.0.1"
75577565
resolved "https://registry.yarnpkg.com/miller-rabin/-/miller-rabin-4.0.1.tgz#f080351c865b0dc562a8462966daa53543c78a4d"
@@ -8911,7 +8919,7 @@ pick@ianstormtaylor/pick:
89118919
version "0.1.0"
89128920
resolved "https://codeload.github.com/ianstormtaylor/pick/tar.gz/e648ac527026b5bfd0c34bf77e4acc161e30f12d"
89138921

8914-
picomatch@^2.0.4, picomatch@^2.2.1:
8922+
picomatch@^2.0.4, picomatch@^2.0.5, picomatch@^2.2.1:
89158923
version "2.2.2"
89168924
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.2.2.tgz#21f333e9b6b8eaff02468f5146ea406d345f4dad"
89178925
integrity sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg==
@@ -11065,6 +11073,17 @@ tryer@^1.0.1:
1106511073
resolved "https://registry.yarnpkg.com/tryer/-/tryer-1.0.1.tgz#f2c85406800b9b0f74c9f7465b81eaad241252f8"
1106611074
integrity sha512-c3zayb8/kWWpycWYg87P71E1S1ZL6b6IJxfb5fvsUgsf0S2MVGaDhDXXjDMpdCpfWXqptc+4mXwmiy1ypXqRAA==
1106711075

11076+
ts-loader@^8.0.4:
11077+
version "8.0.4"
11078+
resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-8.0.4.tgz#02b9c91fbcfdb3114d8b1e98a3829265270eee7a"
11079+
integrity sha512-5u8KF1SW8eCUb/Ff7At81e3wznPmT/27fvaGRO9CziVy+6NlPVRvrzSox4OwU0/e6OflOUB32Err4VquysCSAQ==
11080+
dependencies:
11081+
chalk "^2.3.0"
11082+
enhanced-resolve "^4.0.0"
11083+
loader-utils "^1.0.2"
11084+
micromatch "^4.0.0"
11085+
semver "^6.0.0"
11086+
1106811087
ts-node@^9.0.0:
1106911088
version "9.0.0"
1107011089
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-9.0.0.tgz#e7699d2a110cc8c0d3b831715e417688683460b3"

0 commit comments

Comments
 (0)