Skip to content

Commit

Permalink
Merge pull request #6 from TangibleInc/no-sourcemaps-for-production
Browse files Browse the repository at this point in the history
Generate source maps during development only and remove from production release
  • Loading branch information
eliot-akira authored May 28, 2024
2 parents 053f799 + 20ca89a commit 4d64d87
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
10 changes: 9 additions & 1 deletion commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

const path = require('path')
const fs = require('fs/promises')
const rollup = require('rollup')
const getFileSize = require('../utils/getFileSize')
const displayError = require('../utils/displayError')
Expand All @@ -15,7 +16,7 @@ async function build(props) {
return await inputOptions.build(props)
}

const { cwd, rootDir } = config
const { cwd, rootDir, isDev } = config

console.log('..Building from', path.relative(cwd, inputOptions.input))

Expand All @@ -41,6 +42,13 @@ async function build(props) {
// , 'in', (duration / 1000).toFixed(2)+'s'
`(${fileSize})`
)

if (task.map === 'dev') {
// Remove source maps for production
await fs.rm(`${builtFile}.map`, {
force: true, // exceptions will be ignored if path does not exist
})
}
}

module.exports = build
7 changes: 7 additions & 0 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,15 @@ async function createConfig({ commandName, subproject }) {
lint,
serve,
archive,
map = 'dev' // Global default, can override per task
} = configJson instanceof Function ? await configJson() : configJson

for (const task of tasks) {
if (typeof task.map==='undefined') {
task.map = map
}
}

// Ensure project dependencies are installed
if (
Object.keys(dependencies).length > 0 &&
Expand Down
7 changes: 6 additions & 1 deletion task/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ function createTaskConfigs({ config, task }) {
task.task === 'sass'
? task.dest + '.tmp' // PostCSS emits its own file
: task.dest,
sourcemap: task.task === 'sass' ? false : task.map !== false, // true by default
sourcemap: task.task === 'sass'
? false
: task.map === 'dev' // See ../config for global default
? isDev // Only during development
: task.map !== false
,

// Use default source map name to support dynamic exports and code splitting
// sourcemapFile: task.dest + '.map',
Expand Down
4 changes: 2 additions & 2 deletions test/tangible.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module.exports = {
{
src: 'src/index.jsx',
dest: 'build/test.min.js',
react: 'react'
react: 'react',
map: true, // Test override global default (source map during development only, remove for production)
},
{
src: 'src/index.jsx',
Expand Down Expand Up @@ -40,7 +41,6 @@ module.exports = {
async function({ config, task = {} }) {
console.log('Custom build function')
}

],
format: 'src',
serve: {
Expand Down

0 comments on commit 4d64d87

Please sign in to comment.