Skip to content

Commit 0565f7d

Browse files
authored
Implement esm modules for creator-js package (#6674)
1 parent 80f2060 commit 0565f7d

File tree

4 files changed

+99
-9
lines changed

4 files changed

+99
-9
lines changed

packages/survey-creator-js/package.json

+11-5
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,16 @@
3030
"visual-regression-tests:file": "testcafe --app \"http-server\" ../../visualRegressionTests/tests/designer/pg-editors.ts --screenshots ../../ --reporter minimal --selector-timeout 1500 --config-file .testcaferc.dev.js",
3131
"release": "standard-version --message \"Release: %s [azurepipelines skip]\"",
3232
"remove-package-lock": "rimraf package-lock.json",
33-
"build": "webpack --env buildType=dev && webpack --env buildType=prod",
34-
"watch:dev": "webpack --env buildType=dev --watch",
33+
"build": "webpack --env buildType=dev && webpack --env buildType=prod && rollup -c",
34+
"watch:dev": "webpack --env buildType=dev --watch && rollup -c -w",
3535
"watch:prod": "webpack --env buildType=prod --watch",
3636
"lint": "eslint ./src"
3737
},
3838
"devDependencies": {
39+
"@rollup/plugin-alias": "^5.1.1",
40+
"@rollup/plugin-node-resolve": "^16.0.0",
41+
"@rollup/plugin-replace": "^6.0.2",
42+
"@rollup/plugin-typescript": "^12.1.2",
3943
"@types/ace": "0.0.44",
4044
"@types/jest": "^26.0.24",
4145
"@types/jquery": "3.3.29",
@@ -51,6 +55,8 @@
5155
"jest-environment-jsdom": "^29.7.0",
5256
"mini-css-extract-plugin": "^2.9.0",
5357
"rimraf": "2.5.4",
58+
"rollup": "^4.34.8",
59+
"rollup-plugin-license": "^3.6.0",
5460
"sass": "^1.62.1",
5561
"sass-loader": "^8.0.2",
5662
"standard-version": "^9.5.0",
@@ -65,7 +71,7 @@
6571
},
6672
"dependencies": {
6773
"survey-core": "../../../survey-library/packages/survey-core/build",
68-
"survey-js-ui": "../../../survey-library/packages/survey-js-ui/build",
69-
"survey-creator-core": "../survey-creator-core/build"
74+
"survey-creator-core": "../survey-creator-core/build",
75+
"survey-js-ui": "../../../survey-library/packages/survey-js-ui/build"
7076
}
71-
}
77+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
const typescript = require("@rollup/plugin-typescript");
2+
const nodeResolve = require("@rollup/plugin-node-resolve");
3+
const replace = require("@rollup/plugin-replace");
4+
const alias = require("@rollup/plugin-alias");
5+
const bannerPlugin = require("rollup-plugin-license");
6+
const path = require("path");
7+
const VERSION = require("./package.json").version;
8+
9+
const banner = [
10+
"SurveyJS Creator UI v" + VERSION,
11+
"(c) 2015-" + new Date().getFullYear() + " Devsoft Baltic OÜ - http://surveyjs.io/",
12+
"Github: https://github.com/surveyjs/survey-creator",
13+
"License: https://surveyjs.io/Licenses#SurveyCreator"
14+
].join("\n");
15+
16+
const input = { "survey-creator-js": path.resolve(__dirname, "./entries/index.ts") };
17+
module.exports = (options) => {
18+
options = options ?? {};
19+
if(!options.tsconfig) {
20+
options.tsconfig = path.resolve(__dirname, "./tsconfig.fesm.json");
21+
}
22+
if(!options.dir) {
23+
options.dir = path.resolve(__dirname, "./build/fesm");
24+
}
25+
return {
26+
input,
27+
context: "this",
28+
29+
plugins: [
30+
alias({
31+
entries: {
32+
"survey-react-ui": "survey-js-ui",
33+
"react": "survey-js-ui",
34+
"react-dom/test-utils": "survey-js-ui",
35+
"react-dom": "survey-js-ui",
36+
"react/jsx-runtime": "survey-js-ui"
37+
}
38+
}),
39+
nodeResolve(),
40+
typescript({
41+
filterRoot: false,
42+
inlineSources: true,
43+
sourceMap: true, tsconfig: options.tsconfig,
44+
compilerOptions: {
45+
declaration: false,
46+
declarationDir: null
47+
}
48+
}),
49+
replace({
50+
preventAssignment: false,
51+
values: {
52+
"process.env.RELEASE_DATE": JSON.stringify(new Date().toISOString().slice(0, 10)),
53+
"process.env.VERSION": JSON.stringify(VERSION),
54+
}
55+
}),
56+
bannerPlugin({
57+
banner: {
58+
content: banner,
59+
commentStyle: "ignored",
60+
}
61+
})
62+
],
63+
external: [
64+
"survey-core",
65+
"survey-creator-core",
66+
"survey-js-ui"
67+
],
68+
output: [
69+
{
70+
dir: options.dir,
71+
format: "esm",
72+
exports: "named",
73+
sourcemap: true,
74+
},
75+
],
76+
};
77+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"target": "ES6"
5+
}
6+
}

packages/survey-creator-js/webpack.config.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const buildPlatformJson = {
3737
"**/*"
3838
],
3939
main: packageJson.name + ".js",
40+
module: "fesm/survey-creator-js.js",
4041
repository: {
4142
type: "git",
4243
url: "https://github.com/surveyjs/survey-creator.git"
@@ -125,7 +126,7 @@ module.exports = function (options) {
125126
},
126127
{
127128
test: /\.html$/,
128-
exclude: [/node_modules/, require.resolve('./index.html')],
129+
exclude: [/node_modules/, require.resolve("./index.html")],
129130
loader: "html-loader"
130131
},
131132
{
@@ -142,8 +143,8 @@ module.exports = function (options) {
142143
filename: "[name]" + (isProductionBuild ? ".min" : "") + ".js",
143144
library: {
144145
root: options.libraryName || "SurveyCreator",
145-
amd: '[dashedname]',
146-
commonjs: '[dashedname]',
146+
amd: "[dashedname]",
147+
commonjs: "[dashedname]",
147148
},
148149
libraryTarget: "umd",
149150
globalObject: "this",
@@ -223,7 +224,7 @@ module.exports = function (options) {
223224
]);
224225
config.devServer = {
225226
static: {
226-
directory: path.join(__dirname, '.'),
227+
directory: path.join(__dirname, "."),
227228
},
228229
//host: "0.0.0.0",
229230
compress: false,

0 commit comments

Comments
 (0)