This sample project demonstrates a variety of useful project configuration and setup techniques, including:
DllPlugin
and DllReferencePlugin
to pre-compile specific dependencies, allowing later application builds to be faster since those dependencies don't need to be parsed/node_modules/cesium/
instead of requiring a copy step during developmentmocha-loader
to run a live-watching test server, with results displayed in a browsermocha-webpack
to run a live-watching test process, with results displayed in a consoleNote that this codebase started as a prototype / research project, and any actual code in here is probably pretty ugly and not well documented. The intent is to demonstrate a mostly-working project configuration that implements some specific capabilities, and might serve as a useful example for others interested in the same approaches. You probably don't want to use this as the basis for an actual production application :)
Clone this repo, and run npm install
. All the dependencies should be installed directly from the /node_shrinkwrap/
folder, rather than having to go out to the NPM servers.
Then, execute npm run dll:build
to pre-compile the "vendor" and "cesiumDll" bundles, which need to be available during the development process.
Finally, run npm run dev
to start development.
These commands are NPM scripts defined in the "scripts" section of package.json
npm run dev
: starts the local app development-mode server, at http://localhost:3000
npm start
: same as npm run dev
npm run build
: does a production compile of the source, and writes it to /dist
npm run dll:build
: builds both the "vendor" and "cesiumDll" bundles
npm run dll:build:vendor
: builds the "vendor" bundle
npm run dll:build:cesium
: builds the "cesiumDll" bundle
npm run lint
: executes ESLint to flag code style problems
npm test
: does a compile of the test dependencies, writes to /disttest
, and executes the test suite
npm run test:build
: does the test compilation step
npm run test:run
: uses the Mocha test runner to execute an already-built test suite
npm run test:dev
: starts the local test-running development-mode server for mocha-loader
, at http://localhost:3001
npm run test:fast
: uses mocha-webpack
to compile and execute the test suite once
npm run test:watch
: starts mocha-webpack
to execute tests in live-watching mode in a console
The recent uproar over the unpublishing of "left-pad" and the subsequent breakage of thousands of NPM packages and build environments demonstrates the need to maintain a fixed list of all transitive dependencies. However, the common suggestion of checking in /node_modules/
is a bad idea. A typical /node_modules/
folder is easily 20K files and 150MB, and probably has platform-specific post-installation build artifacts (such as node-sass's native-code SASS compiler).
While researching this issue in 2015, I ran across a tool called https://github.com/JamieMason/shrinkpack , which seems to solve most of this issue. It simply refers to a npm-shrinkwrap.json file, and uses NPM's caching abilities to grab the tarballs for each exact dependency. It copies those to a /node_shrinkwrap/
folder, which can then be easily committed. That folder will probably be more like 500-750 files and 20MB - much more manageable. Re-running shrinkpack after a package update will just add or remove a few tarballs as needed, rather than having to re-commit hundreds or thousands of files under /node_modules/
. In addition, having the pre-install packages available means that the project can have npm install
run on multiple platforms, without worrying that a Linux build artifact got checked out on Windows. There's also no need for NPM to go out to a server during an install, as all dependencies are right here and pre-specified. That means a build environment doesn't have to have a network connection.
A typical Shrinkpack workflow for managing dependencies looks like this:
# one-time global install of shrinkpack
npm install -g shrinkpack
# install whatever packages you want to update
npm install some-package --save-dev
# once you are ready to persist the upgrade, then re-generate
# npm-shrinkwrap.json, including devDependencies
npm shrinkwrap --dev
# re-run shrinkpack to rewrite the shrinkwrap links to
# point to ./node_shrinkwrap/some-tarball.tgz
shrinkpack
# add new package files to version control
git add npm-shrinkwrap.json
git add node_shrinkwrap
git commit -m "Updated some-package"
/node_modules/
to the build output foldernpm run
scripts, and project metadata