diff --git a/packages/oc-template-typescript-react-compiler/lib/compileView.js b/packages/oc-template-typescript-react-compiler/lib/compileView.js index a3b66fb..5138784 100644 --- a/packages/oc-template-typescript-react-compiler/lib/compileView.js +++ b/packages/oc-template-typescript-react-compiler/lib/compileView.js @@ -53,6 +53,7 @@ module.exports = (options, callback) => { const reactOCProviderPath = path.join(tempPath, reactOCProviderName); const compile = (options, cb) => { + const generateSourceMaps = process.env.GENERATE_SOURCEMAP !== 'false' && (process.env.GENERATE_SOURCEMAP === 'true' || !production); const config = webpackConfigurator({ componentPath, viewPath: options.viewPath, @@ -64,8 +65,10 @@ module.exports = (options, callback) => { publishFileName, usingTypescript, production, - buildIncludes: componentPackage.oc.files.template.buildIncludes || [] + buildIncludes: componentPackage.oc.files.template.buildIncludes || [], + generateSourceMaps }); + compiler(config, (err, data) => { if (err) { return cb(err); @@ -80,6 +83,12 @@ module.exports = (options, callback) => { const wrappedBundle = reactComponentWrapper(bundleHash, bundle); fs.outputFileSync(bundlePath, wrappedBundle); + if (generateSourceMaps) { + const sourceMap = memoryFs.readFileSync(`/build/${config.output.filename}.map`, 'UTF8'); + const mapBunldePath = path.join(publishPath, `${publishFileName}.map`); + fs.outputFileSync(mapBunldePath, sourceMap); + } + let css = null; const cssFile = Object.keys(data.build).filter((x) => x.endsWith('.css'))[0]; if (cssFile) { diff --git a/packages/oc-template-typescript-react-compiler/lib/to-abstract-base-template-utils/oc-webpack/lib/configurator/client/index.js b/packages/oc-template-typescript-react-compiler/lib/to-abstract-base-template-utils/oc-webpack/lib/configurator/client/index.js index c0713ba..9de453e 100644 --- a/packages/oc-template-typescript-react-compiler/lib/to-abstract-base-template-utils/oc-webpack/lib/configurator/client/index.js +++ b/packages/oc-template-typescript-react-compiler/lib/to-abstract-base-template-utils/oc-webpack/lib/configurator/client/index.js @@ -9,10 +9,6 @@ const postcssNormalize = require('postcss-normalize'); const commonConfig = require('../commonConfig'); const createExcludeRegex = require('../createExcludeRegex'); -// const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false'; -// DISABLE UNTIL FIGURE HOW TO MAKE IT WORK WITH TESTS -const shouldUseSourceMap = false; - function getCacheIdentifier(environment, packages) { let cacheIdentifier = environment == null ? '' : environment.toString(); for (const packageName of packages) { @@ -33,6 +29,8 @@ module.exports = (options) => { const isEnvProduction = !!options.production; const isEnvDevelopment = !isEnvProduction; + const shouldUseSourceMaps = options.generateSourceMaps; + process.env.BABEL_ENV = isEnvProduction ? 'production' : 'development'; const buildIncludes = options.buildIncludes.concat('oc-template-typescript-react-compiler/utils'); const excludeRegex = createExcludeRegex(buildIncludes); @@ -87,7 +85,7 @@ module.exports = (options) => { postcssNormalize() ] }, - sourceMap: isEnvProduction && shouldUseSourceMap + sourceMap: shouldUseSourceMaps } } ].filter(Boolean); @@ -96,7 +94,7 @@ module.exports = (options) => { { loader: require.resolve('resolve-url-loader'), options: { - sourceMap: isEnvProduction ? shouldUseSourceMap : true, + sourceMap: shouldUseSourceMaps, root: appSrc } }, @@ -119,7 +117,8 @@ module.exports = (options) => { isEnvProduction, entry: options.viewPath, usingTypescript: options.usingTypescript, - componentPath: options.componentPath + componentPath: options.componentPath, + shouldUseSourceMaps, }), context: options.componentPath, output: { @@ -133,7 +132,7 @@ module.exports = (options) => { module: { strictExportPresence: true, rules: [ - shouldUseSourceMap && { + shouldUseSourceMaps && { enforce: 'pre', exclude: /@babel(?:\/|\\{1,2})runtime/, test: /\.(js|mjs|jsx|ts|tsx|css)$/, @@ -230,8 +229,8 @@ module.exports = (options) => { 'react-scripts' ] ), - sourceMaps: shouldUseSourceMap, - inputSourceMap: shouldUseSourceMap + sourceMaps: shouldUseSourceMaps, + inputSourceMap: shouldUseSourceMaps } } ].filter(Boolean) diff --git a/packages/oc-template-typescript-react-compiler/lib/to-abstract-base-template-utils/oc-webpack/lib/configurator/commonConfig.js b/packages/oc-template-typescript-react-compiler/lib/to-abstract-base-template-utils/oc-webpack/lib/configurator/commonConfig.js index e5b4220..32af005 100644 --- a/packages/oc-template-typescript-react-compiler/lib/to-abstract-base-template-utils/oc-webpack/lib/configurator/commonConfig.js +++ b/packages/oc-template-typescript-react-compiler/lib/to-abstract-base-template-utils/oc-webpack/lib/configurator/commonConfig.js @@ -7,8 +7,6 @@ const webpack = require('webpack'); const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'); const ESLintPlugin = require('eslint-webpack-plugin'); -// const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false'; -const shouldUseSourceMap = false; const emitErrorsAsWarnings = process.env.ESLINT_NO_DEV_ERRORS === 'true'; const disableESLintPlugin = process.env.DISABLE_ESLINT_PLUGIN === 'true'; @@ -31,7 +29,8 @@ module.exports = function getConfig({ isEnvProduction, entry, usingTypescript, - configPath + configPath, + shouldUseSourceMaps }) { const isEnvDevelopment = !isEnvProduction; const skipTypecheck = @@ -55,7 +54,7 @@ module.exports = function getConfig({ .filter((ext) => usingTypescript || !ext.includes('ts')) }, devtool: isEnvProduction - ? shouldUseSourceMap + ? shouldUseSourceMaps ? 'source-map' : false : 'cheap-module-source-map', @@ -108,7 +107,7 @@ module.exports = function getConfig({ }), configOverwrite: { compilerOptions: { - sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment, + sourceMap: isEnvProduction ? shouldUseSourceMaps : isEnvDevelopment, skipLibCheck: true, inlineSourceMap: false, declarationMap: false, diff --git a/packages/oc-template-typescript-react-compiler/package.json b/packages/oc-template-typescript-react-compiler/package.json index 2f8baec..3b07a0c 100644 --- a/packages/oc-template-typescript-react-compiler/package.json +++ b/packages/oc-template-typescript-react-compiler/package.json @@ -1,6 +1,6 @@ { "name": "oc-template-typescript-react-compiler", - "version": "3.8.0", + "version": "3.8.1", "description": "", "main": "index.js", "repository": {