bitque/jirs-client/webpack.config.js

76 lines
2.3 KiB
JavaScript
Raw Normal View History

2020-03-29 19:56:55 +02:00
const path = require("path");
const WasmPackPlugin = require("@wasm-tool/wasm-pack-plugin");
const HtmlWebpackPlugin = require('html-webpack-plugin');
2020-03-30 14:26:25 +02:00
const dotenv = require('dotenv');
const webpack = require('webpack');
2020-04-23 21:29:50 +02:00
const { execSync, exec } = require('child_process');
2020-03-30 14:26:25 +02:00
2020-04-04 17:42:02 +02:00
process.env.RUST_LOG = 'info';
2020-04-23 21:29:50 +02:00
execSync('cd .. && cargo build --bin jirs-css');
2020-05-02 00:12:47 +02:00
if (process.env.NODE_ENV === "production") {
execSync("rm -Rf ./dist");
execSync("mkdir -p ./dist");
execSync('cd .. && ./target/debug/jirs-css -O ./jirs-client/dist/styles.css');
console.log("CSS combined");
} else {
exec('cd .. && ./target/debug/jirs-css --watch -O ./jirs-client/dev/styles.css');
console.log("CSS combined, watching for changes...");
}
2020-04-23 21:29:50 +02:00
2020-03-30 14:26:25 +02:00
dotenv.config();
2020-03-29 19:56:55 +02:00
module.exports = {
2020-04-04 17:42:02 +02:00
entry: path.resolve(__dirname, 'js', 'index.js'),
output: {
filename: '[name].js',
path: path.resolve(__dirname, process.env.NODE_ENV === 'production' ? 'dist' : 'dev'),
2020-03-29 19:56:55 +02:00
publicPath: '/',
},
2020-05-02 00:12:47 +02:00
...(
process.env.NODE_ENV === "production"
? {
mode: "production",
watch: false,
devtool: false,
}
: {
mode: "development",
watch: true,
devtool: 'source-map',
devServer: {
contentBase: path.join(__dirname, 'dev'),
historyApiFallback: true,
hot: true,
port: process.env.JIRS_CLIENT_PORT || 6000,
host: process.env.JIRS_CLIENT_BIND || '0.0.0.0',
allowedHosts: [
'localhost:6000',
'localhost:8000',
],
headers: {
'Access-Control-Allow-Origin': '*',
2020-04-04 17:42:02 +02:00
}
2020-05-02 00:12:47 +02:00
},
2020-04-04 17:42:02 +02:00
}
2020-05-02 00:12:47 +02:00
),
2020-04-04 17:42:02 +02:00
plugins: [
2020-03-29 19:56:55 +02:00
new WasmPackPlugin({
crateDirectory: path.resolve(__dirname),
2020-04-10 08:09:40 +02:00
extraArgs: '--no-typescript'
2020-03-29 19:56:55 +02:00
}),
2020-03-30 08:16:26 +02:00
new HtmlWebpackPlugin({
template: path.resolve(__dirname, "js", "template.ejs"),
}),
2020-03-30 14:26:25 +02:00
new webpack.EnvironmentPlugin([
'NODE_ENV',
'DEBUG',
'JIRS_CLIENT_PORT',
'JIRS_CLIENT_BIND',
'JIRS_SERVER_PORT',
'JIRS_SERVER_BIND',
]),
2020-05-02 00:12:47 +02:00
],
2020-03-29 19:56:55 +02:00
};