Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ web/.classpath
web/.project
backend/.classpath
backend/.project
assets/index.json.tmp
1 change: 1 addition & 0 deletions assets/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"plugins": [
{
"name": "SampleExtension",
"version": "@@VERSION@@",
"dependencies": [
"Toolbar"
]
Expand Down
23 changes: 22 additions & 1 deletion build/extension/prod-webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@

const path = require("path");
const fs = require("fs");

const createExtensionWebpackConfig = require('../../MapStore2/build/createExtensionWebpackConfig');
const CopyPlugin = require('copy-webpack-plugin');
const ZipPlugin = require('zip-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const {name} = require('../../config');
const commons = require('./commons');

// read version and produce a temporary updated index.json
const { version: versionText } = require('../../package.json');
const indexSrc = path.resolve(__dirname, "..", "..", "assets", "index.json");
const tmpIndex = path.resolve(__dirname, "..", "..", "assets", "index.json.tmp");
try {
const indexContent = JSON.parse(fs.readFileSync(indexSrc, 'utf8'));
if (Array.isArray(indexContent.plugins)) {
indexContent.plugins = indexContent.plugins.map(p => p && p.name === name ? { ...p, version: versionText } : p);
}
fs.writeFileSync(tmpIndex, JSON.stringify(indexContent, null, 4), 'utf8');
} catch (e) {
// keep behavior silent here; build will fail later if necessary
console.error('Error updating index.json from version.txt:', e);
}

// the build configuration for production allow to create the final zip file, compressed accordingly
const plugins = [
new CopyPlugin([
{ from: path.resolve(__dirname, "..", "..", "assets", "translations"), to: "translations" },
{ from: path.resolve(__dirname, "..", "..", "assets", "index.json"), to: "index.json" }
{ from: tmpIndex, to: 'index.json' }
]),
new ZipPlugin({
filename: `${name}.zip`,
Expand All @@ -22,6 +39,10 @@ const plugins = [
// other files have to be placed in the root, with the same name
return path.basename(assetPath);
}
}),
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: [],
cleanAfterEveryBuildPatterns: [tmpIndex]
})
];
module.exports = createExtensionWebpackConfig({ prod: true, name, ...commons, plugins});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"babel-plugin-object-assign": "1.2.1",
"babel-plugin-react-transform": "2.0.2",
"babel-plugin-transform-imports": "2.0.0",
"clean-webpack-plugin": "^4.0.0",
"copy-webpack-plugin": "5.0.2",
"css-loader": "5.1.2",
"css-minimizer-webpack-plugin": "3.0.2",
Expand Down