TrySound / rollup-plugin-terser

Rollup plugin to minify generated bundle
MIT License
611 stars 55 forks source link

Terser generates incorrect sourcemaps. #72

Open ivan-shaban opened 4 years ago

ivan-shaban commented 4 years ago

Hello, i've got simple config:

import pkg from "./package.json";
import typescript from "@wessberg/rollup-plugin-ts";
import { terser } from "rollup-plugin-terser";

const external = [
    ...Object.keys(pkg.dependencies || {}),
    ...Object.keys(pkg.devDependencies || {}),
];

export default {
    input: "src/index.ts",
    output: [{
        file: pkg.main,
        sourcemap: true,
        format: "cjs",
    }],
    external,
    plugins: [
        typescript({
            transpiler: "babel",
        }),
        terser(),
    ],
};

Which produces incorrect sourcemaps (everything points for first line of source code) when i use terser plugin, if i disable it, sourcemaps works correct. Do you have any ideas why that happens?

Package.json dependencies:

    "@babel/plugin-proposal-class-properties": "^7.8.3",
    "@babel/plugin-proposal-decorators": "7.8.3",
    "@babel/plugin-proposal-export-default-from": "7.8.3",
    "@babel/plugin-proposal-object-rest-spread": "7.9.0",
    "@babel/plugin-transform-async-to-generator": "^7.8.3",
    "@babel/plugin-transform-regenerator": "^7.8.7",
    "@babel/preset-env": "^7.8.4",
    "@babel/preset-typescript": "^7.8.3",
    "@wessberg/rollup-plugin-ts": "1.2.21",
    "jsdoc": "3.6.3",
    "npm-run-all": "^4.1.5",
    "rimraf": "^2.7.1",
    "rollup": "^2.0.3",
    "rollup-plugin-size-snapshot": "0.11.0",
    "rollup-plugin-terser": "^5.2.0",
    "rollup-plugin-visualizer": "4.0.1",
    "tslib": "^1.10.0",
    "typescript": "^3.7.5"

babel.config.js:

module.exports = {
    presets: [
        "@babel/preset-env",
        "@babel/preset-typescript"
    ],
    plugins: [
        "@babel/plugin-transform-async-to-generator",
        "@babel/plugin-transform-regenerator",
        ['@babel/plugin-proposal-decorators', { 'legacy': true }],
        ['@babel/plugin-proposal-class-properties', { 'loose': true }],
        ['@babel/plugin-proposal-export-default-from'],
        ['@babel/plugin-proposal-object-rest-spread', { 'loose': true, 'useBuiltIns': true }],
    ],
};
TrySound commented 4 years ago

Does it work without ts plugin?

ivan-shaban commented 4 years ago

No, it doesn't, i've tried without ts and got the same result(

TrySound commented 4 years ago

Could you please provide a repro? https://repl.it/@rollup/rollup-plugin-repro