Webpack based boilerplate for producing libraries (Input: ES6, Output: universal library)
- Webpack 5 based.
- ES6 as a source.
- Exports in a umd format so your library works everywhere.
- Linting with ESLint.
ES6 source files
|
|
webpack
|
+--- babel, eslint
|
ready to use
library
in umd format
Have in mind that you have to build your library before publishing. The files under the lib
folder are the ones that should be distributed.
- Setting up the name of your library
- Open
webpack.config.js
file and change the value oflibraryName
variable. - Open
package.json
file and change the value ofmain
property so it matches the name of your library.
- Get Sstarted
Run the
init.sh
script.
./init.sh
yarn build
ornpm run build
- produces production version of your library under thelib
folder
- Clone mlibrary/search.
gh repo clone mlibrary/search
- Navigate to the repository and open the
package.json
file. Edit the dependency URL forprejudice
to point to your localprejudice
repository.Note: If you want to test a specific branch, add"prejudice": "file:../prejudice",
#
followed by the branch name to the end of the URL."prejudice": "git+https://github.com/mlibrary/prejudice.git#your-branch-here",
- Install
Note: If this is not a fresh clone, do a clean install.
npm install
rm -rf node_modules && package-lock.json && npm install
- Run locally
npm start
While Search is running locally, the site will automatically refresh whenever lib/prejudice.js
changes.
An example of using dependencies that shouldn’t be resolved by webpack, but should become dependencies of the resulting bundle
In the following example we are excluding React and Lodash:
{
devtool: 'source-map',
output: {
path: '...',
libraryTarget: 'umd',
library: '...'
},
entry: '...',
...
externals: {
react: 'react'
// Use more complicated mapping for lodash.
// We need to access it differently depending
// on the environment.
lodash: {
commonjs: 'lodash',
commonjs2: 'lodash',
amd: '_',
root: '_'
}
}
}