-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
58 lines (52 loc) · 2.24 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// webpack.config.js
let Encore = require('@symfony/webpack-encore');
const path = require('path');
const { table } = require('table');
process.env.NODE_ENV = Encore.isProduction() ? 'production' : 'development';
// Represents a package in the "packages"-directory where a CSS and JS Assets need to be compiled.
const packages = ['template'];
const data = [
['Package', 'Public-Path', 'Src-Folder', 'Aliases', 'Build-Context']
];
const alias = {};
const envs = packages.map(function (packageName) {
const extension = require(`./webpack/${packageName}.webpack.config.js`);
extension.name = packageName;
extension.alias = '@' + packageName;
extension.relRoot = extension.root;
extension.root = path.resolve(__dirname, extension.root);
// gathering aliases, so every extension can load resources from each other.
// Use case described below
alias[extension.alias] = extension.root;
// By loading/requiring the webpack config above the code in the module will be executed as well.
// The reset prevents that all the configuration from the previous package wont mess up anything
// in the next webpack.config we load.
Encore.reset();
return extension;
});
module.exports = envs.map(function (env, index) {
// if other aliases exists, we still want to keep them.
const existingAliases = env.webpack.resolve.alias;
// This will set an global alias in webpack to your asset root path
// with this alias you are able to import scripts or VueComponents from other packages more easily.
// So instead of doing
// import myAwesomeComponent from '../../../up/up/we/go/packages/my_package/asset/javascript/Components/FancyComponent.vue'
// you can do this
// import myAwesomeComponent from '@my_package/javascript/Components/FancyComponent.vue'
env.webpack.resolve.alias = {
...existingAliases,
...alias
};
env.webpack.name = env.name;
data.push([
env.name,
env.webpack.output.publicPath,
env.relRoot,
Object.keys(env.webpack.resolve.alias).reduce((acc, key) => acc + `${key} => ${env.webpack.resolve.alias[key]}\n`, ''),
Encore.isProduction() ? '\x1b[32mProduction\x1b[0m' : '\x1b[33mDevelopment\x1b[0m'
]);
if ((index + 1) === packages.length) {
console.log(table(data));
}
return env.webpack;
});