我有一个典型的Webpack文件,其中包含用于字体,图像,css的加载器模块,如下所示:
module: {
loaders: [{
test: /\.jsx?$/,
loaders: ['react-hot', 'babel-loader?
presets[]=es2015,presets[]=stage-1,presets[]=stage-2,presets[]=react,plugins[]=transform-runtime'],
exclude: /node_modules/
},
工作代码:
{ test: /\.scss$/,
exclude: /node_modules/,
loader: ExtractTextPlugin.extract('style', 'css!sass?sourceMap')
},
{
test: /\.(jpg|jpeg|gif|png|svg)$/,
exclude: /node_modules/,
include: PATHS.imagesLoc,
loader: "file-loader?name=img/[name].[ext]"
},
无效:
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
exclude: /node_modules/,
loader: 'file-loader?limit=1024&name=fonts/[name].[ext]'
},
{ test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
exclude: /node_modules/,
loader: "file-loader?limit=1024&name=fonts/test/[name].[ext]"
}
]},
plugins: [
new webpack.DefinePlugin({
'process.env.COSMIC_BUCKET': JSON.stringify(process.env.COSMIC_BUCKET)
}),
new CopyWebpackPlugin([
{ from: 'images/', to: 'img/' }
]),
new ExtractTextPlugin("css/custom.css")
]
};
我的根文件夹包含以下目录:
const PATHS = {
app: path.join(__dirname, './enter.js'),
build: path.join(__dirname, './public'),
fonts: path.join(__dirname, './fonts'),
cssLoc: path.join(__dirname, './styles'),
imagesLoc: path.join(__dirname, './images')
};
图像和样式加载器都工作正常,但由于某些原因,没有任何字体文件被转换为public / fonts目录。
就像我的image
和style
文件夹一样,fonts目录位于app根目录中。在./fonts
内,我有两个文件夹,其字体内容为./fonts/roboto
,./fontawesome
。这些目录需要反映在./public/
内部,但是现在我甚至无法将字体复制到./public
目录中,因此最终会得到./public/fonts/roboto
。什么都没发生。没有任何警告/错误。如何辨别我做错了什么?
新WEBPACK
什么都没有渲染或被复制到public /目录中。没有错误。
var webpack = require("webpack");
var HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
const PATHS = {
app: path.join(__dirname, './app-client.js'),
build: path.join(__dirname, './public'),
fonts: path.join(__dirname, './fonts'),
cssLoc: path.join(__dirname, './styles'),
imagesLoc: path.join(__dirname, './images')
};
if(process.env.NODE_ENV === 'development'){
var loaders = ['react-hot','babel']
} else {
var loaders = ['babel']
}
module.exports = {
devServer: {
inline: true,
port: 8080,
outputPath: PATHS.build
},
//bundle app from here
entry: {
app: PATHS.app
},
output: {
path: PATHS.build,
filename: 'bundle.js',
publicPath: PATHS.build
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loaders: ['react-hot', 'babel-loader?presets[]=es2015,presets[]=stage-1,presets[]=stage-2,presets[]=react,plugins[]=transform-runtime']
},
{
test: /\.scss$/,
loader: 'style!css!sass'
},
{
test: /\.css$/,
loader: 'css'
},
{
test: /\.(png|gif|jpe?g|svg)$/i,
loader: 'url?limit=50000&name=img/[name]' // limit ~50kb
},
{
test: /\.(otf|eot|ttf|woff|woff2)$/,
loader: 'file?name=assets/fonts/[name].[ext]'
},
{
test: /\.html$/,
loader: 'html-loader'
}
]
},
resolve: {
extensions: ['', '.webpack.js', '.web.js', '.js', '.jsx']
},
node: {
console: true,
fs: 'empty',
net: 'empty',
tls: 'empty'
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: ['app', 'vendor']
}),
new webpack.DefinePlugin({
'process.env.COSMIC_BUCKET': JSON.stringify(process.env.COSMIC_BUCKET)
}),
new webpack.HotModuleReplacementPlugin(),
new HtmlWebpackPlugin(
{
template: './public/index.html'
}
)
]
}
答案 0 :(得分:0)
我通常会传递所有字体扩展名,如下所示:
live_products = Product.where('status = ?', 'live')
live_products.each do |product|
at: product.end_time do
product.status = 'dead'
product.save
end
end
所有字体都会被复制到我的deploy / assets / fonts文件夹中。
这是我的整个webpack.config文件:
{
test: /\.(otf|eot|ttf|woff|woff2)$/,
loader: 'file?name=assets/fonts/[name].[ext]'
}