2017-05-03 01:04:16 +01:00
|
|
|
// Common configuration for webpacker loaded from config/webpack/paths.yml
|
|
|
|
|
2017-05-20 16:31:47 +01:00
|
|
|
const { join, resolve } = require('path');
|
|
|
|
const { env } = require('process');
|
|
|
|
const { safeLoad } = require('js-yaml');
|
|
|
|
const { readFileSync } = require('fs');
|
2017-05-03 01:04:16 +01:00
|
|
|
|
2017-05-20 16:31:47 +01:00
|
|
|
const configPath = resolve('config', 'webpack');
|
|
|
|
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'];
|
2017-05-03 01:04:16 +01:00
|
|
|
|
|
|
|
// Compute public path based on environment and CDN_HOST in production
|
2017-05-20 16:31:47 +01:00
|
|
|
const ifHasCDN = env.CDN_HOST !== undefined && env.NODE_ENV === 'production';
|
[nanobox] Adjustments for Nanobox development (#3295)
Because Nanobox doesn't run data components in the same container as the code, there are a few tweaks that need to be made in the configuration to get WebPack to work properly in development mode.
The same differences lead to needing to use `DATABASE_URL` by default in the `.env` file for Rails to work correctly.
Limitations of our `.env` loader for Node.js mean the `.env` file needs to be compiled everywhere in order to work, so we compile it in development, now, too. Also, all the `.env.production` tweaks have been consolidated into a single command.
Finally, since Nanobox actually creates the database when it sets up the database server, using the existence of the database alone to determine whether to migrate or setup is insufficient. So we add a condition to `rake db:migrate:setup` to check whether any migrations have run - if the database doesn't exist yet, `db:setup` will be called; if it does, but no migrations have been run, `db:migrate` and `db:seed` are called instead (the same basic idea as what `db:setup` does, but it skips `db:create`, which will only cause problems with an existing DB); otherwise, only `db:migrate` is called.
None of these changes should affect development, and all are designed not to interfere with existing behaviors in other environments.
2017-05-29 16:59:18 +01:00
|
|
|
const devServerUrl = `http://${env.LOCAL_DOMAIN || devServer.host}:${devServer.port}/${paths.entry}/`;
|
2017-05-20 16:31:47 +01:00
|
|
|
const publicUrl = ifHasCDN ? `${env.CDN_HOST}/${paths.entry}/` : `/${paths.entry}/`;
|
|
|
|
const publicPath = env.NODE_ENV !== 'production' ? devServerUrl : publicUrl;
|
2017-05-03 01:04:16 +01:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
devServer,
|
|
|
|
env,
|
|
|
|
paths,
|
|
|
|
loadersDir,
|
|
|
|
publicUrl,
|
2017-05-20 16:31:47 +01:00
|
|
|
publicPath,
|
|
|
|
};
|