Skip to content

Commit 4a96189

Browse files
authored
fix(sourcemaps): fix sourcemap generation for browser code [triage-skip] (#29)
* fix(sourcemaps): fix sourcemap generation for browser code * chore(*): add ts-loader dependencies
1 parent f70c7f2 commit 4a96189

File tree

3 files changed

+71
-38
lines changed

3 files changed

+71
-38
lines changed

gulp/tasks/build.js

Lines changed: 51 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function cleanDist(dir) {
5252

5353
function compileTypescriptToES2015() {
5454
const stream = tsProject.src()
55-
.pipe(sourcemaps.init({loadMaps: true}))
55+
.pipe(sourcemaps.init({ loadMaps: true }))
5656
.pipe(tsProject());
5757
return merge([
5858
stream.dts
@@ -65,7 +65,7 @@ function compileTypescriptToES2015() {
6565

6666
function compileES2015ToCJS() {
6767
return gulp.src('dist/es2015/**/*.js')
68-
.pipe(sourcemaps.init({loadMaps: true}))
68+
.pipe(sourcemaps.init({ loadMaps: true }))
6969
.pipe(babel(config.babel))
7070
.pipe(sourcemaps.write('.'))
7171
.pipe(gulp.dest(`${config.paths.outDir}/cjs`))
@@ -115,30 +115,46 @@ function compileIndvES2015ModulesToBrowser() {
115115
return pathObj.name === 'firebase-app';
116116
};
117117

118-
// Webpack config for compiling indv modules
118+
const babelLoader = {
119+
loader: 'babel-loader',
120+
options: config.babel
121+
};
122+
123+
const tsLoader = {
124+
loader: 'ts-loader',
125+
options: {
126+
compilerOptions: {
127+
declaration: false
128+
}
129+
}
130+
};
131+
119132
const webpackConfig = {
133+
devtool: 'source-map',
120134
entry: {
121-
'firebase-app': './dist/es2015/app.js',
122-
'firebase-storage': './dist/es2015/storage.js',
123-
'firebase-messaging': './dist/es2015/messaging.js',
135+
'firebase-app': './src/app.ts',
136+
'firebase-storage': './src/storage.ts',
137+
'firebase-messaging': './src/messaging.ts',
124138
},
125139
output: {
126-
filename: '[name].js',
140+
path: path.resolve(__dirname, './dist/browser'),
141+
filename: '[name].js'
127142
},
128143
module: {
129-
rules: [
130-
{
131-
test: /\.js$/,
132-
exclude: /(node_modules|bower_components)/,
133-
use: {
134-
loader: 'babel-loader',
135-
options: {
136-
presets: config.babel.presets,
137-
plugins: config.babel.plugins
138-
}
139-
}
140-
}
141-
]
144+
rules: [{
145+
test: /\.ts(x?)$/,
146+
exclude: /node_modules/,
147+
use: [
148+
babelLoader,
149+
tsLoader
150+
]
151+
}, {
152+
test: /\.js$/,
153+
exclude: /node_modules/,
154+
use: [
155+
babelLoader
156+
]
157+
}]
142158
},
143159
plugins: [
144160
new webpack.optimize.CommonsChunkPlugin({
@@ -147,7 +163,7 @@ function compileIndvES2015ModulesToBrowser() {
147163
new WrapperPlugin({
148164
header: fileName => {
149165
return isFirebaseApp(fileName) ? `var firebase = (function() {
150-
var window = typeof window === 'undefined' ? self : window;
166+
var window = typeof window === 'undefined' ? self : window;
151167
return ` : `try {
152168
`;
153169
},
@@ -162,20 +178,17 @@ function compileIndvES2015ModulesToBrowser() {
162178
}`
163179
}
164180
}),
165-
new webpack.optimize.UglifyJsPlugin()
166-
]
167-
};
168-
return gulp.src('./dist/es2015/firebase.js')
181+
new webpack.optimize.UglifyJsPlugin({
182+
sourceMap: true
183+
})
184+
],
185+
resolve: {
186+
extensions: ['.ts', '.tsx', '.js']
187+
},
188+
}
189+
190+
return gulp.src('src/**/*.ts')
169191
.pipe(webpackStream(webpackConfig, webpack))
170-
.pipe(sourcemaps.init({loadMaps: true}))
171-
.pipe(through.obj(function(file, enc, cb) {
172-
// Dont pipe through any source map files as it will be handled
173-
// by gulp-sourcemaps
174-
var isSourceMap = /\.map$/.test(file.path);
175-
if (!isSourceMap) this.push(file);
176-
cb();
177-
}))
178-
.pipe(sourcemaps.write('.'))
179192
.pipe(gulp.dest(`${config.paths.outDir}/browser`));
180193
}
181194

@@ -188,7 +201,7 @@ function compileSDKES2015ToBrowser() {
188201
})
189202
]
190203
}, webpack))
191-
.pipe(sourcemaps.init({loadMaps: true}))
204+
.pipe(sourcemaps.init({ loadMaps: true }))
192205
.pipe(through.obj(function(file, enc, cb) {
193206
// Dont pipe through any source map files as it will be handled
194207
// by gulp-sourcemaps
@@ -202,7 +215,9 @@ function compileSDKES2015ToBrowser() {
202215

203216
function buildBrowserFirebaseJs() {
204217
return gulp.src('./dist/browser/*.js')
218+
.pipe(sourcemaps.init({ loadMaps: true }))
205219
.pipe(concat('firebase.js'))
220+
.pipe(sourcemaps.write('.'))
206221
.pipe(gulp.dest(`${config.paths.outDir}/browser`));
207222
}
208223

@@ -223,7 +238,7 @@ function buildAltEnvFirebaseJs() {
223238
]
224239
});
225240
return gulp.src('./dist/es2015/firebase.js')
226-
.pipe(sourcemaps.init({loadMaps: true}))
241+
.pipe(sourcemaps.init({ loadMaps: true }))
227242
.pipe(babel(babelConfig))
228243
.pipe(rename({
229244
suffix: `-${env}`

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"shx": "^0.2.2",
7878
"sinon": "^2.1.0",
7979
"through2": "^2.0.3",
80+
"ts-loader": "^2.1.0",
8081
"ts-node": "2.1.1",
8182
"typescript": "^2.2.1",
8283
"validate-commit-msg": "^2.12.1",

yarn.lock

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ [email protected]:
13611361
version "1.0.3"
13621362
resolved "https://registry.yarnpkg.com/colors/-/colors-1.0.3.tgz#0433f44d809680fdeb60ed260f1b0c262e82a40b"
13631363

1364-
colors@^1.1.0, colors@^1.1.2:
1364+
colors@^1.0.3, colors@^1.1.0, colors@^1.1.2:
13651365
version "1.1.2"
13661366
resolved "https://registry.yarnpkg.com/colors/-/colors-1.1.2.tgz#168a4701756b6a7f51a12ce0c97bfa28c084ed63"
13671367

@@ -3682,6 +3682,14 @@ loader-utils@^0.2.11, loader-utils@^0.2.16:
36823682
json5 "^0.5.0"
36833683
object-assign "^4.0.1"
36843684

3685+
loader-utils@^1.0.2:
3686+
version "1.1.0"
3687+
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.1.0.tgz#c98aef488bcceda2ffb5e2de646d6a754429f5cd"
3688+
dependencies:
3689+
big.js "^3.1.3"
3690+
emojis-list "^2.0.0"
3691+
json5 "^0.5.0"
3692+
36853693
lodash._baseassign@^3.0.0:
36863694
version "3.2.0"
36873695
resolved "https://registry.yarnpkg.com/lodash._baseassign/-/lodash._baseassign-3.2.0.tgz#8c38a099500f215ad09e59f1722fd0c52bfe0a4e"
@@ -5156,7 +5164,7 @@ [email protected], semver-regex@^1.0.0:
51565164
version "1.0.0"
51575165
resolved "https://registry.yarnpkg.com/semver-regex/-/semver-regex-1.0.0.tgz#92a4969065f9c70c694753d55248fc68f8f652c9"
51585166

5159-
"semver@2 || 3 || 4 || 5", semver@^5.3.0:
5167+
"semver@2 || 3 || 4 || 5", semver@^5.0.1, semver@^5.3.0:
51605168
version "5.3.0"
51615169
resolved "https://registry.yarnpkg.com/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f"
51625170

@@ -5760,6 +5768,15 @@ trim-right@^1.0.1:
57605768
version "1.0.1"
57615769
resolved "https://registry.yarnpkg.com/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003"
57625770

5771+
ts-loader@^2.1.0:
5772+
version "2.1.0"
5773+
resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-2.1.0.tgz#5a8efcc5c72c06fc49d69bad69c85617c6194f77"
5774+
dependencies:
5775+
colors "^1.0.3"
5776+
enhanced-resolve "^3.0.0"
5777+
loader-utils "^1.0.2"
5778+
semver "^5.0.1"
5779+
57635780
57645781
version "2.1.1"
57655782
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-2.1.1.tgz#2fe7049ea56319730052a9e677985e6151a7bd31"

0 commit comments

Comments
 (0)