Skip to content

Commit

Permalink
Docs: Using this library as typescript module
Browse files Browse the repository at this point in the history
  * also test that it works well with `isolatedModules`
  • Loading branch information
literat committed Mar 23, 2022
1 parent 6992c94 commit 02cdd2c
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/webpack-with-typescript/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bundle.js
yarn.lock
index.js
18 changes: 18 additions & 0 deletions examples/webpack-with-typescript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Webpack with Typescript module

This example shows how to integrate LMC Cookie Consent Manager with Webpack via ESM module using Typescript.

## How to use

Execute [npm][npm] or [Yarn][yarn] to bootstrap the example:

```shell
npm install
# or
yarn
```

Then run the `build` script and open `index.html` in your browser.

[npm]:https://docs.npmjs.com/cli/init
[yarn]:https://yarnpkg.com/lang/en/docs/cli/create/
20 changes: 20 additions & 0 deletions examples/webpack-with-typescript/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>

<title>Cookie Consent Manager – module example</title>
<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap">

<link rel="stylesheet" href="../../dist/LmcCookieConsentManager.min.css"><!-- You will load this from CDN instead -->

</head>
<body>
<h1>LMC Cookie Consent Manager</h1>
<script defer src="./bundle.js"></script>
</body>
</html>
15 changes: 15 additions & 0 deletions examples/webpack-with-typescript/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// eslint-disable-next-line import/no-unresolved
import LmcCookieConsentManager, { DisplayMode } from '@lmc-eu/cookie-consent-manager';

const ccmArgs = {
displayMode: DisplayMode.SOFT,
config: {
cookie_name: 'lmc_ccm_example',
cookie_domain: 'example.com',
cookie_necessary_only_expiration: 30,
}
};

window.addEventListener('DOMContentLoaded', () => {
LmcCookieConsentManager('example', ccmArgs);
});
18 changes: 18 additions & 0 deletions examples/webpack-with-typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "@lmc-eu/cookie-consent-manager-example-typescript",
"version": "1.0.0",
"license": "MIT",
"devDependencies": {
"ts-loader": "^9.2.8",
"typescript": "^4.6.2",
"webpack": "^5.63.0",
"webpack-cli": "^4.9.1"
},
"dependencies": {
"@lmc-eu/cookie-consent-manager": "../../dist"
},
"scripts": {
"build": "webpack build --config ./webpack.config.js",
"types": "tsc -p ./tsconfig.json"
}
}
18 changes: 18 additions & 0 deletions examples/webpack-with-typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"outDir": "./",
"noImplicitAny": true,
"module": "es6",
"target": "es5",
"jsx": "react",
"allowJs": true,
"moduleResolution": "node",
"isolatedModules": true
},
"include": [
"./index.ts"
],
"exclude": [
"./bundle.js"
],
}
21 changes: 21 additions & 0 deletions examples/webpack-with-typescript/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const path = require('path');

module.exports = {
entry: './index.ts',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
output: {
path: path.resolve(__dirname, './'),
filename: 'bundle.js',
},
};

0 comments on commit 02cdd2c

Please sign in to comment.