From 49c27c4c7a10dc4ca7bee2364eb38b9ed1e016f7 Mon Sep 17 00:00:00 2001 From: Alasdair Smith Date: Fri, 12 Jan 2018 11:41:02 +0000 Subject: [PATCH] Port webpack config from OL --- services/web/webpack.config.dev.js | 41 +++++++++++++++++++++++ services/web/webpack.config.js | 54 ++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 services/web/webpack.config.dev.js create mode 100644 services/web/webpack.config.js diff --git a/services/web/webpack.config.dev.js b/services/web/webpack.config.dev.js new file mode 100644 index 0000000000..316f0d15f8 --- /dev/null +++ b/services/web/webpack.config.dev.js @@ -0,0 +1,41 @@ +const merge = require('webpack-merge') + +const base = require('./webpack.config') + +module.exports = merge(base, { + // Enable source maps for dev (fast compilation, slow runtime) + devtool: 'cheap-module-eval-source-map', + + devServer: { + // Disable webpack dev server auto-reload + inline: false, + + // Expose dev server as localhost with dev box + host: '0.0.0.0', + + // Webpack-rails default port for webpack-dev-server + port: 3808, + + // Allow CORS + headers: { + 'Access-Control-Allow-Origin': '*' + }, + + // Customise output to the (node) console + stats: { + colors: true, // Enable some coloured highlighting + timings: true, // Show build timing info + assets: true, // Show output bundles + warnings: true, // Show build warnings + // Hide some overly verbose output + hash: false, + version: false, + chunks: false + } + }, + + // Disable performance budget warnings as code is uncompressed in dev mode + performance: { + hints: false + } +}) diff --git a/services/web/webpack.config.js b/services/web/webpack.config.js new file mode 100644 index 0000000000..13b77bcacc --- /dev/null +++ b/services/web/webpack.config.js @@ -0,0 +1,54 @@ +const path = require('path') + +module.exports = { + // Defines the "entry point" for the application - i.e. the file which + // bootstraps the application + entry: { + 'rich-text': './public/frontend/rich-text.js' + }, + + // Define where and how the bundle will be output to disk + // Note: webpack-dev-server does not write the bundle to disk, instead it is + // kept in memory for speed + output: { + path: path.join(__dirname, '/public/js/frontend'), + // publicPath: '/frontend/', + + filename: '[name].js', + + // Output as UMD bundle (allows main JS to import with CJS, AMD or global + // style code bundles + libraryTarget: 'umd', + // Name the exported variable from output bundle + library: ['Frontend', '[name]'] + }, + + // TODO?? + // Defines the external modules which will be stripped out when bundling for + // the rails app. These modules are already loaded in the rails app + // environment, so we strip them out to prevent conflicts. + // externals: {}, + + // Define how file types are handled by webpack + module: { + rules: [{ + // Pass application JS files through babel-loader, compiling to ES5 + test: /\.js$/, // Only compile .js files + // Only compile application files (dependencies are in ES5 already) + // include: [path.join(__dirname, './public/frontend')], + exclude: /node_modules/, + use: [{ + loader: 'babel-loader', + options: { + presets: ['env'], + // Configure babel-loader to cache compiled output so that subsequent + // compile runs are much faster + cacheDirectory: true + } + }] + }] + }, + + // TODO + // plugins: {} +} \ No newline at end of file