Skip to content

Commit

Permalink
Enable production sourcemap for index.js, fix css sourcemaps
Browse files Browse the repository at this point in the history
  • Loading branch information
silverwind committed Sep 26, 2023
1 parent eab20cb commit e1f22ac
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/content/installation/from-source.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ If pre-built frontend files are present it is possible to only build the backend
TAGS="bindata" make backend
```

Webpack source maps are by default enabled in development builds and disabled in production builds. They can be enabled by setting the `ENABLE_SOURCEMAP=true` environment variable.
Webpack source maps are limited by default to conserve space. When `ENABLE_SOURCEMAP=true` is set, the webpack build will generate all source maps.

## Test

Expand Down
2 changes: 1 addition & 1 deletion docs/content/installation/from-source.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ TAGS="bindata sqlite sqlite_unlock_notify" make build
TAGS="bindata" make backend
```

在开发构建中,默认启用 Webpack 源映射,在生产构建中禁用。可以通过设置`ENABLE_SOURCEMAP=true`环境变量来启用它们
默认情况下,Webpack 源映射受到限制以节省空间。 当设置`ENABLE_SOURCEMAP=true`时,webpack 构建将生成所有源映射

## 测试

Expand Down
19 changes: 12 additions & 7 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ for (const path of glob('web_src/css/themes/*.css')) {

const isProduction = env.NODE_ENV !== 'development';

let sourceMapEnabled;
// The production build only generates limited sourcemaps to conserve binary size.
// When in development or when ENABLE_SOURCEMAP=true, generate all source maps.
let fullSourceMapEnabled;
if ('ENABLE_SOURCEMAP' in env) {
sourceMapEnabled = env.ENABLE_SOURCEMAP === 'true';
fullSourceMapEnabled = env.ENABLE_SOURCEMAP === 'true';
} else {
sourceMapEnabled = !isProduction;
fullSourceMapEnabled = !isProduction;
}

const filterCssImport = (url, ...args) => {
Expand Down Expand Up @@ -105,7 +107,9 @@ export default {
css: !LightningCssMinifyPlugin,
legalComments: 'none',
}),
LightningCssMinifyPlugin && new LightningCssMinifyPlugin(),
LightningCssMinifyPlugin && new LightningCssMinifyPlugin({
sourceMap: fullSourceMapEnabled,
}),
],
splitChunks: {
chunks: 'async',
Expand Down Expand Up @@ -143,7 +147,7 @@ export default {
{
loader: 'css-loader',
options: {
sourceMap: sourceMapEnabled,
sourceMap: fullSourceMapEnabled,
url: {filter: filterCssImport},
import: {filter: filterCssImport},
},
Expand Down Expand Up @@ -181,9 +185,10 @@ export default {
filename: 'css/[name].css',
chunkFilename: 'css/[name].[contenthash:8].css',
}),
sourceMapEnabled && (new SourceMapDevToolPlugin({
new SourceMapDevToolPlugin({
filename: '[file].[contenthash:8].map',
})),
...(!fullSourceMapEnabled && {include: /^js\/index\.js$/}),
}),
new MonacoWebpackPlugin({
filename: 'js/monaco-[name].[contenthash:8].worker.js',
}),
Expand Down

0 comments on commit e1f22ac

Please sign in to comment.