Skip to content
This repository has been archived by the owner on Jan 31, 2023. It is now read-only.

Enable source maps by default #26

Merged
merged 1 commit into from
May 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ If you pass one of the top-level options in (`extensions`, `transform`, etc), it

[watchify](https://github.com/browserify/watchify) is automatically configured as a plugin (as needed), so it's not necessary to manually specify it.

Source maps are always enabled unless explicitly disabled by specifying `debug: false`.

**Default**:

```javascript
Expand Down Expand Up @@ -92,6 +94,7 @@ If you pass one of the top-level options in (`extensions`, `transform`, etc), it
},
]
],
debug: true,
plugin: [],
cache: {},
packageCache: {}
Expand Down
3 changes: 2 additions & 1 deletion __snapshots__/e2e_spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 29 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const path = require('path')
const Promise = require('bluebird')
const fs = require('./fs')

const cloneDeep = require('lodash.clonedeep')
const browserify = require('browserify')
const watchify = require('watchify')

Expand All @@ -26,10 +27,9 @@ const defaultOptions = {
{
ast: false,
babelrc: false,
// irons out differents between ES6 modules and node exports
plugins: [
...[
'babel-plugin-add-module-exports',
'babel-plugin-add-module-exports', // irons out differences between ES6 modules and node exports
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-object-rest-spread',
].map(require.resolve),
Expand Down Expand Up @@ -60,6 +60,32 @@ const defaultOptions = {
},
}

const getBrowserifyOptions = (entry, userBrowserifyOptions = {}) => {
let browserifyOptions = cloneDeep(defaultOptions.browserifyOptions)

// allow user to override default options
browserifyOptions = Object.assign(browserifyOptions, userBrowserifyOptions, {
// these must always be new objects or 'update' events will not fire
cache: {},
packageCache: {},
})

// unless user has explicitly turned off source map support, always enable it
// so we can use it to point user to the source code
if (userBrowserifyOptions.debug !== false) {
browserifyOptions.debug = true
}

// we need to override and control entries
Object.assign(browserifyOptions, {
entries: [entry],
})

debug('browserifyOptions: %o', browserifyOptions)

return browserifyOptions
}

// export a function that returns another function, making it easy for users
// to configure like so:
//
Expand Down Expand Up @@ -101,20 +127,9 @@ const preprocessor = (options = {}) => {
debug('input:', filePath)
debug('output:', outputPath)

// allow user to override default options
const browserifyOptions = Object.assign({}, defaultOptions.browserifyOptions, options.browserifyOptions, {
// these must always be new objects or 'update' events will not fire
cache: {},
packageCache: {},
})
const browserifyOptions = getBrowserifyOptions(filePath, options.browserifyOptions)
const watchifyOptions = Object.assign({}, defaultOptions.watchifyOptions, options.watchifyOptions)

// we need to override and control entries
Object.assign(browserifyOptions, {
entries: [filePath],
})

debug('browserifyOptions %o:', browserifyOptions)
const bundler = browserify(browserifyOptions)

if (file.shouldWatch) {
Expand Down
Loading