2022-07-11 17:27:00 +00:00
|
|
|
const Encore = require('@symfony/webpack-encore');
|
|
|
|
const { resolve, parse } = require('path');
|
|
|
|
const { readdir } = require('fs').promises;
|
|
|
|
|
|
|
|
/**
|
2022-12-24 14:40:18 +00:00
|
|
|
* get the file names inside given directory recursively, limiting to
|
2022-07-11 17:27:00 +00:00
|
|
|
* a given depth in the recursion
|
2022-12-24 14:40:18 +00:00
|
|
|
*
|
2022-07-11 17:27:00 +00:00
|
|
|
* @param string dir the directory
|
|
|
|
* @param int depth the maximum depth to look into
|
|
|
|
*/
|
|
|
|
async function* getFiles(dir, depth, ignored) {
|
|
|
|
const dirents = await readdir(dir, { withFileTypes: true });
|
|
|
|
for (const dirent of dirents) {
|
|
|
|
const res = resolve(dir, dirent.name);
|
|
|
|
if (dirent.isDirectory()) {
|
|
|
|
if (depth > 0) {
|
|
|
|
yield* getFiles(res, depth - 1, ignored);
|
|
|
|
}
|
|
|
|
} else if (ignored.includes(res)) {
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
yield res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* populate the config of encore in directories inside `'./src'` and
|
|
|
|
* `'./vendor'` and letting them to alter the encore config.
|
2022-12-24 14:40:18 +00:00
|
|
|
*
|
2022-07-11 17:27:00 +00:00
|
|
|
* if a file `chill.webpack.config.js` is found, the default function is
|
2022-12-24 14:40:18 +00:00
|
|
|
* imported and executed. This function receive two arguments:
|
|
|
|
*
|
2022-07-11 17:27:00 +00:00
|
|
|
* - `Encore`, the main encore object
|
|
|
|
* - `chillEntries`: the entries which will be appended to the main `chill` module,
|
|
|
|
* resulting in a chill.js and chill.css file.
|
2022-12-24 14:40:18 +00:00
|
|
|
*
|
2022-07-11 17:27:00 +00:00
|
|
|
*/
|
|
|
|
async function populateConfig(Encore, chillEntries) {
|
|
|
|
// chill-main contains some bootstrap that must be loaded first.
|
|
|
|
// we register them first and, then, store this chill.webpack.config.js file
|
|
|
|
// into `toIgnore`, ignoring it when we loop on other folders.
|
2022-12-24 14:40:18 +00:00
|
|
|
let
|
2022-07-11 17:27:00 +00:00
|
|
|
toIgnore = [];
|
2022-12-24 14:40:18 +00:00
|
|
|
|
2022-07-11 17:27:00 +00:00
|
|
|
// loop into chill main
|
|
|
|
for await (const f of getFiles('./vendor/chill-project/chill-bundles/src/Bundle/ChillMainBundle/', 1, [])) {
|
|
|
|
let filename = parse(f).base;
|
|
|
|
if (filename === 'chill.webpack.config.js') {
|
|
|
|
configure = require(f);
|
|
|
|
configure(Encore, chillEntries);
|
|
|
|
toIgnore.push(f);
|
|
|
|
}
|
|
|
|
}
|
2022-12-24 14:40:18 +00:00
|
|
|
|
2022-07-11 17:27:00 +00:00
|
|
|
// loop into other chill bundles
|
|
|
|
for await (const f of getFiles('./vendor/chill-project/chill-bundles/src/Bundle', 2, toIgnore)) {
|
|
|
|
let filename = parse(f).base;
|
|
|
|
if (filename === 'chill.webpack.config.js') {
|
|
|
|
configure = require(f);
|
|
|
|
configure(Encore, chillEntries);
|
|
|
|
}
|
|
|
|
}
|
2022-12-24 14:40:18 +00:00
|
|
|
|
2022-07-11 17:27:00 +00:00
|
|
|
// loop into other vendors
|
|
|
|
for await (const f of getFiles('./vendor/', 3, toIgnore)) {
|
|
|
|
let filename = parse(f).base;
|
|
|
|
if (filename === 'chill.webpack.config.js') {
|
|
|
|
configure = require(f);
|
|
|
|
configure(Encore, chillEntries);
|
|
|
|
}
|
|
|
|
}
|
2022-12-24 14:40:18 +00:00
|
|
|
|
2022-07-11 17:27:00 +00:00
|
|
|
// loop into src directory
|
|
|
|
for await (const f of getFiles('./src', 3, [])) {
|
|
|
|
let filename = parse(f).base;
|
|
|
|
if (filename === 'chill.webpack.config.js') {
|
|
|
|
configure = require(f);
|
|
|
|
configure(Encore, chillEntries);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// export the final configuration
|
|
|
|
module.exports = (async () => {
|
2022-12-24 14:40:18 +00:00
|
|
|
|
|
|
|
// Manually configure the runtime environment if not already configured yet by the "encore" command.
|
|
|
|
// It's useful when you use tools that rely on webpack.config.js file.
|
|
|
|
if (!Encore.isRuntimeEnvironmentConfigured()) {
|
|
|
|
Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'dev');
|
|
|
|
}
|
2022-07-11 17:27:00 +00:00
|
|
|
// basic encore configuration
|
|
|
|
Encore
|
|
|
|
.setOutputPath('public/build/')
|
|
|
|
.setPublicPath('/build')
|
|
|
|
.enableSassLoader()
|
2022-12-24 14:40:18 +00:00
|
|
|
.enableVueLoader(() => {}, {
|
2022-07-11 17:27:00 +00:00
|
|
|
version: 3
|
|
|
|
})
|
2022-12-24 14:40:18 +00:00
|
|
|
.enableTypeScriptLoader(function (tsConfig){
|
|
|
|
tsConfig.appendTsSuffixTo = [/\.vue$/];
|
|
|
|
tsConfig.appendTsxSuffixTo = [/\.vue$/];
|
|
|
|
// temporary fix for https://github.com/vuejs/vue-loader/issues/1915 and https://github.com/vuejs/core/issues/2855
|
|
|
|
tsConfig.compilerOptions = {strict: !Encore.isProduction()};
|
|
|
|
tsConfig.silent = false;
|
|
|
|
})
|
|
|
|
//.enableForkedTypeScriptTypesChecking()
|
2022-07-11 17:27:00 +00:00
|
|
|
.autoProvidejQuery()
|
|
|
|
.enableSourceMaps(!Encore.isProduction())
|
|
|
|
.cleanupOutputBeforeBuild()
|
2023-09-06 10:54:47 +00:00
|
|
|
//.enableBuildNotifications()
|
2022-07-11 17:27:00 +00:00
|
|
|
.enableVersioning()
|
|
|
|
.enableSingleRuntimeChunk()
|
|
|
|
.splitEntryChunks()
|
2023-09-06 10:54:47 +00:00
|
|
|
// added when upgrading to symfony 5.4
|
|
|
|
// enables and configure @babel/preset-env polyfills
|
|
|
|
//.configureBabelPresetEnv((config) => {
|
|
|
|
// config.useBuiltIns = 'usage';
|
|
|
|
// config.corejs = '3.23';
|
|
|
|
//})
|
2022-12-24 14:40:18 +00:00
|
|
|
//.addLoader({ test: /\.pdf$/, loader: 'file-loader', options: { name: '[name]_[hash].[ext]', outputPath: 'pdf/' } })
|
2022-07-11 17:27:00 +00:00
|
|
|
;
|
2022-12-24 14:40:18 +00:00
|
|
|
|
2022-07-11 17:27:00 +00:00
|
|
|
// populate config with chill entries
|
|
|
|
let chillEntries = [];
|
|
|
|
await populateConfig(Encore, chillEntries);
|
2023-09-06 10:54:47 +00:00
|
|
|
// configure Babel
|
|
|
|
// .configureBabel((config) => {
|
|
|
|
// config.plugins.push('@babel/a-babel-plugin');
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
|
|
// enables Sass/SCSS support
|
|
|
|
//.enableSassLoader()
|
2022-07-11 17:27:00 +00:00
|
|
|
|
|
|
|
// add swagger UI
|
|
|
|
if (!Encore.isProduction()) {
|
|
|
|
Encore
|
|
|
|
.addEntry('swagger', __dirname + '/assets/swagger-ui/index.js')
|
2022-12-24 14:40:18 +00:00
|
|
|
.addLoader({
|
2022-07-11 17:27:00 +00:00
|
|
|
test: /\.yaml$/,
|
|
|
|
type: 'json',
|
|
|
|
use: [
|
|
|
|
{ loader: 'json-loader' },
|
|
|
|
{ loader: 'yaml-loader' }
|
|
|
|
],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//getting the encore config and appending chill entries
|
|
|
|
config = Encore.getWebpackConfig();
|
|
|
|
config.entry.chill = chillEntries;
|
|
|
|
|
|
|
|
if (!Encore.isProduction()) {
|
|
|
|
console.log(config);
|
|
|
|
config.devtool = 'eval-source-map';
|
|
|
|
}
|
|
|
|
|
|
|
|
return config;
|
|
|
|
})();
|