Skip to content

Commit

Permalink
Merge pull request #9741 from timvandermeij/webpack
Browse files Browse the repository at this point in the history
Build improvements
  • Loading branch information
brendandahl authored Jun 4, 2018
2 parents 5053d02 + a71886f commit 3c51f2f
Show file tree
Hide file tree
Showing 8 changed files with 13,734 additions and 35 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ Makefile
node_modules/
examples/node/svgdump/
examples/node/pdf2png/*.png
package-lock.json
14 changes: 7 additions & 7 deletions examples/webpack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ Example to demonstrate PDF.js library usage with Webpack.

## Getting started

Build project and install the example dependencies:
Install the example dependencies and build the project:

$ gulp dist-install
$ cd examples/webpack
$ npm install
$ ./node_modules/webpack/bin/webpack.js

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
You can observe the build results by running `gulp server` and navigating to
http://localhost:8888/examples/webpack/index.html.

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.
Refer to the `main.js` and `webpack.config.js` files for the source code.
Note that PDF.js packaging requires packaging of the main application and
the worker code, and the `workerSrc` path shall be set to the latter file.
3 changes: 2 additions & 1 deletion examples/webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"build": "webpack"
},
"devDependencies": {
"webpack": "~1.12.9",
"webpack": "^4.10.2",
"webpack-cli": "^2.1.4",
"pdfjs-dist": "../../node_modules/pdfjs-dist"
}
}
11 changes: 2 additions & 9 deletions examples/webpack/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,10 @@ module.exports = {
'main': './main.js',
'pdf.worker': 'pdfjs-dist/build/pdf.worker.entry'
},
mode: 'none',
output: {
path: path.join(__dirname, '../../build/webpack'),
publicPath: '../../build/webpack/',
filename: '[name].bundle.js'
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
compressor: {
screw_ie8: true,
warnings: false
}
})
]
}
};
2 changes: 1 addition & 1 deletion external/webpack/pdfjsdev-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = function (source) {
this.cacheable();

var filePath = this.resourcePath;
var context = this.options.context;
var context = this.rootContext;
var sourcePath = path.relative(context, filePath).split(path.sep).join('/');

var ctx = Object.create(this.query);
Expand Down
13 changes: 10 additions & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,15 @@ function createWebpackConfig(defines, output) {
var skipBabel = bundleDefines.SKIP_BABEL ||
process.env['SKIP_BABEL'] === 'true';

// Required to expose e.g., the `window` object.
output.globalObject = 'this';

return {
mode: 'none',
output: output,
performance: {
hints: false, // Disable messages about larger file sizes.
},
plugins: [
new webpack2.BannerPlugin({ banner: licenseHeaderLibre, raw: true, }),
],
Expand All @@ -160,7 +167,7 @@ function createWebpackConfig(defines, output) {
},
devtool: enableSourceMaps ? 'source-map' : undefined,
module: {
loaders: [
rules: [
{
loader: 'babel-loader',
// babel is too slow
Expand Down Expand Up @@ -1166,10 +1173,10 @@ gulp.task('dist-pre', ['generic', 'components', 'lib', 'minified'], function() {
license: DIST_LICENSE,
dependencies: {
'node-ensure': '^0.0.0', // shim for node for require.ensure
'worker-loader': '^1.1.1', // used in external/dist/webpack.json
'worker-loader': '^2.0.0', // used in external/dist/webpack.json
},
peerDependencies: {
'webpack': '^2.0.0 || ^3.0.0', // peerDependency of 'worker-loader'
'webpack': '^3.0.0 || ^4.0.0-alpha.0 || ^4.0.0', // from 'worker-loader'
},
browser: {
'fs': false,
Expand Down
Loading

0 comments on commit 3c51f2f

Please sign in to comment.