Transpile source to lib/ dir for npm publishing#11
Conversation
By pointing package.json's `main` property to the ES6 source code, external projects that use this module have to ensure they transpile the code before publishing it. It's better practice to pre-transpile everything to a lib/ dir and set it as `main` so that other projects can consume it hassle-free. https://stackoverflow.com/a/33976278
| 'BlackBerry 7', | ||
| 'BlackBerry 10' | ||
| ] | ||
| browsers: config.supportedBrowsers |
There was a problem hiding this comment.
I moved the browser list into the config file.
| new webpack.optimize.UglifyJsPlugin( { | ||
| compress: { warnings: true } | ||
| } ) | ||
| ] |
There was a problem hiding this comment.
I removed the minification step because IMHO it's premature optimization. This package isn't used on its own -- it's consumed by other projects -- so I think it's appropriate to leave minification to the consumer. Thoughts?
There was a problem hiding this comment.
One reason to keep it may be to keep the build process as close to other projects as possible, which will make it easier to update them all. Having recently updated webpack in CF, DM, and here it helps if the config looks and acts the same.
There was a problem hiding this comment.
Valid point. I think I'd prefer to remove it from most of our projects. It often makes development harder by obfuscating the transpiled code. For example, when I write JS for cfgov-refresh I find myself temporarily commenting out the uglify step to make debugging IE a lot easier. It seems like the sort of thing that should be in a deployment pipeline job or a separate gulp task or something.
There was a problem hiding this comment.
Ah yeah, we were having this discussion in CF a little while ago (b/c I crushed the unminified version 😛 ). The way I've been seeing to do this is set NODE_ENV and have a development and production setting https://stackoverflow.com/questions/25956937/how-to-build-minified-and-uncompressed-bundle-with-webpack
webpack has a flag for the environment too https://webpack.js.org/api/cli/#environment-options
In that setup each project has a set of environment settings and while some may omit one pathway, the pathways they share could be the same.
There was a problem hiding this comment.
I'm definitely on board with this. Do we have it saved somewhere so it doesn't get lost to the ether?
| compress: { warnings: true } | ||
| } ) | ||
| ] | ||
| filename: 'index.js' |
There was a problem hiding this comment.
Renamed the transpiled file from main to index to match the src file.
85bca50 to
d4fca86
Compare
By pointing package.json's
mainproperty to the ES6 source code,external projects that use this module have to ensure they transpile
the code before publishing it. It's better practice to pre-transpile
everything to a lib/ dir and set it as
mainso that other projectscan consume it hassle-free.
https://stackoverflow.com/a/33976278