vuejs / vue-component-compiler

Compile a single file Vue component into a CommonJS module.
MIT License
342 stars 52 forks source link

Assemble in line function #33

Closed eddyerburgh closed 6 years ago

eddyerburgh commented 6 years ago

At the moment, assemble requires an import/require string for the script.

Not all compilers require this feature, and it makes the process more complicated. For example, vueify and vue-jest can work with the script being inlined.

I propose we add an assembleInline function that returns an es6/cjs module that doesn't include import/require statements.

assembleInline would need to be passed the transformed code, and source maps.

znck commented 6 years ago

I felt same when I was looking at parcel code.

znck commented 6 years ago

Contents of <script> tag would be an ES or CJs module. The default export from <script> is required in normalizeComponent.

Approach 1: Search and replace export default with var __script__ =. Approach 2: Parse to AST and convert default export to __script__ variable.

@eddyerburgh What do you think, which way to proceed? Any other suggestions?

znck commented 6 years ago

@eddyerburgh for inline assemble, can import statements for other javascript dependencies be added?

eddyerburgh commented 6 years ago

I think they shouldn't be