lukeed / lukeed/webpack-plugin-replace

ERROR in http.min.js from Terser

Open
#7 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
36
Forks
8
PR merge metrics
No merged PRs in 30d

Description

When I set webpack config `mode: 'production'`,it throw error:

```
ERROR in http.min.js from Terser
"Export" statement may only appear at the top level [http.min.js:1161,0]
```

But when I set `mode: 'development'`,it works...I can't figure out why.

```js
// http.js

const http = () => {}

http.version = '__version__';

export default http;
```

```js
// webpack.build-lib.js
const path = require('path');
const ReplacePlugin = require('../lib/webpack-plugin-replace');
const rootPath = path.resolve(__dirname, '..');
const pkg = require('../package.json');

const libName = 'http';
const entryFile = path.resolve(rootPath, `src/${libName}.js`);

module.exports = {
entry: entryFile,
mode: 'production',
output: {
path: path.resolve(rootPath, 'lib'),
filename: `${libName}.min.js`,
libraryTarget: 'umd2',
libraryExport: 'default',
},
plugins: [
new ReplacePlugin({
exclude: [
/node_modules/,
],
patterns: [{
regex: /__version__/g,
value: pkg.version,
}],
}),
],
};

```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with http.js and webpack.build-lib.js, then run the production build that uses mode: 'production' and Terser; compare it with the development build. Trace how the ReplacePlugin output reaches lib/http.min.js and determine why the export is no longer at the top level. Done means the production build completes without the reported Terser error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.