File tree Expand file tree Collapse file tree 5 files changed +80
-1
lines changed Expand file tree Collapse file tree 5 files changed +80
-1
lines changed Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " custom-block" ,
3
+ "version" : " 0.0.0" ,
4
+ "private" : true ,
5
+ "scripts" : {
6
+ "build" : " rollup -c"
7
+ },
8
+ "dependencies" : {
9
+ "rollup" : " ^2.10.9" ,
10
+ "rollup-pluginutils" : " ^2.8.2" ,
11
+ "rollup-plugin-vue" : " link:../.."
12
+ }
13
+ }
Original file line number Diff line number Diff line change
1
+ import VuePlugin from 'rollup-plugin-vue'
2
+ import { createFilter } from 'rollup-pluginutils'
3
+
4
+ export default [
5
+ {
6
+ input : 'src/App.vue' ,
7
+ output : {
8
+ file : 'dist/app.js' ,
9
+ format : 'esm' ,
10
+ sourcemap : 'inline' ,
11
+ } ,
12
+ plugins : [ VuePlugin ( { customBlocks : [ 'i18n' ] } ) , VueI18N ( ) ] ,
13
+ external : [ 'vue' ] ,
14
+ } ,
15
+ ]
16
+
17
+ function VueI18N ( ) {
18
+ const filter = createFilter ( [ / v u e & t y p e = i 1 8 n / ] )
19
+
20
+ return {
21
+ transform ( code , id ) {
22
+ if ( filter ( id ) ) {
23
+ return {
24
+ code : `
25
+ export default function i18n(component) {
26
+ component.i18n = ${ JSON . stringify ( JSON . parse ( code . trim ( ) ) ) }
27
+ }` ,
28
+ map : null ,
29
+ }
30
+ }
31
+ } ,
32
+ }
33
+ }
Original file line number Diff line number Diff line change
1
+ <script >
2
+ export default {
3
+ name: ' App' ,
4
+ }
5
+ </script >
6
+
7
+ <template >
8
+ <h1 >{{ $t('say.hello', { name: 'Rahul' }) }}</h1 >
9
+ </template >
10
+
11
+ <i18n lang="json">
12
+ {
13
+ "say" : {
14
+ "hello" : " Hello :name"
15
+ }
16
+ }
17
+ </i18n >
Original file line number Diff line number Diff line change @@ -112,7 +112,7 @@ export default function PluginVue(userOptions: Partial<Options> = {}): Plugin {
112
112
? descriptor . script !
113
113
: query . type === 'style'
114
114
? descriptor . styles [ query . index ]
115
- : query . type === 'custom '
115
+ : typeof query . index === 'number '
116
116
? descriptor . customBlocks [ query . index ]
117
117
: null
118
118
Original file line number Diff line number Diff line change @@ -12,6 +12,22 @@ describe('simple', () => {
12
12
} )
13
13
} )
14
14
15
+ describe ( 'custom-block' , ( ) => {
16
+ let result ! : RollupOutput
17
+
18
+ beforeAll ( async ( ) => {
19
+ result = await roll ( 'custom-block' )
20
+ } )
21
+
22
+ it ( 'should compile <i18n>' , ( ) => {
23
+ expect ( result . output [ 0 ] . code ) . toEqual (
24
+ expect . stringContaining (
25
+ 'component.i18n = {"say":{"hello":"Hello :name"}}'
26
+ )
27
+ )
28
+ } )
29
+ } )
30
+
15
31
describe ( 'css-modules' , ( ) => {
16
32
let result ! : RollupOutput
17
33
You can’t perform that action at this time.
0 commit comments