Skip to content
Draft
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
45 changes: 29 additions & 16 deletions cli/config/makeBabelConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,36 @@ const getBabelModuleType = (moduleType) => {
return false
}
}
const makeBabelConfig = ({ moduleType, mode }) => {
const makeBabelConfig = ({ moduleType, mode, isAppType }) => {
const isTest = mode === 'test'

const styledJsxConfig = {
env: {
production: {
plugins: [
[require('styled-jsx/babel'), { optimizeForSpeed: true }],
],
},
development: {
plugins: [
[require('styled-jsx/babel'), { optimizeForSpeed: true }],
],
},
test: {
plugins: [require('styled-jsx/babel-test')],
},
},
}

// Minimal transpiling for apps
if (isAppType) {
return {
presets: ['@babel/preset-typescript'],
...styledJsxConfig,
}
}

// More for libs
return {
presets: [
require('@babel/preset-react'),
Expand Down Expand Up @@ -53,21 +80,7 @@ const makeBabelConfig = ({ moduleType, mode }) => {
// Adds support for default value using ?? operator
require('@babel/plugin-proposal-nullish-coalescing-operator'),
],
env: {
production: {
plugins: [
[require('styled-jsx/babel'), { optimizeForSpeed: true }],
],
},
development: {
plugins: [
[require('styled-jsx/babel'), { optimizeForSpeed: true }],
],
},
test: {
plugins: [require('styled-jsx/babel-test')],
},
},
...styledJsxConfig,
}
}

Expand Down
14 changes: 8 additions & 6 deletions cli/src/lib/compiler/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const compile = async ({
fs.copySync(paths.shellSourcePublic, paths.shellPublic)
}

const babelConfig = makeBabelConfig({ moduleType, mode })
const babelConfig = makeBabelConfig({ moduleType, mode, isAppType })

const copyFile = async (source, destination) => {
reporter.debug(
Expand All @@ -112,18 +112,20 @@ const compile = async ({
babelConfig
)

// Always write .js files
const jsDestination = normalizeExtension(destination)
// Always write .js files for libraries; don't change for apps
const resolvedDestination = isAppType
? destination
: normalizeExtension(destination)

reporter.debug(
`Compiled ${prettyPrint.relativePath(
source
)} with Babel, saving to ${prettyPrint.relativePath(
jsDestination
resolvedDestination
)}`
)

await fs.writeFile(jsDestination, result.code)
await fs.writeFile(resolvedDestination, result.code)
} catch (err) {
reporter.dumpErr(err)
reporter.error(
Expand All @@ -143,7 +145,7 @@ const compile = async ({
outputDir: outDir,
// todo: handle lib compilations with Vite
// https://dhis2.atlassian.net/browse/LIBS-722
processFileCallback: isAppType ? copyFile : compileFile,
processFileCallback: compileFile,
watch,
}),
isAppType &&
Expand Down
Loading