egoist / bili

Bili makes it easier to bundle JavaScript libraries.
https://bili.egoist.sh
MIT License
1.04k stars 61 forks source link

Plugin order causes issues #177

Closed zcuric closed 6 months ago

zcuric commented 5 years ago

Hi, when trying to fix the build for vue-plyr (https://github.com/redxtech/vue-plyr/issues/60) by updating to bili@4 (see here: https://github.com/zcuric/vue-plyr/pull/1) I encountered an issue when using specific babel config with vue files (I was trying to solve this actually: https://github.com/rollup/rollup-plugin-babel/issues/260).

Error I got was this:

error Failed to bundle src/index.js in cjs format

Stack Trace:
SyntaxError: /Users/zdravko/Code/vue-plyr/src/VuePlyr.vue: Unexpected token (1:0)

> 1 | <template>
    | ^
  2 |   <div>
  3 |     <slot/>
  4 |   </div>
    at Parser.raise (/Users/zdravko/Code/vue-plyr/node_modules/@babel/parser/lib/index.js:3831:17)
    at Parser.unexpected (/Users/zdravko/Code/vue-plyr/node_modules/@babel/parser/lib/index.js:5143:16)
    at Parser.parseExprAtom (/Users/zdravko/Code/vue-plyr/node_modules/@babel/parser/lib/index.js:6283:20)
    at Parser.parseExprSubscripts (/Users/zdravko/Code/vue-plyr/node_modules/@babel/parser/lib/index.js:5862:23)
    at Parser.parseMaybeUnary (/Users/zdravko/Code/vue-plyr/node_modules/@babel/parser/lib/index.js:5842:21)
    at Parser.parseExprOps (/Users/zdravko/Code/vue-plyr/node_modules/@babel/parser/lib/index.js:5729:23)
    at Parser.parseMaybeConditional (/Users/zdravko/Code/vue-plyr/node_modules/@babel/parser/lib/index.js:5702:23)
    at Parser.parseMaybeAssign (/Users/zdravko/Code/vue-plyr/node_modules/@babel/parser/lib/index.js:5647:21)
    at Parser.parseExpression (/Users/zdravko/Code/vue-plyr/node_modules/@babel/parser/lib/index.js:5595:23)
    at Parser.parseStatementContent (/Users/zdravko/Code/vue-plyr/node_modules/@babel/parser/lib/index.js:7378:23)
    at Parser.parseStatement (/Users/zdravko/Code/vue-plyr/node_modules/@babel/parser/lib/index.js:7243:17)
    at Parser.parseBlockOrModuleBlockBody (/Users/zdravko/Code/vue-plyr/node_modules/@babel/parser/lib/index.js:7810:25)
    at Parser.parseBlockBody (/Users/zdravko/Code/vue-plyr/node_modules/@babel/parser/lib/index.js:7797:10)
    at Parser.parseTopLevel (/Users/zdravko/Code/vue-plyr/node_modules/@babel/parser/lib/index.js:7181:10)
    at Parser.parse (/Users/zdravko/Code/vue-plyr/node_modules/@babel/parser/lib/index.js:8660:17)
    at parse (/Users/zdravko/Code/vue-plyr/node_modules/@babel/parser/lib/index.js:10660:38)

After debugging, we concluded that was probably because of order of plugins, which we test by moving https://github.com/egoist/bili/blob/28b1a197eb41dac2582814253f6b2b9226310d21/src/index.ts#L290-L301

to here: https://github.com/egoist/bili/blob/28b1a197eb41dac2582814253f6b2b9226310d21/src/index.ts#L216

In bili@3 this wasn't an issue, probably because of the way the plugins were defined, array was used in that config.

So, there should be a way to define the plugin priority or order of execution to fix these kind of errors.

cc @vladimyr

egoist commented 5 years ago

It should be fixed in 4.5.2

zcuric commented 5 years ago

It should be fixed in 4.5.2

Thank you! 👏

hosein2398 commented 5 years ago

So isn't this done?! Why not to close?

javier-garcia-meteologica commented 3 years ago

I encountered problems using @rollup/plugin-eslint.

// bili.config.ts
import { Config } from 'bili';

const config: Config = {
  input: 'src/index.ts',
  output: {
    format: ['cjs', 'esm']
  },
  plugins: {
    '@rollup/plugin-eslint': {
      throwOnError: true
    }
  }
};

export default config;

The problem is that bili puts this plugin in last place, so it's linting transformed code and not the original one.

   1:51  error    'rollupPluginBabelHelpers.js' imported multiple times