最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

node.js - Compile javascript with dependencies using Babel - Stack Overflow

programmeradmin1浏览0评论

How do I pile ES6 JS code with all required dependencies using babel-cli module? For example.

I have the next project structure:

/lib
 /packageA
   /node_modules
   - package.json
   - index.js
 /packageB
   /node_modules
   - package.json
   - index.js
/app
- index.js
- package.json

I import packages packageA and packageB in /app/index.js, all the ponents are written using ES6 syntax, except from the packages installed with npm in node_modules.

I would like to pile /app/index.js with all the dependencies, but cannot figure out a simple way without to explicitly provide paths of packageA and packageB.

I have found this module , but is there other tools / approaches / native babel soultions?

How do I pile ES6 JS code with all required dependencies using babel-cli module? For example.

I have the next project structure:

/lib
 /packageA
   /node_modules
   - package.json
   - index.js
 /packageB
   /node_modules
   - package.json
   - index.js
/app
- index.js
- package.json

I import packages packageA and packageB in /app/index.js, all the ponents are written using ES6 syntax, except from the packages installed with npm in node_modules.

I would like to pile /app/index.js with all the dependencies, but cannot figure out a simple way without to explicitly provide paths of packageA and packageB.

I have found this module https://github./mairatma/babel-deps, but is there other tools / approaches / native babel soultions?

Share Improve this question asked Feb 15, 2016 at 11:30 agoldisagoldis 1,05716 silver badges29 bronze badges 4
  • Are you trying to add all files into one, or just pile it with babel to see if your project piles? – bolav Commented Feb 15, 2016 at 12:14
  • doesn't really matter, i want to get a piled js code – agoldis Commented Feb 15, 2016 at 12:15
  • what was the solution? – Nth.gol Commented Feb 10, 2019 at 22:14
  • @Nth.gol don't quite remember, but now I'd say it's not babel's responsibility to bundle the code, so some sort of bundler should be used instead (e.g. webpack or rollup) – agoldis Commented Feb 12, 2019 at 0:13
Add a ment  | 

1 Answer 1

Reset to default 6

If you pile several files with babel it will concat the files. If what you want is to get a piled file in app/index.js that includes the dependencies I would remend using something like rollup.

If you decide to go with rollup, a rollup.config.js like this will do what I think you want:

import nodeResolve from 'rollup-plugin-node-resolve';
import babel from 'rollup-plugin-babel';
import monjs from 'rollup-plugin-monjs';

export default {
  entry: 'index.js',
  dest: 'app/app.js',
  plugins: [
    babel(),
    nodeResolve(), 
    monjs()]
};

And then just run rollup -c

发布评论

评论列表(0)

  1. 暂无评论