Skip to content

Commit

Permalink
Build esm with rollup (#9503)
Browse files Browse the repository at this point in the history
* Implement core rollup build

* Remove old webpack.fesm* configs

* Fix process.env.VERSION is exists in result build

* Add license banner

* Remove unused dep

* Implement react build via rollup

* Fix replace plugin warning

* Fix icons build

* Fix icons build (2)

* Fix icons build (3)

* Fix sourcemaps
  • Loading branch information
dk981234 authored Feb 25, 2025
1 parent c350579 commit 9cd581d
Show file tree
Hide file tree
Showing 15 changed files with 226 additions and 122 deletions.
24 changes: 15 additions & 9 deletions packages/survey-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"name": "survey-core",
"version": "2.0.0",
"scripts": {
"build": "webpack --env buildType=dev --env emitDeclarations --env emitNonSourceFiles && webpack --env buildType=prod && webpack --config ./webpack.fesm.config.mjs --env buildType=prod",
"build:i18n": "webpack --config ./webpack.i18n.config.js --env buildType=dev && webpack --config ./webpack.i18n.config.js --env buildType=prod && webpack --config ./webpack.i18n.fesm.config.mjs --env buildType=prod",
"build:themes": "webpack --config ./webpack.themes.config.js --env buildType=dev --env emitDeclarations && webpack --config ./webpack.themes.config.js --env buildType=prod && webpack --config ./webpack.themes.fesm.config.mjs --env buildType=prod",
"build:icons": "webpack --config ./webpack.icons.config.js --env buildType=dev --env emitDeclarations && webpack --config ./webpack.icons.config.js --env buildType=prod && webpack --config ./webpack.icons.fesm.config.mjs --env buildType=prod",
"watch:dev": "concurrently \"webpack --env buildType=dev --watch --env emitDeclarations\" \"webpack --config ./webpack.fesm.config.mjs --env buildType=prod --watch\" ",
"build": "webpack --env buildType=dev --env emitDeclarations --env emitNonSourceFiles && webpack --env buildType=prod && rollup -c",
"build:i18n": "webpack --config ./webpack.i18n.config.js --env buildType=dev && webpack --config ./webpack.i18n.config.js --env buildType=prod && rollup -c rollup.i18n.config.js",
"build:themes": "webpack --config ./webpack.themes.config.js --env buildType=dev --env emitDeclarations && webpack --config ./webpack.themes.config.js --env buildType=prod && rollup -c rollup.themes.config.js",
"build:icons": "webpack --config ./webpack.icons.config.js --env buildType=dev --env emitDeclarations && webpack --config ./webpack.icons.config.js --env buildType=prod && rollup -c rollup.icons.config.js",
"watch:dev": "concurrently \"webpack --env buildType=dev --watch --env emitDeclarations\" \"rollup -c -w\" ",
"build:all": "npm run build && npm run build:i18n && npm run build:themes && npm run build:icons",
"test": "karma start ./karma.conf.js --single-run",
"test:watch": "karma start ./karma.conf.js",
Expand All @@ -21,13 +21,18 @@
"url": "https://github.com/surveyjs/surveyjs.git"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^16.0.0",
"@rollup/plugin-replace": "^6.0.2",
"@rollup/plugin-typescript": "^12.1.2",
"@types/node": "18.11.12",
"@types/qunit": "2.0.31",
"@types/signature_pad": "^2.3.0",
"autoprefixer": "^10.4.17",
"commit-and-tag-version": "^11.0.0",
"concurrently": "^5.2.0",
"css-loader": "^7.1.2",
"eslint": "^7.32.0",
"fast-glob": "^3.3.3",
"karma": "^6.1.1",
"karma-chrome-launcher": "^3.1.0",
"karma-junit-reporter": "2.0.1",
Expand All @@ -42,23 +47,24 @@
"postcss-fail-on-warn": "0.2.1",
"qunitjs": "2.2.0",
"rimraf": "2.5.4",
"rollup": "^4.34.8",
"rollup-plugin-license": "^3.6.0",
"sass": "^1.62.1",
"sass-loader": "^16.0.4",
"commit-and-tag-version": "^11.0.0",
"signature_pad": "^4.1.5",
"style-loader": "^1.2.1",
"surveyjs-doc-generator": "git+https://github.com/surveyjs/surveyjs-doc-generator.git",
"svg-inline-loader": "^0.8.2",
"ts-loader": "^9.5.2",
"ts-node": "3.3.0",
"tsconfig-paths-webpack-plugin": "^3.3.0",
"typescript": "^5.7.0",
"webpack": "^5.93.0",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^5.0.4",
"webpack-fix-style-only-entries": "^0.6.1",
"webpack-merge": "^5.8.0",
"webpack-remove-empty-scripts": "^1.0.4",
"tsconfig-paths-webpack-plugin": "^3.3.0",
"signature_pad": "^4.1.5"
"webpack-remove-empty-scripts": "^1.0.4"
},
"commit-and-tag-version": {
"bumpFiles": [
Expand Down
56 changes: 56 additions & 0 deletions packages/survey-core/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const typescript = require("@rollup/plugin-typescript");
const nodeResolve = require("@rollup/plugin-node-resolve");
const replace = require("@rollup/plugin-replace");
const bannerPlugin = require("rollup-plugin-license");
const path = require("path");
const VERSION = require("./package.json").version;
const input = { "survey-core": path.resolve(__dirname, "./entries/index.ts") };

const banner = [
"surveyjs - Survey JavaScript library v" + VERSION,
"Copyright (c) 2015-" + new Date().getFullYear() + " Devsoft Baltic OÜ - http://surveyjs.io/",
"License: MIT (http://www.opensource.org/licenses/mit-license.php)",
].join("\n");

module.exports = (options) => {
options = options ?? {};
if(!options.tsconfig) {
options.tsconfig = path.resolve(__dirname, "./tsconfig.fesm.json");
}
if(!options.dir) {
options.dir = path.resolve(__dirname, "./build/fesm");
}
return {
input,
context: "this",

plugins: [
nodeResolve(),
typescript({ inlineSources: true, sourceMap: true, tsconfig: options.tsconfig, compilerOptions: {
declaration: false,
declarationDir: null
} }),
replace({
preventAssignment: false,
values: {
"process.env.RELEASE_DATE": JSON.stringify(new Date().toISOString().slice(0, 10)),
"process.env.VERSION": JSON.stringify(VERSION),
}
}),
bannerPlugin({
banner: {
content: banner,
commentStyle: "ignored",
}
})
],
output: [
{
dir: options.dir,
format: "esm",
exports: "named",
sourcemap: true,
},
],
};
};
27 changes: 27 additions & 0 deletions packages/survey-core/rollup.i18n.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const defaultConfig = require("./rollup.config");
const path = require("path");
const fs = require("fs");
const input = {
"survey.i18n": path.resolve(__dirname, "./entries/i18n.ts")
};

function patchEntries() {
fs.readdirSync(path.resolve(__dirname, "./src/localization")).forEach(file => {
var extension = path.extname(file);
if (extension.toLowerCase() === ".ts") {
input[`i18n/${path.basename(file, extension)}`] = (path.resolve(__dirname, "./src/localization") + "/" + file);
}
});
input["i18n/index"] = path.resolve(__dirname, "./entries/i18n.ts");
}

module.exports = () => {
let options = {
tsconfig: path.resolve(__dirname, "./tsconfig.i18n.json")
};
const config = defaultConfig(options);
patchEntries();
config.input = input;
config.external = ["survey-core"];
return config;
};
39 changes: 39 additions & 0 deletions packages/survey-core/rollup.icons.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const defaultConfig = require("./rollup.config");
const path = require("path");
const fg = require("fast-glob");
const svgLoader = require("svg-inline-loader");
const readFile = require("fs").readFileSync;
const input = {
"iconsV1": path.resolve(__dirname, "./src/iconsV1-es.ts"),
"iconsV2": path.resolve(__dirname, "./src/iconsV2-es.ts"),
};
module.exports = () => {
let options = {
dir: path.resolve(__dirname, "./build/fesm/icons"),
tsconfig: path.resolve(__dirname, "./tsconfig.icons.json")
};
const config = defaultConfig(options);
const iconsMap = {
"iconsV1": fg.convertPathToPattern(path.resolve(__dirname, "./src/images-v1")) + "/*.svg",
"iconsV2": fg.convertPathToPattern(path.resolve(__dirname, "./src/images-v2")) + "/*.svg"
};
config.plugins.push({
name: "icons",
resolveId: (id) => {
if (Object.keys(iconsMap).includes(id)) {
return id;
}
},
load: async (id) => {
if (Object.keys(iconsMap).includes(id)) {
const icons = {};
for (const iconPath of await fg.glob(iconsMap[id])) {
icons[path.basename(iconPath).replace(/\.svg$/, "").toLocaleLowerCase()] = svgLoader.getExtractedSVG(readFile(iconPath).toString());
}
return `export default ${JSON.stringify(icons, undefined, "\t")}`;
}
}
});
config.input = input;
return config;
};
12 changes: 12 additions & 0 deletions packages/survey-core/rollup.themes.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const defaultConfig = require("./rollup.config");
const path = require("path");
const input = { index: path.resolve(__dirname, "./src/themes/index.ts") };
module.exports = () => {
let options = {
dir: path.resolve(__dirname, "./build/fesm/themes"),
tsconfig: path.resolve(__dirname, "./tsconfig.themes.json")
};
const config = defaultConfig(options);
config.input = input;
return config;
};
4 changes: 4 additions & 0 deletions packages/survey-core/src/iconsV1-es.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
import icons from "iconsV1";
export { icons };
4 changes: 4 additions & 0 deletions packages/survey-core/src/iconsV2-es.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
import icons from "iconsV2";
export { icons };
2 changes: 2 additions & 0 deletions packages/survey-core/tsconfig.icons.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"include": [
"./src/iconsV1.ts",
"./src/iconsV2.ts",
"./src/iconsV1-es.ts",
"./src/iconsV2-es.ts",
],
"exclude": [],
}
22 changes: 0 additions & 22 deletions packages/survey-core/webpack.fesm.config.mjs

This file was deleted.

22 changes: 0 additions & 22 deletions packages/survey-core/webpack.i18n.fesm.config.mjs

This file was deleted.

18 changes: 0 additions & 18 deletions packages/survey-core/webpack.icons.fesm.config.mjs

This file was deleted.

22 changes: 0 additions & 22 deletions packages/survey-core/webpack.themes.fesm.config.mjs

This file was deleted.

9 changes: 7 additions & 2 deletions packages/survey-react-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"url": "https://github.com/surveyjs/surveyjs.git"
},
"scripts": {
"build": "webpack --env buildType=dev --env emitDeclarations --env emitNonSourceFiles && webpack --env buildType=prod && webpack --config ./webpack.fesm.config.mjs --env buildType=prod",
"watch:dev": "concurrently \"webpack --env buildType=dev --watch --env emitDeclarations\" \"webpack --config ./webpack.fesm.config.mjs --env buildType=prod --watch\" ",
"build": "webpack --env buildType=dev --env emitDeclarations --env emitNonSourceFiles && webpack --env buildType=prod && rollup -c",
"watch:dev": "concurrently \"webpack --env buildType=dev --watch --env emitDeclarations\" \"rollup -c -w\" ",
"start": "webpack-dev-server --env buildType=dev --open",
"test": "karma start ./karma.conf.js --single-run",
"test:watch": "karma start ./karma.conf.js",
Expand All @@ -35,6 +35,9 @@
},
"typings": "./typings/src/entries/react-ui.d.ts",
"devDependencies": {
"@rollup/plugin-node-resolve": "^16.0.0",
"@rollup/plugin-replace": "^6.0.2",
"@rollup/plugin-typescript": "^12.1.2",
"@types/qunit": "2.0.31",
"@types/node": "7.0.4",
"@types/react": "^17.0.83",
Expand All @@ -51,6 +54,8 @@
"react-dom": "^17.0.1",
"react-test-renderer": "^17.0.1",
"rimraf": "2.5.4",
"rollup": "^4.34.8",
"rollup-plugin-license": "^3.6.0",
"sass": "^1.62.1",
"sass-loader": "^8.0.2",
"commit-and-tag-version": "^11.0.0",
Expand Down
Loading

0 comments on commit 9cd581d

Please sign in to comment.