Skip to content

Commit d1459eb

Browse files
fix(lib): Generate a module version of the library to be used as import in a devlopment source
1 parent 768c42c commit d1459eb

9 files changed

+91
-43
lines changed

package-lock.json

+35-19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"files": [
99
"./dist/**/*"
1010
],
11-
"main": "./dist/ods-charts.js",
11+
"type": "module",
12+
"main": "./dist/ods-charts-module.js",
1213
"types": "./dist/ods-charts.d.js",
1314
"scripts": {
1415
"build": "webpack",
@@ -29,5 +30,8 @@
2930
"typescript": "^5.3.3",
3031
"webpack": "^5.89.0",
3132
"webpack-cli": "^5.1.4"
33+
},
34+
"dependencies": {
35+
"@types/echarts": "^4.9.22"
3236
}
3337
}

test/angular-tour-of-heroes/package-lock.json

+4-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/react/package-lock.json

+7-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/react/src/LineChartComponent.js

-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ class LineChartComponent extends Component {
6161
});
6262

6363
console.log('>>', ODSCharts);
64-
console.log('>>', ODSCharts.theme);
6564
console.log(lineChartODSTheme);
6665

6766
echarts.registerTheme(lineChartODSTheme.name, lineChartODSTheme.theme);

test/vue/package-lock.json

+4-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/vue/src/components/LineChartComponent.vue

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ onMounted(() => {
5656
})
5757
5858
console.log('>>', ODSCharts)
59-
console.log('>>', ODSCharts.theme)
6059
console.log(lineChartODSTheme)
6160
6261
echarts.registerTheme(lineChartODSTheme.name, lineChartODSTheme.theme)

tsconfig.json

+3-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
2727

2828
/* Modules */
29-
"module": "commonjs" /* Specify what module code is generated. */,
29+
"module": "ESNext" /* Specify what module code is generated. */,
3030
// "rootDir": "./", /* Specify the root folder within your source files. */
3131
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
3232
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
@@ -40,7 +40,7 @@
4040
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
4141
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
4242
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
43-
"resolveJsonModule": true /* Enable importing .json files. */,
43+
// "resolveJsonModule": true /* Enable importing .json files. */,
4444
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
4545
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
4646

@@ -107,7 +107,5 @@
107107
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
108108
"skipLibCheck": true /* Skip type checking all .d.ts files. */
109109
},
110-
"exclude": [
111-
"./test/"
112-
]
110+
"exclude": ["./test/"]
113111
}

webpack.config.js

+33-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
const path = require('path');
1+
import path from 'node:path';
2+
import { fileURLToPath } from 'node:url';
23

3-
module.exports = {
4+
const __filename = fileURLToPath(import.meta.url);
5+
const __dirname = path.dirname(__filename);
6+
7+
const defaultConfig = {
48
mode: 'development',
59
devtool: 'inline-source-map',
610
entry: {
711
main: './index.ts',
812
},
9-
output: {
10-
path: path.resolve(__dirname, './dist'),
11-
filename: 'ods-charts.js',
12-
libraryTarget: 'umd',
13-
library: 'ODSCharts',
14-
},
1513
resolve: {
1614
extensions: ['.ts', '.tsx', '.js'],
1715
},
@@ -24,3 +22,30 @@ module.exports = {
2422
],
2523
},
2624
};
25+
26+
export default [
27+
{
28+
...defaultConfig,
29+
output: {
30+
path: path.resolve(__dirname, './dist'),
31+
filename: 'ods-charts.js',
32+
library: {
33+
type: 'umd',
34+
name: 'ODSCharts',
35+
},
36+
},
37+
},
38+
{
39+
...defaultConfig,
40+
output: {
41+
path: path.resolve(__dirname, './dist'),
42+
filename: 'ods-charts-module.js',
43+
library: {
44+
type: 'module',
45+
},
46+
},
47+
experiments: {
48+
outputModule: true,
49+
},
50+
},
51+
];

0 commit comments

Comments
 (0)