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

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

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