Files
spark/src/web/ui/webpack.config.js
T

81 lines
2.2 KiB
JavaScript

var path = require("path");
var webpack = require("webpack");
var fableUtils = require("fable-utils");
var UglifyJsPlugin = require("uglifyjs-webpack-plugin")
function resolve(filePath) {
return path.join(__dirname, filePath)
}
var babelOptions = fableUtils.resolveBabelOptions({
presets: [["es2015", { "modules": false }]],
plugins: [["transform-runtime", {
"helpers": true,
// We don't need the polyfills as we're already calling
// cdn.polyfill.io/v2/polyfill.js in index.html
"polyfill": false,
"regenerator": false
}]]
});
var isProduction = process.argv.indexOf("-p") >= 0;
console.log("Bundling for " + (isProduction ? "production" : "development") + "...");
module.exports = env => {
const build_path = env.BUILD_PATH || resolve("../../../build/web")
const output_path = build_path + "/ui/";
const api_path = build_path + "/api/";
return {
devtool: isProduction ? undefined : "source-map",
entry: resolve('./src/ui.fsproj'),
output: {
filename: 'bundle.js',
path: output_path,
},
resolve: {
modules: [
"node_modules", resolve("./node_modules/"), api_path
]
},
devServer: {
contentBase: resolve("./public/"),
port: 8080,
hot: true,
inline: true
},
module: {
rules: [
{
test: /\.fs(x|proj)?$/,
use: {
loader: "fable-loader",
options: {
babel: babelOptions,
define: isProduction ? [] : ["DEBUG"]
}
}
},
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: babelOptions
},
},
{
test: /\.sass$/,
use: [
"style-loader",
"css-loader",
"sass-loader"
]
}
]
},
plugins: isProduction ? [new UglifyJsPlugin()] : [
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin()
]
}};