Skip to content

Commit

Permalink
wasm: Fix production API path. (#788)
Browse files Browse the repository at this point in the history
Webpack is putting this in the static dir.
  • Loading branch information
betterengineering committed May 23, 2023
1 parent 71a6f77 commit c3e7744
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 23 deletions.
21 changes: 0 additions & 21 deletions webpack.common.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
const webpack = require('webpack');

let plugins = [];

if (process.env.PIXLET_BACKEND === "wasm") {
plugins.push(
new webpack.DefinePlugin({
'PIXLET_WASM': JSON.stringify(true),
'PIXLET_API_BASE': JSON.stringify('pixlet'),
})
);
} else {
plugins.push(
new webpack.DefinePlugin({
'PIXLET_WASM': JSON.stringify(false),
'PIXLET_API_BASE': JSON.stringify(''),
})
);
}

module.exports = {
plugins,
resolve: {
extensions: ['*', '.js', '.jsx'],
},
Expand Down
21 changes: 20 additions & 1 deletion webpack.dev.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const { merge } = require('webpack-merge');
const common = require('./webpack.common.js');
const webpack = require('webpack');

const HtmlWebPackPlugin = require("html-webpack-plugin");

const htmlPlugin = new HtmlWebPackPlugin({
Expand All @@ -8,6 +10,23 @@ const htmlPlugin = new HtmlWebPackPlugin({
favicon: 'src/favicon.png'
});

let plugins = [htmlPlugin];
if (process.env.PIXLET_BACKEND === "wasm") {
plugins.push(
new webpack.DefinePlugin({
'PIXLET_WASM': JSON.stringify(true),
'PIXLET_API_BASE': JSON.stringify('pixlet'),
})
);
} else {
plugins.push(
new webpack.DefinePlugin({
'PIXLET_WASM': JSON.stringify(false),
'PIXLET_API_BASE': JSON.stringify(''),
})
);
}

module.exports = merge(common, {
mode: 'development',
devtool: 'source-map',
Expand All @@ -22,5 +41,5 @@ module.exports = merge(common, {
},
],
},
plugins: [htmlPlugin]
plugins: plugins,
});
20 changes: 19 additions & 1 deletion webpack.prod.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { merge } = require('webpack-merge');
const common = require('./webpack.common.js');
const webpack = require('webpack');
const path = require('path');
const HtmlWebPackPlugin = require("html-webpack-plugin");

Expand All @@ -9,6 +10,23 @@ const htmlPlugin = new HtmlWebPackPlugin({
favicon: 'src/favicon.png'
});

let plugins = [htmlPlugin];
if (process.env.PIXLET_BACKEND === "wasm") {
plugins.push(
new webpack.DefinePlugin({
'PIXLET_WASM': JSON.stringify(true),
'PIXLET_API_BASE': JSON.stringify('static/pixlet'),
})
);
} else {
plugins.push(
new webpack.DefinePlugin({
'PIXLET_WASM': JSON.stringify(false),
'PIXLET_API_BASE': JSON.stringify(''),
})
);
}

module.exports = merge(common, {
mode: 'production',
devtool: 'source-map',
Expand All @@ -19,5 +37,5 @@ module.exports = merge(common, {
filename: '[name].[chunkhash].js',
clean: true,
},
plugins: [htmlPlugin]
plugins: plugins,
});

0 comments on commit c3e7744

Please sign in to comment.