diff --git a/packages/uni-cli-shared/lib/file-loader.js b/packages/uni-cli-shared/lib/file-loader.js index c8b17d31802287658be6a23b0b4cfbd32af3742e..c4d8637a07a924c61b4cbe833111c89bd8c1c9f3 100644 --- a/packages/uni-cli-shared/lib/file-loader.js +++ b/packages/uni-cli-shared/lib/file-loader.js @@ -1,4 +1,5 @@ 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)) diff --git a/packages/uni-cli-shared/lib/url-loader.js b/packages/uni-cli-shared/lib/url-loader.js index 3536f2682a5bcd548f9c3737b5eedecb75cf9253..6c936331140b6e539d0508a33a53bc393a4d0bc7 100644 --- a/packages/uni-cli-shared/lib/url-loader.js +++ b/packages/uni-cli-shared/lib/url-loader.js @@ -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 { diff --git a/packages/vue-cli-plugin-uni/lib/chain-webpack.js b/packages/vue-cli-plugin-uni/lib/chain-webpack.js index 5277538b4f89003d42ff3b93315db891bd40c8b6..d0a463dc87deb4aeea58a38dec57aab1e650f67c 100644 --- a/packages/vue-cli-plugin-uni/lib/chain-webpack.js +++ b/packages/vue-cli-plugin-uni/lib/chain-webpack.js @@ -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) } diff --git a/packages/vue-cli-plugin-uni/lib/h5/index.js b/packages/vue-cli-plugin-uni/lib/h5/index.js index eb3f6ea480de76f0572fc98c84c3cd09fb0b5c2e..b762e416aef2061c519322940c419cb1fadcb8f2 100644 --- a/packages/vue-cli-plugin-uni/lib/h5/index.js +++ b/packages/vue-cli-plugin-uni/lib/h5/index.js @@ -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 - }) - }) } }