2020-04-24 02:08:47 +03:00
|
|
|
const path = require('path');
|
2020-04-30 01:48:25 +03:00
|
|
|
// const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
|
|
// const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
|
|
|
const urbitrc = require('./urbitrc');
|
2020-06-05 05:50:14 +03:00
|
|
|
const fs = require('fs');
|
|
|
|
const util = require('util');
|
2020-10-13 08:04:46 +03:00
|
|
|
const _ = require('lodash');
|
2020-06-05 05:50:14 +03:00
|
|
|
const exec = util.promisify(require('child_process').exec);
|
|
|
|
|
|
|
|
function copyFile(src,dest) {
|
|
|
|
return new Promise((res,rej) =>
|
|
|
|
fs.copyFile(src,dest, err => err ? rej(err) : res()));
|
|
|
|
}
|
|
|
|
|
|
|
|
class UrbitShipPlugin {
|
|
|
|
constructor(urbitrc) {
|
|
|
|
this.piers = urbitrc.URBIT_PIERS;
|
|
|
|
this.herb = urbitrc.herb || false;
|
|
|
|
}
|
|
|
|
|
|
|
|
apply(compiler) {
|
2020-06-10 05:46:38 +03:00
|
|
|
compiler.hooks.afterEmit.tapPromise(
|
2020-06-05 05:50:14 +03:00
|
|
|
'UrbitShipPlugin',
|
|
|
|
async (compilation) => {
|
|
|
|
const src = path.resolve(compiler.options.output.path, 'index.js');
|
2020-07-15 00:03:55 +03:00
|
|
|
// uncomment to copy into all piers
|
|
|
|
//
|
|
|
|
// return Promise.all(this.piers.map(pier => {
|
|
|
|
// const dst = path.resolve(pier, 'app/landscape/js/index.js');
|
|
|
|
// copyFile(src, dst).then(() => {
|
|
|
|
// if(!this.herb) {
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// pier = pier.split('/');
|
|
|
|
// const desk = pier.pop();
|
|
|
|
// return exec(`herb -p hood -d '+hood/commit %${desk}' ${pier.join('/')}`);
|
|
|
|
// });
|
|
|
|
// }));
|
2020-06-05 05:50:14 +03:00
|
|
|
}
|
2020-07-15 00:03:55 +03:00
|
|
|
);
|
2020-06-05 05:50:14 +03:00
|
|
|
}
|
|
|
|
}
|
2020-04-24 02:08:47 +03:00
|
|
|
|
2020-07-15 08:04:14 +03:00
|
|
|
let devServer = {
|
|
|
|
contentBase: path.join(__dirname, '../dist'),
|
|
|
|
hot: true,
|
|
|
|
port: 9000,
|
2020-09-26 02:13:29 +03:00
|
|
|
host: '0.0.0.0',
|
|
|
|
disableHostCheck: true,
|
2020-07-15 08:04:14 +03:00
|
|
|
historyApiFallback: true
|
2020-07-16 18:40:35 +03:00
|
|
|
};
|
2020-07-15 08:04:14 +03:00
|
|
|
|
2020-10-13 08:04:46 +03:00
|
|
|
const router = _.mapKeys(urbitrc.FLEET || {}, (value, key) => `${key}.localhost:9000`);
|
|
|
|
|
2020-07-15 08:04:14 +03:00
|
|
|
if(urbitrc.URL) {
|
|
|
|
devServer = {
|
2020-07-16 18:40:35 +03:00
|
|
|
...devServer,
|
2020-07-15 08:04:14 +03:00
|
|
|
index: '',
|
|
|
|
proxy: {
|
2020-08-04 03:41:55 +03:00
|
|
|
'/~landscape/js/bundle/index.*.js': {
|
2020-07-16 02:32:11 +03:00
|
|
|
target: 'http://localhost:9000',
|
2020-10-13 08:04:46 +03:00
|
|
|
pathRewrite: (req, path) => {
|
|
|
|
return '/index.js'
|
|
|
|
}
|
2020-07-16 02:32:11 +03:00
|
|
|
},
|
|
|
|
'**': {
|
2020-10-13 08:04:46 +03:00
|
|
|
changeOrigin: true,
|
2020-07-16 02:32:11 +03:00
|
|
|
target: urbitrc.URL,
|
2020-10-13 08:04:46 +03:00
|
|
|
router,
|
2020-07-16 02:32:11 +03:00
|
|
|
// ensure proxy doesn't timeout channels
|
2020-10-13 08:04:46 +03:00
|
|
|
proxyTimeout: 0,
|
|
|
|
}
|
2020-07-15 08:04:14 +03:00
|
|
|
}
|
2020-07-16 18:40:35 +03:00
|
|
|
};
|
2020-07-15 08:04:14 +03:00
|
|
|
}
|
|
|
|
|
2020-04-24 02:08:47 +03:00
|
|
|
module.exports = {
|
2020-04-30 01:48:25 +03:00
|
|
|
mode: 'development',
|
2020-04-24 02:08:47 +03:00
|
|
|
entry: {
|
2020-05-01 05:54:03 +03:00
|
|
|
app: './src/index.js'
|
2020-04-24 02:08:47 +03:00
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
2020-06-22 07:59:02 +03:00
|
|
|
test: /\.(j|t)sx?$/,
|
2020-04-24 02:08:47 +03:00
|
|
|
use: {
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
2020-06-20 07:45:52 +03:00
|
|
|
presets: ['@babel/preset-env', '@babel/typescript', '@babel/preset-react'],
|
2020-04-24 02:08:47 +03:00
|
|
|
plugins: [
|
2020-07-15 23:42:56 +03:00
|
|
|
'@babel/transform-runtime',
|
2020-04-24 02:08:47 +03:00
|
|
|
'@babel/plugin-proposal-object-rest-spread',
|
2020-05-01 05:54:03 +03:00
|
|
|
'@babel/plugin-proposal-optional-chaining',
|
2020-07-15 08:04:14 +03:00
|
|
|
'@babel/plugin-proposal-class-properties',
|
|
|
|
'react-hot-loader/babel'
|
2020-04-24 02:08:47 +03:00
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
2020-11-10 05:47:12 +03:00
|
|
|
exclude: /node_modules\/(?!(@tlon\/indigo-dark|@tlon\/indigo-light)\/).*/
|
2020-04-24 02:08:47 +03:00
|
|
|
},
|
2020-04-30 01:48:25 +03:00
|
|
|
{
|
2020-04-30 02:02:59 +03:00
|
|
|
test: /\.css$/i,
|
2020-04-30 01:48:25 +03:00
|
|
|
use: [
|
|
|
|
// Creates `style` nodes from JS strings
|
|
|
|
'style-loader',
|
|
|
|
// Translates CSS into CommonJS
|
|
|
|
'css-loader',
|
|
|
|
// Compiles Sass to CSS
|
|
|
|
'sass-loader'
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
2020-04-24 02:08:47 +03:00
|
|
|
},
|
|
|
|
resolve: {
|
2020-06-22 07:59:02 +03:00
|
|
|
extensions: ['.js', '.ts', '.tsx']
|
2020-04-24 02:08:47 +03:00
|
|
|
},
|
|
|
|
devtool: 'inline-source-map',
|
2020-07-15 08:04:14 +03:00
|
|
|
devServer: devServer,
|
2020-04-24 02:08:47 +03:00
|
|
|
plugins: [
|
2020-06-05 05:50:14 +03:00
|
|
|
new UrbitShipPlugin(urbitrc)
|
2020-04-28 23:49:39 +03:00
|
|
|
// new CleanWebpackPlugin(),
|
2020-04-24 23:23:58 +03:00
|
|
|
// new HtmlWebpackPlugin({
|
|
|
|
// title: 'Hot Module Replacement',
|
|
|
|
// template: './public/index.html',
|
|
|
|
// }),
|
2020-04-24 02:08:47 +03:00
|
|
|
],
|
2020-06-05 05:50:14 +03:00
|
|
|
watch: true,
|
2020-04-24 02:08:47 +03:00
|
|
|
output: {
|
2020-04-24 23:23:58 +03:00
|
|
|
filename: 'index.js',
|
|
|
|
chunkFilename: 'index.js',
|
2020-06-05 05:50:14 +03:00
|
|
|
path: path.resolve(__dirname, '../dist'),
|
2020-04-24 02:08:47 +03:00
|
|
|
publicPath: '/'
|
|
|
|
},
|
2020-04-28 23:49:39 +03:00
|
|
|
optimization: {
|
2020-04-30 01:48:25 +03:00
|
|
|
minimize: false,
|
|
|
|
usedExports: true
|
2020-04-28 23:49:39 +03:00
|
|
|
}
|
2020-04-24 02:08:47 +03:00
|
|
|
};
|