Skip to content

Commit 7aed96e

Browse files
authored
Fix debug experience (#1125)
1 parent 9063d37 commit 7aed96e

File tree

6 files changed

+31
-15
lines changed

6 files changed

+31
-15
lines changed

.changeset/clever-pots-smash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@segment/analytics-next': patch
3+
---
4+
5+
Update init to allow for asset path overriding and fix debugging experience

packages/browser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"tsc": "yarn run -T tsc",
3333
"jest": "yarn run -T jest",
3434
"concurrently": "yarn run -T concurrently",
35-
"watch": "yarn concurrently 'NODE_ENV=production WATCH=true yarn umd --watch' 'yarn pkg --watch'",
35+
"watch": "yarn concurrently 'WATCH=true yarn umd --watch' 'yarn pkg --watch'",
3636
"build": "yarn clean && yarn build-prep && yarn concurrently 'NODE_ENV=production yarn umd' 'yarn pkg' 'yarn cjs'",
3737
"release:cdn": "yarn . build && NODE_ENV=production bash scripts/release.sh && NODE_ENV=stage bash scripts/release.sh",
3838
"pkg": "yarn tsc -p tsconfig.build.json",

packages/browser/src/browser/browser-umd.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { getCDN, setGlobalCDNUrl } from '../lib/parse-cdn'
22
import { setVersionType } from '../lib/version-type'
33

4-
if (process.env.ASSET_PATH) {
5-
if (process.env.ASSET_PATH === '/dist/umd/') {
4+
if (process.env.IS_WEBPACK_BUILD) {
5+
if (process.env.ASSET_PATH) {
66
// @ts-ignore
7-
__webpack_public_path__ = '/dist/umd/'
7+
__webpack_public_path__ = process.env.ASSET_PATH
88
} else {
99
const cdn = getCDN()
10-
setGlobalCDNUrl(cdn) // preserving original behavior -- TODO: neccessary?
10+
setGlobalCDNUrl(cdn)
1111

1212
// @ts-ignore
1313
__webpack_public_path__ = cdn + '/analytics-next/bundles/'

packages/browser/src/browser/standalone.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import { getCDN, setGlobalCDNUrl } from '../lib/parse-cdn'
33
import { setVersionType } from '../lib/version-type'
44

5-
if (process.env.ASSET_PATH) {
6-
if (process.env.ASSET_PATH === '/dist/umd/') {
5+
if (process.env.IS_WEBPACK_BUILD) {
6+
if (process.env.ASSET_PATH) {
77
// @ts-ignore
8-
__webpack_public_path__ = '/dist/umd/'
8+
__webpack_public_path__ = process.env.ASSET_PATH
99
} else {
1010
const cdn = getCDN()
1111
setGlobalCDNUrl(cdn)

packages/browser/webpack.config.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,26 @@ const BundleAnalyzerPlugin =
77
const CircularDependencyPlugin = require('circular-dependency-plugin')
88

99
const isProd = process.env.NODE_ENV === 'production'
10-
const ASSET_PATH = isProd
11-
? 'https://cdn.segment.com/analytics-next/bundles/'
12-
: '/dist/umd/'
10+
11+
const ASSET_PATH = process.env.ASSET_PATH
12+
? process.env.ASSET_PATH
13+
: !isProd
14+
? '/dist/umd/'
15+
: ''
16+
17+
const envPluginConfig = {
18+
ASSET_PATH: ASSET_PATH,
19+
IS_WEBPACK_BUILD: true,
20+
}
21+
22+
console.log('Running Webpack Build', {
23+
NODE_ENV: process.env.NODE_ENV,
24+
'Webpack Environment Plugin': envPluginConfig,
25+
})
1326

1427
const plugins = [
1528
new CompressionPlugin({}),
16-
new webpack.EnvironmentPlugin({
17-
ASSET_PATH,
18-
}),
29+
new webpack.EnvironmentPlugin(envPluginConfig),
1930
new CircularDependencyPlugin({
2031
failOnError: true,
2132
}),

playgrounds/standalone-playground/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"scripts": {
88
".": "yarn run -T turbo run --filter=@playground/standalone-playground...",
99
"start": "yarn http-server . -o /pages",
10-
"dev": "yarn concurrently 'yarn . build && yarn start' 'sleep 10 && yarn . watch'",
10+
"dev": "yarn concurrently 'yarn start' 'sleep 3 && ASSET_PATH='/node_modules/@segment/analytics-next/dist/umd/' yarn . watch'",
1111
"concurrently": "yarn run -T concurrently"
1212
},
1313
"dependencies": {

0 commit comments

Comments
 (0)