Rollup не создает исходную карту машинописного текста - PullRequest
1 голос
/ 02 августа 2020

Я использую свертку с svelte + typescript + s css. Моя проблема в том, что я не могу создавать исходные карты.

Ниже приведен мой файл конфигурации накопительного пакета:

import svelte from 'rollup-plugin-svelte'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import livereload from 'rollup-plugin-livereload'
import { terser } from 'rollup-plugin-terser'
import typescript from '@rollup/plugin-typescript'
import alias from '@rollup/plugin-alias'

const production = !process.env.ROLLUP_WATCH
const path = require('path').resolve(__dirname, 'src')
const svelteOptions = require('./svelte.config')

function serve() {
    let server

    function toExit() {
        if (server) server.kill(0)
    }

    return {
        writeBundle() {
            if (server) return
            server = require('child_process').spawn(
                'yarn',
                ['run', 'start', '--', '--dev'],
                {
                    stdio: ['ignore', 'inherit', 'inherit'],
                    shell: true,
                }
            )

            process.on('SIGTERM', toExit)
            process.on('exit', toExit)
        },
    }
}

export default {
    input: 'src/main.ts',
    output: {
        sourcemap: true,
        format: 'iife',
        name: 'app',
        file: 'public/build/bundle.js',
    },
    plugins: [
        alias({
            entries: [
                { find: '@app', replacement: `${path}` },
                { find: '@components', replacement: `${path}/components` },
                { find: '@includes', replacement: `${path}/includes` },
                { find: '@styles', replacement: `${path}/styles` },
                { find: '@pages', replacement: `${path}/pages` },
            ],
        }),
        svelte(svelteOptions),

        // If you have external dependencies installed from
        // npm, you'll most likely need these plugins. In
        // some cases you'll need additional configuration -
        // consult the documentation for details:
        // https://github.com/rollup/plugins/tree/master/packages/commonjs
        resolve({
            browser: true,
            dedupe: ['svelte'],
        }),
        commonjs(),
        typescript({ sourceMap: !production }),

        // In dev mode, call `npm run start` once
        // the bundle has been generated
        !production && serve(),

        // Watch the `public` directory and refresh the
        // browser on changes when not in production
        !production && livereload('public'),

        // If we're building for production (npm run build
        // instead of npm run dev), minify
        production && terser(),
    ],
    watch: {
        clearScreen: false,
    },
}

Я не уверен, что именно я делаю неправильно. Вот ссылка на код, который я использую. Мы будем благодарны за любую помощь!

Ответы [ 2 ]

3 голосов
/ 03 августа 2020

Как также упоминалось другими, похоже, что комбинация TypeScript и Rollup приводит к проблеме. Отключение исходной карты в TypeScript решает только проблему сопоставления Svelte с TypeScript. Однако вы получаете только карту источников, показывающую исходный код в скомпилированном JavaScript, а не в исходном TypeScript. Я наконец нашел решение, которое сработало для меня: просто добавьте Option inlineSources: true к параметрам TypeScript:

typescript({ sourceMap: !production, inlineSources: !production }),

Это позволяет обойти проблему, просто не создавая дубликат SourceMap, а скопировав исходный код из TypeScript в SourceMap.

2 голосов
/ 03 августа 2020

Это то, что сработало для меня: вам нужно установить sourceMap: false в typescript параметрах подключаемого модуля свертки.

export default {
  input: 'src/main.ts',
  output: {
    sourcemap: true,
    format: 'iife',
    ...
  },
  plugins: [
    ...
    svelte(...),
    typescript({ sourceMap: false }),
    ...
  ]
}

Оказывается, коллапсер свертки исходной карты конфликтует с генератором исходной карты подключаемого модуля машинописного текста. Вот почему он работает в сборках prod, но не в сборках dev (потому что изначально это sourceMap: !production). Просто позвольте свертке делать тяжелую работу.

...