Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lib): Generate a module version of the library to be used as import in a devlopment source #46

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
54 changes: 35 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"./dist/**/*"
],
"main": "./dist/ods-charts.js",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main file here should remain dist/ods-charts.js because this would be the default packaged version. The module version shouldn't be the default one.

For example, in Bootstrap:

"main": "dist/js/bootstrap.js",
"module": "dist/js/bootstrap.esm.js",

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I test this solution (with the changes in webpack.config.js as well of course), and i got back the angular compilation errors :

./src/app/graph/graph.component.ts:44:21-46 - Error: export 'getThemeManager' (imported as 'ODSCharts') was not found in 'ods-charts' (module has no exports)
./src/app/graph/graph.component.ts:45:14-43 - Error: export 'ODSChartsMode' (imported as 'ODSCharts') was not found in 'ods-charts' (module has no exports)
./src/app/graph/graph.component.ts:46:27-79 - Error: export 'ODSChartsCategoricalColorsSet' (imported as 'ODSCharts') was not found in 'ods-charts' (module has no exports)
./src/app/graph/graph.component.ts:47:24-78 - Error: export 'ODSChartsSequentialColorsSet' (imported as 'ODSCharts') was not found in 'ods-charts' (module has no exports)
./src/app/graph/graph.component.ts:48:19-54 - Error: export 'ODSChartsLineStyle' (imported as 'ODSCharts') was not found in 'ods-charts' (module has no exports)

NB : to update the angular projet before testing, I do

npm uninstall ods-charts
npm i ../..

"module": "./dist/ods-charts.esm.js",
"types": "./dist/ods-charts.d.js",
"scripts": {
"build": "webpack",
Expand All @@ -28,6 +29,7 @@
"typedoc": "^0.25.4",
"typescript": "^5.3.3",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4"
"webpack-cli": "^5.1.4",
"@types/echarts": "^4.9.22"
julien-deramond marked this conversation as resolved.
Show resolved Hide resolved
}
}
3 changes: 2 additions & 1 deletion test/angular-ngx-echarts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion test/angular-tour-of-heroes/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions test/react/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion test/react/src/LineChartComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class LineChartComponent extends Component {
});

console.log('>>', ODSCharts);
console.log('>>', ODSCharts.theme);
console.log(lineChartODSTheme);

echarts.registerTheme(lineChartODSTheme.name, lineChartODSTheme.theme);
Expand Down
6 changes: 4 additions & 2 deletions test/vue/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion test/vue/src/components/LineChartComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ onMounted(() => {
})

console.log('>>', ODSCharts)
console.log('>>', ODSCharts.theme)
console.log(lineChartODSTheme)

echarts.registerTheme(lineChartODSTheme.name, lineChartODSTheme.theme)
Expand Down
8 changes: 3 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */

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

Expand Down Expand Up @@ -107,7 +107,5 @@
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
},
"exclude": [
"./test/"
]
"exclude": ["./test/"]
}
35 changes: 28 additions & 7 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
const path = require('path');

module.exports = {
const defaultConfig = {
mode: 'development',
devtool: 'inline-source-map',
entry: {
main: './index.ts',
},
output: {
path: path.resolve(__dirname, './dist'),
filename: 'ods-charts.js',
libraryTarget: 'umd',
library: 'ODSCharts',
},
resolve: {
extensions: ['.ts', '.tsx', '.js'],
},
Expand All @@ -24,3 +18,30 @@ module.exports = {
],
},
};

module.exports = [
{
...defaultConfig,
output: {
path: path.resolve(__dirname, './dist'),
filename: 'ods-charts.js',
library: {
type: 'umd',
name: 'ODSCharts',
},
},
},
{
...defaultConfig,
output: {
path: path.resolve(__dirname, './dist'),
filename: 'ods-charts.esm.js',
library: {
type: 'module',
},
},
experiments: {
outputModule: true,
},
},
];