Skip to content
This repository has been archived by the owner on Feb 19, 2021. It is now read-only.

Commit

Permalink
fixed the fonts path error after build
Browse files Browse the repository at this point in the history
  • Loading branch information
BiYuqi committed Jan 6, 2019
1 parent d7614de commit 07158b8
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 14 deletions.
1 change: 0 additions & 1 deletion build/utils.js
Expand Up @@ -55,7 +55,6 @@ exports.cssLoaders = function (options) {
})
})
}

return loaders
}

Expand Down
22 changes: 22 additions & 0 deletions build/webpack.base.conf.js
Expand Up @@ -3,6 +3,9 @@ const path = require('path')
const utils = require('./utils')
const config = require('../config')
const { VueLoaderPlugin } = require('vue-loader')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const devMode = process.env.NODE_ENV !== 'production'

function resolve (dir) {
return path.join(__dirname, '..', dir)
}
Expand Down Expand Up @@ -50,6 +53,25 @@ module.exports = {
symbolId: 'icon-[name]'
}
},
{
test: /\.(sa|sc|c)ss$/,
use: [
{
loader: devMode ? 'vue-style-loader' : MiniCssExtractPlugin.loader,
// to fixed the fonts path error
options: devMode ? {} : { publicPath: '../../' }
},
{
loader: 'css-loader'
},
{
loader: 'sass-loader'
},
{
loader: 'postcss-loader'
}
]
},
{
test: /\.vue$/,
loader: 'vue-loader'
Expand Down
3 changes: 0 additions & 3 deletions build/webpack.dev.conf.js
Expand Up @@ -15,9 +15,6 @@ const PORT = process.env.PORT && Number(process.env.PORT)

const devWebpackConfig = merge(baseWebpackConfig, {
mode: 'development',
module: {
rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap, usePostCSS: true })
},
// cheap-module-eval-source-map is faster for development
devtool: config.dev.devtool,

Expand Down
32 changes: 22 additions & 10 deletions build/webpack.prod.conf.js
Expand Up @@ -15,15 +15,12 @@ const env = process.env.NODE_ENV === 'testing'
? require('../config/test.env')
: require('../config/prod.env')

// For NamedChunksPlugin
const seen = new Set()
const nameLength = 4

const webpackConfig = merge(baseWebpackConfig, {
mode: 'production',
module: {
rules: utils.styleLoaders({
sourceMap: config.build.productionSourceMap,
extract: true,
usePostCSS: true
})
},
devtool: config.build.productionSourceMap ? config.build.devtool : false,
output: {
path: config.build.assetsRoot,
Expand Down Expand Up @@ -102,9 +99,24 @@ const webpackConfig = merge(baseWebpackConfig, {
removeAttributeQuotes: true
// more options:
// https://github.com/kangax/html-minifier#options-quick-reference
},
// necessary to consistently work with multiple chunks via CommonsChunkPlugin
chunksSortMode: 'dependency'
}
}),
// keep chunk.id stable when chunk has no name
new webpack.NamedChunksPlugin(chunk => {
if (chunk.name) {
return chunk.name
}
const modules = Array.from(chunk.modulesIterable)
if (modules.length > 1) {
const hash = require('hash-sum')
const joinedHash = hash(modules.map(m => m.id).join('_'))
let len = nameLength
while (seen.has(joinedHash.substr(0, len))) len++
seen.add(joinedHash.substr(0, len))
return `chunk-${joinedHash.substr(0, len)}`
} else {
return modules[0].id
}
}),
// 根据模块的相对路径生成一个四位数的hash作为模块id
new webpack.HashedModuleIdsPlugin(),
Expand Down

0 comments on commit 07158b8

Please sign in to comment.