@eaglesong/task-panorama
Version:
Eaglesong task for Panorama
139 lines • 6.15 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const copy_webpack_plugin_1 = tslib_1.__importDefault(require("copy-webpack-plugin"));
const fork_ts_checker_webpack_plugin_1 = tslib_1.__importDefault(require("fork-ts-checker-webpack-plugin"));
const html_webpack_plugin_1 = tslib_1.__importDefault(require("html-webpack-plugin"));
const lodash_1 = tslib_1.__importDefault(require("lodash"));
const transformer_1 = tslib_1.__importDefault(require("panorama-types/transformer"));
const path_1 = tslib_1.__importDefault(require("path"));
const sass_1 = tslib_1.__importDefault(require("sass"));
const webpack_1 = tslib_1.__importDefault(require("webpack"));
const webpack_merge_1 = require("webpack-merge");
const HtmlWebpackXmlPlugin_1 = require("./plugins/HtmlWebpackXmlPlugin");
const OutputHeaderWebpackPlugin_1 = require("./plugins/OutputHeaderWebpackPlugin");
const PanoramaManifestPlugin_1 = require("./plugins/PanoramaManifestPlugin");
function createWebpackConfig({ context, dotaPath, addonName, outputOptions, }) {
const panoramaPath = path_1.default.join(context, 'src', 'panorama');
const tsconfigPath = path_1.default.join(panoramaPath, 'tsconfig.json');
const contentBasePath = dotaPath == null ? '/' : path_1.default.join(dotaPath, 'content', 'dota_addons', addonName);
const resolveContent = (...segments) => path_1.default.join(contentBasePath, ...segments);
const mainConfig = {
target: 'webworker',
// TODO: Make a runtime consumer for nosources-source-map
devtool: false,
context: panoramaPath,
output: {
path: resolveContent('panorama', 'layout', 'custom_game'),
publicPath: 'file://{resources}/layout/custom_game/',
filename: '[name]',
globalObject: 'globalThis',
},
// TODO: It would be nice to use splitChunks instead of DllPlugin
// But webpack 4 not supports sharing chunks with child compiler.
// See:
// https://github.com/webpack-contrib/worker-loader/issues/70
// https://github.com/webpack/webpack/pull/6447
optimization: { splitChunks: { cacheGroups: { vendor: false, default: false } } },
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
plugins: [new OutputHeaderWebpackPlugin_1.OutputHeaderWebpackPlugin(outputOptions)],
};
const resourcesConfig = {
module: {
rules: [
{
test: /\.(png|je?pg)$/,
loader: require.resolve('file-loader'),
options: { name: '[path][name].[ext]', esModule: false },
},
],
},
plugins: [
// Should be applied before `HtmlWebpackPlugin`, since both tap to `emit` hook
new copy_webpack_plugin_1.default({
patterns: [{ from: 'images', to: resolveContent('panorama', 'images') }],
}),
],
};
const scriptsConfig = {
resolve: { extensions: ['.js', '.jsx', '.ts', '.tsx'] },
module: {
rules: [
{
test: /\.[jt]sx?$/,
issuer: /\.xml$/,
loader: require.resolve('./plugins/entry-loader'),
options: lodash_1.default.identity({ plugins: ['BannerPlugin'] }),
},
{
test: /\.tsx?$/,
exclude: /node_modules/,
loader: require.resolve('ts-loader'),
options: lodash_1.default.identity({
configFile: tsconfigPath,
transpileOnly: true,
getCustomTransformers: () => ({ before: [transformer_1.default()] }),
}),
},
],
},
plugins: [
new fork_ts_checker_webpack_plugin_1.default({
async: false,
logger: { issues: 'silent' },
typescript: { configFile: tsconfigPath },
}),
new webpack_1.default.BannerPlugin({ banner: 'var globalThis = this;', raw: true, test: /\.js$/ }),
],
};
const layoutConfig = {
resolve: { extensions: ['.xml'] },
module: {
rules: [
{
test: /\.xml$/,
use: [
require.resolve('./plugins/emit-loader'),
require.resolve('./plugins/panorama-layout-loader'),
],
},
],
},
plugins: [
new PanoramaManifestPlugin_1.PanoramaManifestPlugin(path_1.default.join(context, 'src', 'panorama', 'manifest.yml')),
new html_webpack_plugin_1.default({
filename: 'custom_ui_manifest.xml',
inject: false,
template: path_1.default.resolve(__dirname, '../template.ejs'),
xhtml: true,
}),
new HtmlWebpackXmlPlugin_1.HtmlWebpackXmlPlugin(),
],
};
const stylesConfig = {
module: {
rules: [
{
test: /\.(c|sa|sc)ss$/,
issuer: /\.xml$/,
loader: require.resolve('file-loader'),
options: { name: '[path][name].css', esModule: false },
},
{
test: /\.s(a|c)ss$/,
loader: require.resolve('sass-loader'),
options: {
implementation: sass_1.default,
sassOptions: {
// VCSS doesn't allow omitting last semicolon in a rule
outputStyle: 'expanded',
},
},
},
],
},
};
return webpack_merge_1.merge(mainConfig, resourcesConfig, scriptsConfig, layoutConfig, stylesConfig);
}
exports.createWebpackConfig = createWebpackConfig;
//# sourceMappingURL=config.js.map
;