Skip to content

Commit 845f549

Browse files
committed
tweaks
- use `cwd` and `ownDir` function to get path
1 parent d31e2a5 commit 845f549

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

bin/vue-build

+21-13
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ var localConfig
5151
// config option in only available in CLI option
5252
if (!program.disableConfig) {
5353
var localConfigPath = typeof program.config === 'string'
54-
? path.join(process.cwd(), program.config)
54+
? cwd(program.config)
5555
: path.join(home, '.vue', 'config.js')
5656
var hasLocalConfig = fs.existsSync(localConfigPath)
5757
if (hasLocalConfig) {
@@ -133,7 +133,7 @@ var webpackConfig = {
133133
client: []
134134
},
135135
output: {
136-
path: path.join(process.cwd(), options.dist),
136+
path: cwd(options.dist),
137137
filename: filenames.js,
138138
publicPath: '/'
139139
},
@@ -143,16 +143,16 @@ var webpackConfig = {
143143
resolve: {
144144
extensions: ['.js', '.vue', '.css'],
145145
modules: [
146-
process.cwd(),
147-
path.join(process.cwd(), 'node_modules'), // modules in cwd's node_modules
148-
path.join(__dirname, '../node_modules') // modules in package's node_modules
146+
cwd(),
147+
cwd('node_modules'), // modules in cwd's node_modules
148+
ownDir('node_modules') // modules in package's node_modules
149149
],
150150
alias: {}
151151
},
152152
resolveLoader: {
153153
modules: [
154-
path.join(process.cwd(), 'node_modules'), // loaders in cwd's node_modules
155-
path.join(__dirname, '../node_modules') // loaders in package's node_modules
154+
cwd('node_modules'), // loaders in cwd's node_modules
155+
ownDir('node_modules') // loaders in package's node_modules
156156
]
157157
},
158158
module: {
@@ -215,8 +215,8 @@ if (options.mount === undefined && !options.lib && /\.vue$/.test(options.entry))
215215
// set an alias to the path of the component
216216
// otherwise use it directly as webpack entry
217217
if (options.mount) {
218-
webpackConfig.entry.client.push(path.join(__dirname, '../lib/default-entry.es6'))
219-
webpackConfig.resolve.alias['your-tasteful-component'] = path.resolve(process.cwd(), options.entry)
218+
webpackConfig.entry.client.push(ownDir('lib/default-entry.es6'))
219+
webpackConfig.resolve.alias['your-tasteful-component'] = cwd(options.entry)
220220
} else {
221221
webpackConfig.entry.client.push(options.entry)
222222
}
@@ -234,7 +234,7 @@ if (options.lib) {
234234
webpackConfig.plugins.unshift(
235235
new HtmlWebpackPlugin(Object.assign({
236236
title: 'Vue App',
237-
template: path.join(__dirname, '../lib/template.html')
237+
template: ownDir('lib/template.html')
238238
}, options.html))
239239
)
240240
}
@@ -243,9 +243,9 @@ if (options.lib) {
243243
if (isYarn(__dirname)) {
244244
// modules in yarn global node_modules
245245
// because of yarn's flat node_modules structure
246-
webpackConfig.resolve.modules.push(path.join(__dirname, '../../'))
246+
webpackConfig.resolve.modules.push(ownDir('..'))
247247
// loaders in yarn global node_modules
248-
webpackConfig.resolveLoader.modules.push(path.join(__dirname, '../../'))
248+
webpackConfig.resolveLoader.modules.push(ownDir('..'))
249249
}
250250

251251
if (production) {
@@ -291,7 +291,7 @@ if (!options.disableWebpackConfig) {
291291
webpackConfig = options.webpack(webpackConfig, options, webpack)
292292
} else {
293293
var localWebpackConfigPath = typeof options.webpack === 'string'
294-
? path.join(process.cwd(), options.webpack)
294+
? cwd(options.webpack)
295295
: path.join(home, '.vue', 'webpack.config.js')
296296
var hasLocalWebpackConfig = fs.existsSync(localWebpackConfigPath)
297297
if (hasLocalWebpackConfig) {
@@ -396,3 +396,11 @@ function getFilenames (options) {
396396
static: options.lib ? 'static/[name].[ext]' : 'static/[name].[hash:8].[ext]'
397397
}, options.filename)
398398
}
399+
400+
function cwd (file) {
401+
return path.resolve(file || '')
402+
}
403+
404+
function ownDir (file) {
405+
return path.join(__dirname, '..', file || '')
406+
}

0 commit comments

Comments
 (0)