Skip to content

Commit 859e582

Browse files
committed
Add example
1 parent d3d3ad2 commit 859e582

File tree

5 files changed

+69
-0
lines changed

5 files changed

+69
-0
lines changed

example/dist/index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8"/>
5+
<title>Getting Started</title>
6+
</head>
7+
<body>
8+
<script src="bundle.js"></script>
9+
</body>
10+
</html>

example/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "messageformat-properties-loader-example",
3+
"version": "0.1.0",
4+
"description": "Minimal example for messageformat-properties-loader",
5+
"private": true,
6+
"scripts": {
7+
"build": "webpack",
8+
"prepare": "npm run build"
9+
},
10+
"main": "src/index.js",
11+
"repository": "https://github.com/messageformat/properties-loader",
12+
"author": "Eemeli Aro <[email protected]>",
13+
"license": "MIT",
14+
"devDependencies": {
15+
"messageformat-properties-loader": "file:../",
16+
"webpack": "^3.11.0"
17+
}
18+
}

example/src/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import messages from './messages.properties'
2+
const { format, messages: errors } = messages.errors
3+
4+
function component() {
5+
const element = document.createElement('div')
6+
element.innerHTML = format([
7+
'Your message',
8+
errors.wrong_length({ count: 42 })
9+
])
10+
return element
11+
}
12+
13+
console.log('messages', messages)
14+
document.body.appendChild(component())

example/src/messages.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
errors.format: {0} {1}
2+
errors.messages.confirmation: doesn't match {attribute}
3+
errors.messages.accepted: must be accepted
4+
errors.messages.wrong_length: is the wrong length (should be {count, plural, one{1 character} other{# characters}})
5+
errors.messages.equal_to: must be equal to {count}

example/webpack.config.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const path = require('path')
2+
3+
module.exports = {
4+
entry: './src/index.js',
5+
output: {
6+
filename: 'bundle.js',
7+
path: path.resolve(__dirname, 'dist')
8+
},
9+
module: {
10+
rules: [
11+
{
12+
test: /\.properties$/,
13+
loader: require.resolve('messageformat-properties-loader'),
14+
options: {
15+
biDiSupport: false,
16+
locales: 'en',
17+
path: true
18+
}
19+
}
20+
]
21+
}
22+
}

0 commit comments

Comments
 (0)