- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在尝试构建一个 Electron 应用程序。我试图将自定义字体引入到我的应用程序中,并且在开发中,该自定义字体有效,但是,当将其编译为可用于生产环境的应用程序时,该字体不会通过。
我在此处放置了“裸露的骨头”应用程序来突出显示该问题https://github.com/jacobluke121/electron-forge-font-issue-。我还在这里包括了相关的代码。
我觉得问题出在我的Webpack配置周围。在webpack.renderer.config.js
内部,我使用copy-webpack-plugin
将 Assets 从static
文件夹移至.webpack/renderer
文件夹。 Assets 确实转移到了生产中,但是,在编译时, Assets 表示渲染器无法在开发人员控制台中找到它们,即使它们明确位于开发人员控制台的资源选项卡中也是如此。
以下包含的文件并非项目的所有文件,但我认为它们与我的问题最相关。
main.js又名 Electron 面
const {app, BrowserWindow} = require('electron');
const electronLog = require('electron-log');
const main_log = electronLog.create('main')
//set console.log to main_log.log,
console.log = main_log.log;
let mainWindow;
// Handle creating/removing shortcuts on Windows when installing/uninstalling.
if (require('electron-squirrel-startup')) { // eslint-disable-line global-require
app.quit();
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', (event) => {
event.preventDefault();
mainWindow = new BrowserWindow({
width: 1280, height: 960,
webPreferences: {
nodeIntegration: false,
webSecurity: false,
contextIsolation: true,
enableRemoteModule: false,
preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY
}
});
mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY);
mainWindow.webContents.openDevTools();
// if closed then end application:
mainWindow.on('closed', function () {
main_log.info('%c Closing. %c The application', 'color: red', 'color: green');
mainWindow = null;
});
});
// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
// On Mac OS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) {
mainWindow = new BrowserWindow({
width: 1280,
height: 960,
});
mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY);
}
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
import React, {Component} from 'react';
import './app.css';
import 'bootstrap/dist/css/bootstrap.min.css';
class App extends Component {
render() {
return (
<div>
<p className="san-serif">This is supposed to be Calibril Light in Production but it's not...</p>
<p className="san-serif">however, when you run 'yarn start' its the correct font-family</p>
<p className="san-serif">When in production if you look in the dev console tools, you can see that the font family is there under resources...</p>
</div>)
}
}
export default App;
@font-face {
font-family: "Calibri Light2";
font-style: normal;
font-weight: normal;
src: url("/fonts/calibril.woff") format("woff");
}
.san-serif {
font-family: "Calibri Light2";
}
/*# sourceMappingURL=app.css.map */
module.exports = {
/**
* This is the main entry point for your application, it's the first file
* that runs in the main process.
*/
entry: './src/electron/main.js',
// Put your normal webpack config below here
module: {
rules: require('./webpack.rules'),
},
resolve: {
extensions: ['.js', '.jsx', '.css', '.woff']
},
};
const rules = require('./webpack.rules');
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const assets = ["fonts"]
module.exports = {
// Put your normal webpack config below here
module: {
rules,
},
resolve: {
extensions: ['.js', '.jsx', '.css', '.woff'],
},
plugins: assets.map(asset => {
return new CopyWebpackPlugin({
patterns : [
{
from: path.resolve(__dirname, 'static', asset),
to: path.resolve(__dirname, '.webpack/renderer', asset)
}
]
});
}),
}
const path = require('path');
module.exports = [
// Add support for native node modules
{
test: /\.node$/,
use: 'node-loader',
},
{
test: /\.(js|jsx)$/,
exclude: /(node_modules|.webpack)/,
loaders: [{
loader: 'babel-loader'
}]
},
{
test: /\.css$/,
use: [{loader: 'style-loader'}, {loader: 'css-loader'}],
},
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'fonts/'
}
}
]
},
]
最佳答案
经过多次尝试和考验,我今天也面临着同样的问题
仅在规则中添加此内容对我有用,而无需使用任何额外的插件
{
test: /\.(ttf|otf|eot|svg|woff2|woff)$/,
use: [
{
loader: "file-loader",
options: {
name: "[path][name].[ext]",
publicPath: "../",
},
},
],
}
在带有webpack插件的electronic-forge v6.0.0中
关于node.js - 进口 Assets 发行, Electron 伪造,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62449065/
我在我的应用程序中使用rails 4 和 ruby 1.9.3 以及fancybox2-rails gem,但是 Assets 管道存在一个普遍问题。如果我运行 rake task 进行预编译,那
我把我所有的 Assets 都放在我的包里例如myBundle/Resources/public/css/ 然后像这样加载它们: {% block stylesheets %} {{ parent()
我正在创建RoR-6应用程序,并从此行的application.html.erb文件中引发以下错误: javascript_include_tag 'application', 'data-turbo
我正在对 Play Subproject 功能进行更多扩展测试,如下所述:http://www.playframework.com/documentation/2.0/SBTSubProjects .
我是 symfony 2 和 Assetic 的新手。我想在 CSS 中使用 assetic 和 Sass。我使用自定义字体。我在资源下的包中创建文件夹“assets/css”,里面有 _base.s
这是我的目录结构(这只是一个测试项目): stan@mypc:/generate_assets$ sudo tree -L 3 -p . ├── [drwxr-xr-x] assets │ └─
我使用 node.js connect/express。 有人知道支持 TypeScript 源代码即时编译和缩小的 Assets 管理器吗? 知道如何以编程方式调用编译器吗? 我一直在使用 conn
因此,我们在 Assets 管道摘要方面遇到了一个小问题,因为我们有许多 HTML 模板作为 Assets (对于 AngularJS),并且我们使用 asset_path 在 Javascript
我想从iPad的照片库中获取图像URL。 当我尝试从Image Piicker的信息中获取 UIImagePickerControllerReferenceURL 时 我将URL设为: assets
我正在使用带有Assetic的Symfony 2.1.10版,并且在上次 Composer 更新之后,当我尝试运行php app/console assetic:dump时出现以下错误 Dumping
我的 Assets 管道有问题,我已经有一个名为 Assets 的资源/ Controller 。所以我已将 assets.prefix 选项更改为“/externals”。 config.asset
更新到 Expo sdk 34 后,出现此错误:TypeError:Asset.fromModule 不是函数。 (在“Asset.fromModule(image)”中,“Asset.fromMod
将 Play 框架项目从 2.2.4 迁移到 2.3.8 后遇到问题: 这是运行命令“activatorcompile”的错误输出: [error] ...\workspace\testproject
我在将 Google Analytics 添加到我的 Rails 4 应用程序时遇到了一些困难(参见 this post)。 我通过在 /public/assets/google-analytics.
我正在使用 Symfony2 和 Assetic。最近我一直在做很多 CSS 工作,所以在某个时候我需要命令 $ php app/console assetic:dump --env=prod --n
我正在 Android 开发中迈出第一步,并遇到了 Assets 一词。 据我了解, Assets 只是一个未被解析或引用为资源的文件。 这个词有更准确的定义吗?我应该在哪些情况下在我的应用程序中使用
我添加了 danial-farid--angular-file-upload通过 Rails Assets 将库添加到我的 Rails 4 应用程序。主库加载正常,但 sprockets 找不到它包含
这是我的代码,尽管编码非常粗糙: public void loadStack(AssetManager manager, String path) { String[] lis
我正在使用 Assets 管理我的 Symfony 2 框架中的 CSS 文件。它在生产模式下运行良好。 我的问题是在 Debug模式下,assetic 不断将我的文件合并为一个输出文件。这使得跟踪特
我想以编程方式从重复的相册中删除 Assets (照片不是)。我可以使用照片框架删除相册 我想知道如何从相册中删除 Assets 而不从照片应用中完全删除它。我想在多个地方使用它,例如将 Assets
我是一名优秀的程序员,十分优秀!