about summary refs log tree commit diff
path: root/config/webpack/configuration.js
diff options
context:
space:
mode:
authorYamagishi Kazutoshi <ykzts@desire.sh>2017-06-18 09:57:09 +0900
committerEugen Rochko <eugen@zeonfederated.com>2017-06-18 02:57:09 +0200
commit53e42bf91ef2c705168f8d04b9374c349ec14074 (patch)
tree564d8607ee6fd7ac27979d157b261c038e9fad61 /config/webpack/configuration.js
parent94d0e012dea89058b9c059636fb6d42f6565e534 (diff)
Upgrade Webpacker to version 2.0 (#3729)
Diffstat (limited to 'config/webpack/configuration.js')
-rw-r--r--config/webpack/configuration.js35
1 files changed, 22 insertions, 13 deletions
diff --git a/config/webpack/configuration.js b/config/webpack/configuration.js
index 2a54080cf..6ef484c3a 100644
--- a/config/webpack/configuration.js
+++ b/config/webpack/configuration.js
@@ -1,26 +1,35 @@
-// Common configuration for webpacker loaded from config/webpack/paths.yml
+// Common configuration for webpacker loaded from config/webpacker.yml
 
 const { join, resolve } = require('path');
 const { env } = require('process');
 const { safeLoad } = require('js-yaml');
 const { readFileSync } = require('fs');
 
-const configPath = resolve('config', 'webpack');
+const configPath = resolve('config', 'webpacker.yml');
 const loadersDir = join(__dirname, 'loaders');
-const paths = safeLoad(readFileSync(join(configPath, 'paths.yml'), 'utf8'))[env.NODE_ENV || 'development'];
-const devServer = safeLoad(readFileSync(join(configPath, 'development.server.yml'), 'utf8'))[env.NODE_ENV || 'development'];
+const settings = safeLoad(readFileSync(configPath), 'utf8')[env.NODE_ENV];
 
-// Compute public path based on environment and CDN_HOST in production
-const ifHasCDN = env.CDN_HOST !== undefined && env.NODE_ENV === 'production';
-const devServerUrl = `http://${env.LOCAL_DOMAIN || devServer.host}:${devServer.port}/${paths.entry}/`;
-const publicUrl = ifHasCDN ? `${env.CDN_HOST}/${paths.entry}/` : `/${paths.entry}/`;
-const publicPath = env.NODE_ENV !== 'production' ? devServerUrl : publicUrl;
+function removeOuterSlashes(string) {
+  return string.replace(/^\/*/, '').replace(/\/*$/, '');
+}
+
+function formatPublicPath(host = '', path = '') {
+  let formattedHost = removeOuterSlashes(host);
+  if (formattedHost && !/^http/i.test(formattedHost)) {
+    formattedHost = `//${formattedHost}`;
+  }
+  const formattedPath = removeOuterSlashes(path);
+  return `${formattedHost}/${formattedPath}/`;
+}
+
+const output = {
+  path: resolve('public', settings.public_output_path),
+  publicPath: formatPublicPath(env.ASSET_HOST, settings.public_output_path),
+};
 
 module.exports = {
-  devServer,
+  settings,
   env,
-  paths,
   loadersDir,
-  publicUrl,
-  publicPath,
+  output,
 };