Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate source maps during development only and remove from production release #6

Merged
merged 2 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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 = true // or 'dev'
} = 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'
? isDev // Only during development
: task.map !== false // true by default
,

// 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
@@ -1,9 +1,10 @@
module.exports = {
map: 'dev', // Source map during development only - Remove for production
build: [
{
src: 'src/index.jsx',
dest: 'build/test.min.js',
react: 'react'
react: 'react',
},
{
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