Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

When using preserveModules = true, the rollup output can't be consumed with sideEffects: false in package.json #417

Open
@07akioni

Description

@07akioni

Version

5.0.0

Reproduction link

https://repl.it/join/czprwdpz-07akioni

Steps to reproduce

run main.sh

What is expected?

The app output should contains render function

What is actually happening?

Only the options is preserved


preserveModules = true is important for library development. However every single vue file is split into 3 files in that mode.

.vue =>
vue-template
vue-options (default export)
set-render-on-options
import default from 'xxx.vue'
// is converted to
import default from 'xxx-vue-options'
import 'set-render-on-options' // which has side effects

// I think the behavior is wired and may have some unexpected effects when tree-shaking

When I use the built library (if it is set to sideEffects: false)

import { Button } from 'my-library'

// use Button

Only the options of the Button will be bundled.

Is there any possibility to create only one file for a .vue sfc in preserveModules = true mode? That will not create unexpected side effects.


For example

export { default as Button } from './button/index'
export { default as Text } from './text/index'
export { default as Space } from './switch/index'

Is build as

export { default as Text } from './text/Text.vue_vue&type=script&lang.js';
import './text/Text.vue.js';
export { default as Button } from './button/Button.vue_vue&type=script&lang.js';
import './button/Button.vue.js';
export { default as Space } from './switch/Switch.vue_vue&type=script&lang.js';
import './switch/Switch.vue.js';

Which is not friendly for tree-shaking. For a component library, the codebase may be huge. If you don't set sideEffects: false, you will find it very hard to find out which part breaks tree-shaking. However if you set sideEffects: false, every xxx.vue.js will be pruned since it is not directly imported and viewed as tree-shakable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions