From 78da9fd1441cbba4cfcaf241448a84ad24436793 Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Wed, 31 Jul 2019 14:32:26 +0100 Subject: [PATCH] Fix build on Windows (#666) * Use `require` for reading JSON JSON is natively supported by Node.js, so no point in using a custom helper here. * Fix build on Windows Fixes #465. --- webpack.config.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index fe52f705..c6c16b3f 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,4 +1,3 @@ -const fs = require('fs'); const path = require('path'); const webpack = require('webpack'); const CleanPlugin = require('clean-webpack-plugin'); @@ -17,11 +16,7 @@ const CrittersPlugin = require('critters-webpack-plugin'); const AssetTemplatePlugin = require('./config/asset-template-plugin'); const addCssTypes = require('./config/add-css-types'); -function readJson (filename) { - return JSON.parse(fs.readFileSync(filename)); -} - -const VERSION = readJson('./package.json').version; +const VERSION = require('./package.json').version; module.exports = async function (_, env) { const isProd = env.mode === 'production'; @@ -147,11 +142,13 @@ module.exports = async function (_, env) { }, { // All the codec files define a global with the same name as their file name. `exports-loader` attaches those to `module.exports`. - test: /\/codecs\/.*\.js$/, + test: /\.js$/, + include: path.join(__dirname, 'src/codecs'), loader: 'exports-loader' }, { - test: /\/codecs\/.*\.wasm$/, + // For some reason using `include` here breaks the build. + test: /[/\\]codecs[/\\].*\.wasm$/, // This is needed to make webpack NOT process wasm files. // See https://github.com/webpack/webpack/issues/6725 type: 'javascript/auto', @@ -172,7 +169,7 @@ module.exports = async function (_, env) { plugins: [ new webpack.IgnorePlugin( /(fs|crypto|path)/, - new RegExp(`${path.sep}codecs${path.sep}`) + /[/\\]codecs[/\\]/ ), // Pretty progressbar showing build progress: @@ -239,7 +236,7 @@ module.exports = async function (_, env) { removeRedundantAttributes: true, removeComments: true }, - manifest: readJson('./src/manifest.json'), + manifest: require('./src/manifest.json'), inject: 'body', compile: true }),