sheetjs_sheetjs/demos/webpack
SheetJS 7149728c7c version bump 0.12.4: zip cleanup
- PK magic number bound (fixes #1013 h/t @wlpeter)
- removed JSZip conflict (fixes #1017 h/t @seanmars)
- updated CFB to 1.0.5
- demo HTML conversion `string`
2018-03-05 19:34:04 -05:00
..
.gitignore demo refresh [ci skip] 2017-09-24 19:40:09 -04:00
app.js version bump 0.12.4: zip cleanup 2018-03-05 19:34:04 -05:00
appworker.js demo refresh [ci skip] 2017-09-24 19:40:09 -04:00
core.html version bump 0.11.3: "array" type 2017-08-19 19:06:34 -04:00
core.js Math.LOG2E precision issue + new demos [ci skip] 2017-09-05 01:34:30 -04:00
coreworker.js demo refresh [ci skip] 2017-09-24 19:40:09 -04:00
full.html version bump 0.11.3: "array" type 2017-08-19 19:06:34 -04:00
full.js Math.LOG2E precision issue + new demos [ci skip] 2017-09-05 01:34:30 -04:00
fullworker.js demo refresh [ci skip] 2017-09-24 19:40:09 -04:00
main.html demo refresh [ci skip] 2017-09-24 19:40:09 -04:00
main.js Math.LOG2E precision issue + new demos [ci skip] 2017-09-05 01:34:30 -04:00
mainworker.js demo refresh [ci skip] 2017-09-24 19:40:09 -04:00
Makefile demo refresh [ci skip] 2017-09-24 19:40:09 -04:00
README.md version bump 0.11.18: infrastructure 2018-01-23 04:07:55 -05:00
webpack.app.js version bump 0.11.18: infrastructure 2018-01-23 04:07:55 -05:00
webpack.config.js version bump 0.11.18: infrastructure 2018-01-23 04:07:55 -05:00
xlsx.core.min.js version bump 0.11.1: dist cleanup 2017-08-05 02:32:57 -04:00
xlsx.full.min.js version bump 0.11.1: dist cleanup 2017-08-05 02:32:57 -04:00

Webpack

This library is built with some dynamic logic to determine if it is invoked in a script tag or in nodejs. Webpack does not understand those feature tests, so by default it will do some strange things.

Basic Usage

webpack.app.js demonstrates bundling an entire app script in a bundle. For basic projects requiring the module from the npm package, it is sufficient to suppress the node shims:

/* webpack config for app.out.js */
{
	/* entry point app.js */
	entry: './app.js',

	/* write to app.out.js */
	output: { path:__dirname, filename: './app.out.js' },

	/* suppress node shims */
	node: {
		process: false,
		Buffer: false
	}
}

Suppressing the Node shims

The library properly guards against accidental leakage of node features in the browser but webpack disregards those. The config should explicitly suppress:

	node: {
		process: false,
		Buffer: false
	}

Omitting optional dependencies

The codepage is needed in certain special cases, including files generated by non-US-English versions of Excel, but may not be needed. To reduce build size, the module can be omitted by aliasing the dependency:

	resolve: {
		alias: { "./dist/cpexcel.js": "" }
	},

Alternatively, bundling the xlsx.core.min.js script always omits dependencies.

Bower and minified versions

Webpack may show a message like "This seems to be a pre-built javascript file" when processing minified files (like the default Bower script). The message is harmless. To suppress the message, set module.noParse in the webpack config:

	module: {
		noParse: [
			/xlsx.core.min.js/,
			/xlsx.full.min.js/
		]
	}

Other Demos

This demo also attempts to demonstrate bundling of the library as well as the core and full distribution versions. app.js is the common app code (it will not be bundled). The individual bundles merely wrap and reflect XLSX. The app code uses the bundles with script tag inclusion in the main HTML files. The worker scripts use the bundles with importScripts references.

required script HTML page entry worker script
main xlsx lib main.html main.js mainworker.js
xlsx.core.min core.html core.js coreworker.js
xlsx.full.min full.html full.js fullworker.js

The entry points in the demo merely require and re-export the library:

/* main.js */
var XLSX = require('../../');
console.log("it works!");
module.exports = XLSX;

The main advantage of reflecting the library is deduplication: the library code is only downloaded once. The basic example builds a separate worker script and eventually ships the library twice.

Reflecting the XLSX variable

This library will not assign to module.exports if it is run in the browser. To convince webpack, the demo webpack config sets output:

	output: {
		libraryTarget: 'var',
		library: 'XLSX'
	}

Analytics