FountainJS / generator-fountain-webapp

Yeoman 'fountain' generator to start a webapp
http://fountainjs.io
MIT License
967 stars 67 forks source link

Build Project as Module #178

Open IdanCo opened 7 years ago

IdanCo commented 7 years ago

I'm trying to build my fountain project into a module, to be consumed by other projects, using webpack (or maybe bower?).

webpack-dist is not the configuration i'm looking for: I've been playing it for some time but i couldn't seperate the vendor from the app.

Can anyone point me in the right direction?

IdanCo commented 7 years ago

I dug a little deeper and came across this seed project - webpack library starter;

This led me to create a new webpack config file which i've named webpack-library.conf, and adjusted it for my needs. the main part is the library property inside the output manifest -

  output: {
    path: path.join(process.cwd(), conf.paths.libraryDist),
    filename: 'my-library.js',
    library: 'MyLibrary',
    libraryTarget: 'umd',
    umdNamedDefine: true
  },

This facilitates the bundling of a single importable module (library). notice also the externals property which is important to avoid wrapping the external modules as well. in my setup it looks like this -

  externals: {
    angular: 'angular',
  },

If anyone has recommendations or improvements i'll be happy to know, and if anyone needs the entire setup let me know and i'll be happy to share.