Code Monkey home page Code Monkey logo

Comments (4)

dmvaldman avatar dmvaldman commented on May 18, 2024

Yeah, the current /dist folder only has the bundled files as you mention, and there is no CommonJS format for each individual source file. This is an artifact of how I currently develop the library, which is just to use the AMD files in the /samsara directory. When we move to an es6 format this will no longer be the case, and you'll be able to import individual files and do tree shaking.

from samsara.

trusktr avatar trusktr commented on May 18, 2024

@dmvaldman The only thing you have to do to support this is to simply publish the the /samsara folder to NPM too.

Any modern bundler like Webpack, JSPM, Browserify, understands AMD format.


@chickendinosaur, after @dmvaldman makes that small change, you can just import the specific files that you want after making an alias to the /samsara folder.

In Webpack, the resolve.alias property can be used to define an alias like samsara: samsara/samsara' (which means "let anything imported from samsara/ actually beimported from samsara/samsara") then things can be imported like

import RenderNode from 'samsara/core/nodes/RenderTreeNode'

Without the alias it would still work, but the import would need to be

import RenderNode from 'samsara/samsara/core/nodes/RenderTreeNode'

Some libs put stuff in src, so the alias in that case would be some-lib: some-lib/src' in order to avoid having to put src/ in every import path.

from samsara.

trusktr avatar trusktr commented on May 18, 2024

@dmvaldman @chickendinosaur Oops, I was looking at https://www.npmjs.com/package/samsara, not https://www.npmjs.com/package/samsarajs.

samsarajs on NPM already includes the /samsara folder, so you're good to go!

@chickendinosaur You can import any file just as they are, right now, in Webpack. They don't need to be in ES6 format.

In AMD format there may not be tree shaking by Webpack, though it is not strictly impossible because there's nothing inherent about AMD that prevents a bundler from statically analyzing functions to see which are used or not, but, at least you can import stuff.

from samsara.

trusktr avatar trusktr commented on May 18, 2024

@dmvaldman You can possibly close this one, since the files are importable already with standard bundlers, and prefer #18 in case you want to migrate to that format in the future. (Safari tech preview already has ES6 module loader, so it can load ES6 modules at runtime without any build tools!)

from samsara.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.