Skip to content

Commit e91e7b5

Browse files
committed
Use webpack-dev-server for test app
1 parent d18fa59 commit e91e7b5

File tree

10 files changed

+2415
-581
lines changed

10 files changed

+2415
-581
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Uses [Window.getComputedStyle](https://developer.mozilla.org/en-US/docs/Web/API/
99
Install the package via npm:
1010

1111
```sh
12-
$ npm install computed-style-to-inline-style
12+
npm install computed-style-to-inline-style
1313
```
1414

1515
Or download it from the unpkg CDN:

package-lock.json

Lines changed: 2337 additions & 520 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
],
1313
"scripts": {
1414
"build": "webpack --mode production",
15-
"test": "electron test/main.js",
16-
"pretest": "npm run build"
15+
"test": "webpack serve --mode development --config ./test/webpack.config.js"
1716
},
1817
"dependencies": {},
1918
"devDependencies": {
20-
"electron": "^26.1.0",
19+
"html-webpack-plugin": "^5.5.0",
2120
"ts-loader": "^9.4.1",
2221
"typescript": "^5.1.6",
2322
"webpack": "^5.75.0",
24-
"webpack-cli": "^4.10.0"
23+
"webpack-cli": "^4.10.0",
24+
"webpack-dev-server": "^4.11.1"
2525
},
2626
"keywords": [
2727
"css",

test/index.html

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
<!DOCTYPE html>
2-
<html>
2+
<html lang="en">
33
<head>
44
<meta charset="utf-8" />
5-
<meta
6-
http-equiv="Content-Security-Policy"
7-
content="script-src 'unsafe-inline'; style-src 'unsafe-inline';"
8-
/>
5+
<title>computed-style-to-inline-style</title>
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
97
<style>
108
html,
119
body {
@@ -26,20 +24,5 @@
2624
}
2725
</style>
2826
</head>
29-
<body>
30-
<h1 style="color: #aaa">Hello, <span>World!</span></h1>
31-
<button type="button">Test</button>
32-
<script>
33-
document.querySelector('button').addEventListener(
34-
'click',
35-
() => {
36-
window.computedStyleToInlineStyle(document.querySelector('h1'), {
37-
recursive: true,
38-
properties: ['font-size', 'text-decoration'],
39-
});
40-
},
41-
false
42-
);
43-
</script>
44-
</body>
27+
<body></body>
4528
</html>

test/index.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import computedStyleToInlineStyle from '../lib';
2+
3+
const h1 = document.createElement('h1');
4+
h1.style.color = '#aaa';
5+
document.body.appendChild(h1);
6+
7+
const textStart = document.createTextNode('Hello, ');
8+
h1.appendChild(textStart);
9+
10+
const span = document.createElement('span');
11+
span.textContent = 'World';
12+
h1.appendChild(span);
13+
14+
const textEnd = document.createTextNode('!');
15+
h1.appendChild(textEnd);
16+
17+
const button = document.createElement('button');
18+
button.type = 'button';
19+
button.textContent = 'Test';
20+
button.addEventListener('click', () => {
21+
computedStyleToInlineStyle(h1, {
22+
recursive: true,
23+
properties: ['font-size', 'text-decoration'],
24+
});
25+
});
26+
document.body.appendChild(button);

test/main.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

test/preload.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

test/tsconfig.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"declaration": false
5+
}
6+
}

test/webpack.config.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const path = require('path');
2+
const webpack = require('webpack');
3+
const HtmlWebpackPlugin = require('html-webpack-plugin');
4+
5+
/** @type { webpack.Configuration } */
6+
module.exports = {
7+
devServer: {
8+
port: 9000,
9+
open: true,
10+
hot: false,
11+
client: {
12+
logging: 'warn',
13+
},
14+
},
15+
entry: path.join(__dirname, 'index.ts'),
16+
resolve: {
17+
extensions: ['.ts', '...'],
18+
},
19+
module: {
20+
rules: [
21+
{
22+
test: /\.ts$/,
23+
loader: 'ts-loader',
24+
exclude: /node_modules/,
25+
options: {
26+
onlyCompileBundledFiles: true,
27+
},
28+
},
29+
],
30+
},
31+
plugins: [
32+
new HtmlWebpackPlugin({
33+
template: path.join(__dirname, 'index.html'),
34+
}),
35+
],
36+
};

tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@
77
"noEmitOnError": true,
88
"declaration": true
99
},
10-
"include": ["lib"],
11-
"exclude": ["node_modules"]
10+
"include": ["lib"]
1211
}

0 commit comments

Comments
 (0)