Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit5fb30ce

Browse files
committed
fix: Use isProduction when defined and fallback to NODE_ENV/BUILD
1 parent911eabc commit5fb30ce

File tree

3 files changed

+38
-25
lines changed

3 files changed

+38
-25
lines changed

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"pre:docs":"cp CHANGELOG.md docs/changelog.md",
3838
":docs":"vuepress dev docs/",
3939
"post:docs":"rm docs/CHANGELOG.md",
40-
"lint":"prettier --no-semi --single-quote --write **/*.js **/*.vue !test/target/** !dist/**",
40+
"lint":"prettier --no-semi --single-quote --write **/*.jssrc/*.ts**/*.vue !test/target/** !dist/**",
4141
"release":"standard-version -a",
4242
"test":"jest"
4343
},

‎src/index.ts

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
parseVuePartRequest,
55
resolveVuePart,
66
isVuePartRequest,
7-
transformRequireToImport,
7+
transformRequireToImport
88
}from'./utils'
99
import{
1010
createDefaultCompiler,
@@ -13,15 +13,15 @@ import {
1313
StyleOptions,
1414
TemplateOptions,
1515
StyleCompileResult,
16-
DescriptorCompileResult,
16+
DescriptorCompileResult
1717
}from'@vue/component-compiler'
1818
import{Plugin,RawSourceMap}from'rollup'
1919
import*aspathfrom'path'
2020
import{parse,SFCDescriptor,SFCBlock}from'@vue/component-compiler-utils'
2121
importdebugfrom'debug'
2222
import{
2323
VueTemplateCompiler,
24-
VueTemplateCompilerParseOptions,
24+
VueTemplateCompilerParseOptions
2525
}from'@vue/component-compiler-utils/dist/types'
2626

2727
consttemplateCompiler=require('vue-template-compiler')
@@ -118,8 +118,11 @@ export interface VuePluginOptions {
118118
*/
119119
exportdefaultfunctionvue(opts:VuePluginOptions={}):Plugin{
120120
constisVue=createVueFilter(opts.include,opts.exclude)
121-
constisProduction=(opts.template&&opts.template.isProduction)||
122-
process.env.NODE_ENV==='production'||process.env.BUILD==='production'
121+
constisProduction=
122+
opts.template&&typeofopts.template.isProduction==='boolean'
123+
?opts.template.isProduction
124+
:process.env.NODE_ENV==='production'||
125+
process.env.BUILD==='production'
123126

124127
d('Version '+version)
125128
d(`Build environment:${isProduction ?'production' :'development'}`)
@@ -128,13 +131,15 @@ export default function vue(opts: VuePluginOptions = {}): Plugin {
128131
if(!opts.normalizer)
129132
opts.normalizer='~'+'vue-runtime-helpers/dist/normalize-component.js'
130133
if(!opts.styleInjector)
131-
opts.styleInjector='~'+'vue-runtime-helpers/dist/inject-style/browser.js'
134+
opts.styleInjector=
135+
'~'+'vue-runtime-helpers/dist/inject-style/browser.js'
132136
if(!opts.styleInjectorSSR)
133-
opts.styleInjectorSSR='~'+'vue-runtime-helpers/dist/inject-style/server.js'
137+
opts.styleInjectorSSR=
138+
'~'+'vue-runtime-helpers/dist/inject-style/server.js'
134139

135140
createVuePartRequest.defaultLang={
136141
...createVuePartRequest.defaultLang,
137-
...opts.defaultLang,
142+
...opts.defaultLang
138143
}
139144

140145
constshouldExtractCss=opts.css===false
@@ -162,9 +167,9 @@ export default function vue(opts: VuePluginOptions = {}): Plugin {
162167
video:['src','poster'],
163168
source:'src',
164169
img:'src',
165-
image:'xlink:href',
170+
image:'xlink:href'
166171
},
167-
...opts.template,
172+
...opts.template
168173
}asany
169174
if(opts.template&&typeofopts.template.isProduction==='undefined'){
170175
opts.template.isProduction=isProduction
@@ -194,7 +199,9 @@ export default function vue(opts: VuePluginOptions = {}): Plugin {
194199
if(src.startsWith('.')){
195200
returnpath.resolve(path.dirname(ref.filename),srcasstring)
196201
}else{
197-
returnrequire.resolve(src,{paths:[path.dirname(ref.filename)]})
202+
returnrequire.resolve(src,{
203+
paths:[path.dirname(ref.filename)]
204+
})
198205
}
199206
}
200207

@@ -230,7 +237,7 @@ export default function vue(opts: VuePluginOptions = {}): Plugin {
230237
compiler:opts.compiler||templateCompiler,
231238
compilerParseOptions:opts.compilerParseOptions,
232239
sourceRoot:opts.sourceRoot,
233-
needMap:true,
240+
needMap:true
234241
})
235242
)
236243
)
@@ -257,7 +264,7 @@ export default function vue(opts: VuePluginOptions = {}): Plugin {
257264
constinput:any={
258265
scopeId,
259266
styles,
260-
customBlocks:[],
267+
customBlocks:[]
261268
}
262269

263270
if(descriptor.template){
@@ -297,7 +304,7 @@ export default function vue(opts: VuePluginOptions = {}): Plugin {
297304
?JSON.stringify(path.basename(filename))
298305
:JSON.stringify(filename)
299306
}
300-
`,
307+
`
301308
}
302309
:{code:''}
303310

@@ -352,6 +359,6 @@ export default function vue(opts: VuePluginOptions = {}): Plugin {
352359

353360
returnresult
354361
}
355-
},
362+
}
356363
}
357364
}

‎src/utils.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ export interface VuePartRequestCreator {
3030
}
3131

3232
exportfunctioncreateVueFilter(
33-
include:Array<string|RegExp>|string|RegExp=[/\.vue$/i],
34-
exclude:Array<string|RegExp>|string|RegExp=[]
33+
include:Array<string|RegExp>|string|RegExp=[/\.vue$/i],
34+
exclude:Array<string|RegExp>|string|RegExp=[]
3535
):(file:string)=>boolean{
3636
constfilter=createFilter(include,exclude)
3737

@@ -128,14 +128,20 @@ export function transformRequireToImport(code: string): string {
128128
constimports:{[key:string]:string}={}
129129
letstrImports=''
130130

131-
code=code.replace(/require\(("(?:[^"\\]|\\.)+"|'(?:[^'\\]|\\.)+')\)/g,(_,name):any=>{
132-
if(!(nameinimports)){
133-
imports[name]=`__$_require_${name.replace(/[^a-z0-9]/g,'_').replace(/_{2,}/g,'_').replace(/^_|_$/g,'')}__`
134-
strImports+='import '+imports[name]+' from '+name+'\n'
131+
code=code.replace(
132+
/require\(("(?:[^"\\]|\\.)+"|'(?:[^'\\]|\\.)+')\)/g,
133+
(_,name):any=>{
134+
if(!(nameinimports)){
135+
imports[name]=`__$_require_${name
136+
.replace(/[^a-z0-9]/g,'_')
137+
.replace(/_{2,}/g,'_')
138+
.replace(/^_|_$/g,'')}__`
139+
strImports+='import '+imports[name]+' from '+name+'\n'
140+
}
141+
142+
returnimports[name]
135143
}
136-
137-
returnimports[name]
138-
})
144+
)
139145

140146
returnstrImports+code
141147
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp