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

enable client sourcemaps #44

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand All @@ -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`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo, I guess this should be mapBundlePath

fs.outputFileSync(mapBunldePath, sourceMap);
}

let css = null;
const cssFile = Object.keys(data.build).filter((x) => x.endsWith('.css'))[0];
if (cssFile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -87,7 +85,7 @@ module.exports = (options) => {
postcssNormalize()
]
},
sourceMap: isEnvProduction && shouldUseSourceMap
sourceMap: shouldUseSourceMaps
}
}
].filter(Boolean);
Expand All @@ -96,7 +94,7 @@ module.exports = (options) => {
{
loader: require.resolve('resolve-url-loader'),
options: {
sourceMap: isEnvProduction ? shouldUseSourceMap : true,
sourceMap: shouldUseSourceMaps,
root: appSrc
}
},
Expand All @@ -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: {
Expand All @@ -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)$/,
Expand Down Expand Up @@ -230,8 +229,8 @@ module.exports = (options) => {
'react-scripts'
]
),
sourceMaps: shouldUseSourceMap,
inputSourceMap: shouldUseSourceMap
sourceMaps: shouldUseSourceMaps,
inputSourceMap: shouldUseSourceMaps
}
}
].filter(Boolean)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -31,7 +29,8 @@ module.exports = function getConfig({
isEnvProduction,
entry,
usingTypescript,
configPath
configPath,
shouldUseSourceMaps
}) {
const isEnvDevelopment = !isEnvProduction;
const skipTypecheck =
Expand All @@ -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',
Expand Down Expand Up @@ -108,7 +107,7 @@ module.exports = function getConfig({
}),
configOverwrite: {
compilerOptions: {
sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment,
sourceMap: isEnvProduction ? shouldUseSourceMaps : isEnvDevelopment,
skipLibCheck: true,
inlineSourceMap: false,
declarationMap: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oc-template-typescript-react-compiler",
"version": "3.8.0",
"version": "3.8.1",
"description": "",
"main": "index.js",
"repository": {
Expand Down