const webpack = require('webpack'); const path = require('path'); const CopyWebpackPlugin = require('copy-webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const isProduction = process.env.NODE_ENV === 'production'; const cMapsDir = path.join(path.dirname(require.resolve('pdfjs-dist/package.json')), 'cmaps'); const standardFontsDir = path.join( path.dirname(require.resolve('pdfjs-dist/package.json')), 'standard_fonts', ); module.exports = { mode: isProduction ? 'production' : 'development', bail: isProduction, context: path.join(__dirname), entry: { src: './index.jsx', }, output: { path: path.resolve(__dirname, 'dist'), }, resolve: { extensions: ['.js', '.jsx'], }, module: { rules: [ { test: /\.jsx?$/, use: ['babel-loader'], }, { test: /\.less$/, use: ['style-loader', 'css-loader', 'less-loader'], }, { test: /\.css$/, use: ['style-loader', 'css-loader'], }, ], }, plugins: [ new webpack.DefinePlugin({ 'process.env': { NODE_ENV: JSON.stringify(process.env.NODE_ENV), }, }), new HtmlWebpackPlugin({ template: 'index.html', }), new CopyWebpackPlugin({ patterns: [ { from: './sample.pdf' }, { from: cMapsDir, to: 'cmaps/' }, { from: standardFontsDir, to: 'standard_fonts/' }, ], }), ], devServer: { compress: true, historyApiFallback: true, // respond to 404s with index.html host: 'localhost', hot: true, // enable HMR on the server port: 3000, }, };