Skip to content

ERROR in http.min.js from Terser #7

@ringcrl

Description

@ringcrl

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.

// http.js

const http = () => {}

http.version = '__version__';

export default http;
// 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,
      }],
    }),
  ],
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions