Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit 3099042

Browse filesBrowse files
committed
Add nuxt2 build module
1 parent 8ce4c60 commit 3099042
Copy full SHA for 3099042

File tree

Expand file treeCollapse file tree

5 files changed

+223
-1
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+223
-1
lines changed

‎LICENSE

Copy file name to clipboardExpand all lines: LICENSE
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021 fluent-vue
3+
Copyright 2021 Ivan Demchuk <ivan.demchuk@gmail.com>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

‎README.md

Copy file name to clipboard
+31Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# @fluent-vue/nuxt2-build-module
2+
3+
This is [fluent-vue](https://github.com/demivan/fluent-vue) build module for Nuxt 2.
4+
5+
## What does it do?
6+
7+
* Adds a `fluent-vue-loader` to support `<fluent>` custom blocks in SFC files
8+
* Adds a `raw-loader` to handle `.ftl` files
9+
* Enables SSR support for `v-t` directive
10+
11+
> NOTE: When using v-t directive with v-bind directive, make sure to write v-t directive second. v-bind will clear all attributes added by v-t directive otherwise. This is a limitation of Vue 2 compiler.
12+
13+
## Instalation
14+
15+
Add this module to your dev dependencies:
16+
17+
```sh
18+
pnpm add @fluent-vue/nuxt2-build-module -D
19+
```
20+
21+
Add build module to your Nuxt 2 config.
22+
23+
```js
24+
{
25+
// ...
26+
buildModules: [
27+
'@fluent-vue/nuxt2-build-module'
28+
],
29+
// ...
30+
}
31+
```

‎lib/index.js

Copy file name to clipboard
+65Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copied from https://github.com/vuejs/vue/blob/0603ff695d2f41286239298210113cbe2b209e28/src/compiler/helpers.js
2+
function addProp (el, name, value, range) {
3+
(el.props || (el.props = [])).push(rangeSetItem({ name, value }, range))
4+
el.plain = false
5+
}
6+
7+
function rangeSetItem (item, range) {
8+
if (range) {
9+
if (range.start != null) {
10+
item.start = range.start
11+
}
12+
if (range.end != null) {
13+
item.end = range.end
14+
}
15+
}
16+
return item
17+
}
18+
19+
// TODO: Extract to a separate package
20+
const vtDirective = function (el, dir) {
21+
// Preserve data from v-bind directive
22+
const previousWrapData = el.wrapData
23+
el.wrapData = (code) => {
24+
if (previousWrapData) {
25+
code = previousWrapData(code)
26+
}
27+
28+
return `_b(${code},'${el.tag}',$ta('${dir.arg}'),false)`
29+
}
30+
31+
addProp(el, 'textContent', `_s($t('${dir.arg}'))`, dir)
32+
}
33+
34+
export default function FluentVueModule () {
35+
this.extendBuild(config => {
36+
config.module = config.module || { rules: [] }
37+
38+
// Allow importing ftl files as strings
39+
config.module.rules.push({
40+
test: /\.ftl$/,
41+
loader: require.resolve('raw-loader')
42+
})
43+
44+
// Add support for SFC custom blocks
45+
config.module.rules.push({
46+
resourceQuery: /blockType=fluent/,
47+
type: 'javascript/auto',
48+
loader: require.resolve('fluent-vue-loader')
49+
})
50+
51+
const vueRule = config.module.rules.find(rule => rule.loader?.toString().includes('vue-loader'))
52+
53+
if (!vueRule) {
54+
console.error('Could not find vue-loader rule in Webpack config')
55+
return
56+
}
57+
58+
vueRule.options = vueRule.options || {}
59+
vueRule.options.compilerOptions = options.compilerOptions || {}
60+
vueRule.options.compilerOptions.directives = vueRule.options.compilerOptions.directives || {}
61+
vueRule.options.compilerOptions.directives.t = vtDirective
62+
})
63+
}
64+
65+
module.exports.meta = require('../package.json')

‎package.json

Copy file name to clipboard
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "@fluent-vue/nuxt2-build-module",
3+
"version": "0.0.1",
4+
"description": "Nuxt build module for fluent-vue",
5+
"scripts": {
6+
},
7+
"files": [
8+
"lib",
9+
"README.md"
10+
],
11+
"main": "lib/index.js",
12+
"dependencies": {
13+
"fluent-vue-loader": "^3.0.0",
14+
"raw-loader": "^4.0.2"
15+
}
16+
}

‎pnpm-lock.yaml

Copy file name to clipboardExpand all lines: pnpm-lock.yaml
+110Lines changed: 110 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.