Files
sage/assets/build/config.js
QWp6t f6bdc7b48c Refactor build routine and switch to airbnb style (#1703)
- Relocate webpack stuff to assets/build
- Switch all js to airbnb code style
- Update webpack to v2.0 (beta)
- Update all other dependencies
- Assets manifest uses relative path as key [1]
- Code should be compatible with Node 4.5.0
- All dependencies have been updated

[1]: Previously the assets manifest would use the basename of a file path as
its key when looking up a cachebusted file. This was to be consistent with
Sage 8. This change makes it so that the relative path is used instead.

To clarify, review the following example.

Before:
```
{
  "main.js": "scripts/main_5f4bfc9a9f82291c6dea.js",
  "main.css": "styles/main_5f4bfc9a9f82291c6dea.css",
  "customizer.js": "scripts/customizer_5f4bfc9a9f82291c6dea.js"
}
```

After:
```
{
  "scripts/main.js":"scripts/main_5f4bfc9a9f82291c6dea.js",
  "styles/main.css":"styles/main_5f4bfc9a9f82291c6dea.css",
  "scripts/customizer.js":"scripts/customizer_5f4bfc9a9f82291c6dea.js"
}
```
2016-09-04 19:13:16 -07:00

53 lines
1.5 KiB
JavaScript

/* eslint-disable import/no-extraneous-dependencies */
const path = require('path');
const argv = require('minimist')(process.argv.slice(2));
const glob = require('glob-all');
const merge = require('lodash/merge');
const mergeWithConcat = require('./util/mergeWithConcat');
const userConfig = require('../config');
const isProduction = !!((argv.env && argv.env.production) || argv.p);
const rootPath = (userConfig.paths && userConfig.paths.root)
? userConfig.paths.root
: process.cwd();
const config = mergeWithConcat({
copy: ['images/**/*'],
proxyUrl: 'http://localhost:3000',
cacheBusting: '[name]_[hash]',
paths: {
root: rootPath,
assets: path.join(rootPath, 'assets'),
dist: path.join(rootPath, 'dist'),
},
enabled: {
sourceMaps: !isProduction,
minify: isProduction,
cacheBusting: isProduction,
watcher: !!argv.watch,
uglifyJs: !(argv.p || argv.optimizeMinimize),
},
watch: [
'templates/**/*.php',
'src/**/*.php',
],
}, userConfig);
Object.keys(config.entry).forEach(id =>
config.entry[id].unshift(path.join(__dirname, 'public-path.js')));
module.exports = mergeWithConcat(config, {
env: merge({ production: isProduction, development: !isProduction }, argv.env),
entry: {
get files() {
return glob.sync(config.copy, {
cwd: config.paths.assets,
mark: true,
}).filter(file => !((file.slice(-1) === '/') || (!file.indexOf('*') === -1)))
.map(file => path.join(config.paths.assets, file));
},
},
});