sheetjs/demos/requirejs
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
browser.html demo refresh [ci skip] 2017-09-24 19:40:09 -04:00
build.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
optimizer.html demo refresh [ci skip] 2017-09-24 19:40:09 -04:00
README.md demo refresh [ci skip] 2017-09-24 19:40:09 -04:00
xlsx-shim.js demo refresh [ci skip] 2017-09-24 19:40:09 -04:00

RequireJS

The minified dist files trip up the RequireJS mechanism. To bypass, the scripts automatically expose an XLSX variable that can be used if the require callback argument is _XLSX rather than XLSX. This trick is employed in the included xlsx-shim.js script:

/* xlsx-shim.js */
define(['xlsx'], function (_XLSX) {
	return XLSX;
});

The require config should set xlsx path to the appropriate dist file:

	paths: {
		xlsx: "xlsx.full.min"
	},

Once that is set, app code can freely require "xlsx-shim":

require(["xlsx-shim"], function(XLSX) {
	/* use XLSX here */
});

Deployments

browser.html demonstrates a dynamic deployment, using the in-browser config:

<script src="require.js"></script>
<script>
require.config({
	baseUrl: ".",
	name: "app",
	paths: {
		xlsx: "xlsx.full.min"
	}
});
</script>
<script src="app.js"></script>

optimizer.html demonstrates an optimized deployment using build.js config:

/* build config */
({
	baseUrl: ".",
	name: "app",
	paths: {
		xlsx: "xlsx.full.min"
	},
	out: "app-built.js"
})

The optimizer is invoked with:

node r.js -o build.js paths.requireLib=./require include=requireLib

That step creates a file app-built.js that can be included in a page:

<!-- final bundle includes require.js, xlsx-shim, library and app code -->
<script src="app-built.js"></script>

Analytics