提交 5442e5b7 编写于 作者: Y yurj26

fix: 调整vue2编译器静态资源编译目录 (question/184480)

上级 ae7a6c91
const path = require('path')
const webpack = require('webpack')
const {
normalizePath
// normalizeNodeModules
......@@ -18,11 +19,11 @@ module.exports = {
const relativePath = normalizePath(path.relative(inputDir,
resourcePath))
if (relativePath.startsWith('static/') || relativePath.includes(
'static/')) {
'/static/')) {
return relativePath
}
}
return 'assets/[name].[hash:8].[ext]'
return `assets/[name].[hash:8]${webpack.version[0] > 4 ? '' : '.'}[ext]`
}
// publicPath (url, resourcePath, context) {
// return '/' + normalizeNodeModules(path.relative(process.env.UNI_INPUT_DIR, resourcePath))
......
......@@ -35,8 +35,11 @@ module.exports = {
loader: 'url-loader',
options () {
if (process.env.UNI_PLATFORM === 'h5') {
// h5平台,不对 url-loader 作调整,默认limit:4096,也不修改file-loader输出路径
return {}
// h5平台,不对 url-loader 作调整,默认limit:4096,也不修改file-loader输出路径(已做处理)
return {
...defaultOptions,
limit: 4096
}
}
if (inlineLimit) {
return {
......
......@@ -31,17 +31,17 @@ module.exports = function chainWebpack (platformOptions, vueOptions, api) {
}
if (newOptions.fallback && newOptions.fallback.options) {
const generator = {}
const oldOptions = newOptions.fallback.options
const keys = ['publicPath', 'outputPath']
keys.forEach(key => {
generator[key] = pathData => {
const outputPath = oldOptions[key](null, pathData.module.request)
const basename = path.basename(outputPath)
return outputPath.substring(0, outputPath.length - basename.length)
}
})
const options = newOptions.fallback.options
// const keys = ['publicPath', 'outputPath']
// keys.forEach(key => {
// generator[key] = pathData => {
// const outputPath = oldOptions[key](null, pathData.module.request)
// const basename = path.basename(outputPath)
// return outputPath.substring(0, outputPath.length - basename.length)
// }
// })
generator.filename = pathData => {
return path.basename(pathData.module.request)
return options.name(pathData.module.request)
}
webpackConfig.module.rule(staticType).set('generator', generator)
}
......
......@@ -193,16 +193,5 @@ module.exports = {
if (process.env.NODE_ENV === 'production') {
require('./cssnano-options')(webpackConfig)
}
const fileLoader = require('@dcloudio/uni-cli-shared/lib/file-loader');
['images', 'media', 'fonts'].forEach(type => {
const rule = webpackConfig.module.rule(type)
rule.use('url-loader').tap(options => {
if (options.fallback) {
options.fallback.options.name = fileLoader.options.name
}
return options
})
})
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册