Skip to content

Commit 7faad91

Browse files
ComLockalansemenov
authored andcommitted
wip #1817 jquery problems
1 parent e452883 commit 7faad91

File tree

4 files changed

+48
-10
lines changed

4 files changed

+48
-10
lines changed

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
},
2828
"devDependencies": {
2929
"@enonic/eslint-config": "^1.2.0",
30+
"@fal-works/esbuild-plugin-global-externals": "^2.1.2",
3031
"@swc/core": "^1.3.93",
3132
"@types/hasher": "^0.0.33",
3233
"@types/nanoid": "^3.0.0",
@@ -42,6 +43,8 @@
4243
"cssnano": "^6.0.1",
4344
"enonic-admin-artifacts": "^1.8.5",
4445
"eslint": "^8.51.0",
46+
"esbuild-plugin-external-global": "^1.0.1",
47+
"esbuild-plugin-globals": "^0.2.0",
4548
"less": "^4.2.0",
4649
"less-loader": "^11.1.3",
4750
"mini-css-extract-plugin": "^2.7.6",

postcss.config.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ const plugins = Object.assign(
1010
'postcss-url': {
1111
basePath: path.resolve('src/main/resources/assets/icons'),
1212
assetsPath: '../icons/',
13-
url: 'copy' // Remember to skip woff and woff2 files in build.gradle
14-
// url: 'inline' // base64 data url inlines the fonts?
15-
// url: 'rebase' // only manipulates the urls?
13+
url: 'copy'
1614
},
1715
},
1816
isProd ? {cssnano: {}} : {}

src/main/resources/admin/tools/main/main.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@
3838
</head>
3939
<body>
4040

41-
<!-- App javascript -->
42-
<script type="text/javascript" src="{{assetsUri}}/js/bundle.js" data-config-service-url="{{configServiceUrl}}"></script>
43-
4441
<!-- Append the launcher -->
4542
<script type="text/javascript" src="{{launcherPath}}" data-config-theme="dark" async></script>
4643

44+
<!-- App javascript -->
45+
<script defer type="text/javascript" src="{{assetsUri}}/js/app-users-bundle.js" data-config-service-url="{{configServiceUrl}}"></script>
46+
4747
</body>
4848
</html>

tsup.config.ts

+41-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,58 @@
1+
import { globalExternals } from "@fal-works/esbuild-plugin-global-externals";
2+
// import GlobalsPlugin from "esbuild-plugin-globals";
13
import { defineConfig } from 'tsup';
4+
// import externalGlobalPlugin from 'esbuild-plugin-external-global';
25

36
export default defineConfig(() => {
47
return {
8+
bundle: true,
59
dts: false, // d.ts files are use useless at runtime
610
entry: {
7-
'js/bundle': 'src/main/resources/assets/js/main.ts',
11+
'js/app-users-bundle': 'src/main/resources/assets/js/main.ts',
812
'js/crypto-worker': 'src/main/resources/assets/js/worker/RSAKeysWorker.ts',
913
},
14+
// esbuildOptions(options, context) {
15+
// options.external = [
16+
// 'jquery'
17+
// ]
18+
// },
19+
esbuildPlugins: [
20+
// GlobalsPlugin({
21+
// // 'jquery': 'jQuery',
22+
// 'jquery': '$'
23+
// }),
24+
globalExternals({
25+
'jquery': '$'
26+
// 'jquery': 'jQuery'
27+
})
28+
// externalGlobalPlugin({
29+
// // 'react': 'window.React',
30+
// // 'react-dom': 'window.ReactDOM',
31+
// 'jQuery': '$' // It seems jquery is available as $ in the global scope
32+
// })
33+
],
34+
// external: [
35+
// // This will leave require('jquery') as is in the bundle
36+
// // causes: Uncaught ReferenceError: require is not defined
37+
// 'jquery'
38+
// ],
1039
format: [
1140
'cjs'
1241
],
13-
minify: process.env.NODE_ENV === 'development' ? false : true,
42+
minify: process.env.NODE_ENV !== 'development',
43+
noExternal: [ // Same as dependencies in package.json
44+
/@enonic\/lib-admin-ui/,
45+
'hasher',
46+
'jquery', // This will bundle jQuery into the bundle
47+
'nanoid',
48+
'owasp-password-strength-test',
49+
'q'
50+
],
1451
outDir: 'build/resources/main/assets',
1552
platform: 'browser',
16-
silent: ['QUIET', 'WARN'].includes(process.env.LOG_LEVEL_FROM_GRADLE||''),
53+
silent: ['QUIET', 'WARN'].includes(process.env.LOG_LEVEL_FROM_GRADLE||''),
1754
// splitting: false,
18-
sourcemap: process.env.NODE_ENV === 'development' ? true : false,
55+
sourcemap: process.env.NODE_ENV === 'development',
1956
tsconfig: 'src/main/resources/assets/tsconfig.json',
2057
};
2158
});

0 commit comments

Comments
 (0)