Removing "entry-loader" dependency from webpack.
This commit is contained in:
parent
127e6d7343
commit
ae415f9e80
12 changed files with 45 additions and 17 deletions
|
@ -16,10 +16,11 @@ http://localhost:8888/examples/browserify/index.html
|
|||
|
||||
See main.js, worker.js and gulpfile.js files. Please notice that PDF.js
|
||||
packaging requires packaging of the main application and PDF.js worker code,
|
||||
and the `workerSrc` path shall be set to the latter file.
|
||||
and the `workerSrc` path shall be set to the latter file. The pdf.worker.js file
|
||||
shall be excluded from the main bundle.
|
||||
|
||||
Alternatives to the gulp commands (without compression) are:
|
||||
|
||||
$ mkdir -p ../../build/browserify
|
||||
$ node_modules/.bin/browserify main.js -o ../../build/browserify/bundle.js
|
||||
$ node_modules/.bin/browserify main.js -u ./node_modules/pdfjs-dist/build/pdf.worker.js -o ../../build/browserify/main.bundle.js
|
||||
$ node_modules/.bin/browserify worker.js -o ../../build/browserify/pdf.worker.bundle.js
|
||||
|
|
|
@ -10,15 +10,18 @@ var TMP_FILE_PREFIX = '../../build/browserify_';
|
|||
|
||||
gulp.task('build-bundle', function() {
|
||||
return browserify('main.js', {output: TMP_FILE_PREFIX + 'main.tmp'})
|
||||
.ignore(require.resolve('pdfjs-dist/build/pdf.worker')) // Reducing size
|
||||
.bundle()
|
||||
.pipe(source(TMP_FILE_PREFIX + 'main.tmp'))
|
||||
.pipe(streamify(uglify()))
|
||||
.pipe(rename('bundle.js'))
|
||||
.pipe(rename('main.bundle.js'))
|
||||
.pipe(gulp.dest(OUTPUT_PATH));
|
||||
});
|
||||
|
||||
gulp.task('build-worker', function() {
|
||||
return browserify('worker.js', {output: TMP_FILE_PREFIX + 'worker.tmp'})
|
||||
// We can create our own viewer (see worker.js) or use already defined one.
|
||||
var workerSrc = require.resolve('pdfjs-dist/build/pdf.worker.entry');
|
||||
return browserify(workerSrc, {output: TMP_FILE_PREFIX + 'worker.tmp'})
|
||||
.bundle()
|
||||
.pipe(source(TMP_FILE_PREFIX + 'worker.tmp'))
|
||||
.pipe(streamify(uglify({compress:{
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>browserify example</title>
|
||||
<script src="../../build/browserify/bundle.js"></script>
|
||||
<script src="../../build/browserify/main.bundle.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="theCanvas"></canvas>
|
||||
|
|
|
@ -7,7 +7,7 @@ require('pdfjs-dist');
|
|||
|
||||
var pdfPath = '../helloworld/helloworld.pdf';
|
||||
|
||||
// Setting worker path to worker bundle
|
||||
// Setting worker path to worker bundle.
|
||||
PDFJS.workerSrc = '../../build/browserify/pdf.worker.bundle.js';
|
||||
|
||||
// It is also possible to disable workers via `PDFJS.disableWorker = true`,
|
||||
|
|
|
@ -14,5 +14,6 @@ To build Webpack bundles, run `node_modules/.bin/webpack`. If you are running
|
|||
a web server, you can observe the build results at
|
||||
http://localhost:8888/examples/webpack/index.html
|
||||
|
||||
See main.js and webpack.config.js files. Please notice that PDF.js packaging
|
||||
requires the `entry` loader.
|
||||
See main.js and webpack.config.js files. Please notice that PDF.js
|
||||
packaging requires packaging of the main application and PDF.js worker code,
|
||||
and the `workerSrc` path shall be set to the latter file.
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>webpack example</title>
|
||||
<script src="../../build/webpack/bundle.js"></script>
|
||||
<script src="../../build/webpack/main.bundle.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="theCanvas"></canvas>
|
||||
|
|
|
@ -7,6 +7,9 @@ var pdfjsLib = require('pdfjs-dist');
|
|||
|
||||
var pdfPath = '../helloworld/helloworld.pdf';
|
||||
|
||||
// Setting worker path to worker bundle.
|
||||
pdfjsLib.PDFJS.workerSrc = '../../build/webpack/pdf.worker.bundle.js';
|
||||
|
||||
// It is also possible to disable workers via `PDFJS.disableWorker = true`,
|
||||
// however that might degrade the UI performance in web browsers.
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
"version": "0.1.0",
|
||||
"devDependencies": {
|
||||
"webpack": "~1.12.9",
|
||||
"entry-loader": "~0.1.0",
|
||||
"pdfjs-dist": "../../build/dist"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,11 +3,14 @@ var path = require('path');
|
|||
|
||||
module.exports = {
|
||||
context: __dirname,
|
||||
entry: './main.js',
|
||||
entry: {
|
||||
'main': './main.js',
|
||||
'pdf.worker': 'pdfjs-dist/build/pdf.worker.entry'
|
||||
},
|
||||
output: {
|
||||
path: path.join(__dirname, '../../build/webpack'),
|
||||
publicPath: '../../build/webpack/',
|
||||
filename: 'bundle.js'
|
||||
filename: '[name].bundle.js'
|
||||
},
|
||||
plugins: [
|
||||
new webpack.optimize.UglifyJsPlugin({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue