- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有以下应用程序结构
:
/webapp
/lib
/assets
ic_add_black_24px.svg
ic_clear_black_24px.svg
..
..
这是我的webpack.config.js
:
var path = require('path'),
webpack = require("webpack"),
libPath = path.join(__dirname, 'lib'),
wwwPath = path.join(__dirname, 'www'),
pkg = require(path.join(__dirname,'package.json')),
HtmlWebpackPlugin = require('html-webpack-plugin');
var config = {
entry: path.join(libPath, 'index.js'),
output: {
path: path.join(wwwPath),
filename: 'bundle-[hash:6].js'
},
module: {
loaders: [{
test: /\.html$/,
loader: 'file?name=templates/[name]-[hash:6].html'
}, {
test: /\.(png|jpg|svg)$/,
loader: 'file-loader?name=assets/[name].[ext]' // inline base64 URLs for <=10kb images, direct URLs for the rest
}, {
test: /\.css$/,
loader: "style!css"
}, {
test: /\.scss$/,
loader: "style!css!autoprefixer!sass"
}, {
test: /\.js$/,
exclude: /(node_modules)/,
loader: "ng-annotate?add=true!babel"
}, {
test: [/fontawesome-webfont\.svg/, /fontawesome-webfont\.eot/, /fontawesome-webfont\.ttf/, /fontawesome-webfont\.woff/, /fontawesome-webfont\.woff2/],
loader: 'file?name=fonts/[name].[ext]'
}]
},
plugins: [
// HtmlWebpackPlugin: Simplifies creation of HTML files to serve your webpack bundles : https://www.npmjs.com/package/html-webpack-plugin
new HtmlWebpackPlugin({
filename: 'index.html',
pkg: pkg,
template: path.join(libPath, 'index.html')
}),
// OccurenceOrderPlugin: Assign the module and chunk ids by occurrence count. : https://webpack.github.io/docs/list-of-plugins.html#occurenceorderplugin
new webpack.optimize.OccurenceOrderPlugin(),
// Deduplication: find duplicate dependencies & prevents duplicate inclusion : https://github.com/webpack/docs/wiki/optimization#deduplication
new webpack.optimize.DedupePlugin()
]
};
module.exports = config;
下面是我如何在我的一个 html 文件中使用 svg Assets
:
<md-card-header>
<span flex></span>
<md-button class="md-icon-button" aria-label="remove condition" style="background-color: #DCD8D8" ng-click="event.removeCondition(condition)">
<md-icon md-svg-src="/lib/assets/ic_clear_black_24px.svg"></md-icon>
</md-button>
</md-card-header>
当我执行 rm -rf www/* && webpack -p
时,它成功创建了包,但没有加载任何 Assets 。我尝试使用 svg-loader, url -loader、文件
,但它们都不起作用。我在这里做错了什么?
最佳答案
如果它对任何人有帮助,我最终使用了 CopyWebpackPlugin手动将 Assets 加载到我需要的位置。这就是我的 webpack.config
现在的样子:
var path = require('path'),
webpack = require("webpack"),
libPath = path.join(__dirname, 'lib'),
wwwPath = path.join(__dirname, 'www'),
pkg = require(path.join(__dirname,'package.json')),
CopyWebpackPlugin = require('copy-webpack-plugin'),
HtmlWebpackPlugin = require('html-webpack-plugin');
var config = {
entry: path.join(libPath, 'index.js'),
output: {
path: path.join(wwwPath),
filename: 'bundle-[hash:6].js'
},
module: {
loaders: [{
test: /\.html$/,
loader: 'file?name=templates/[name]-[hash:6].html'
}, {
test: /\.(png|jpg|svg)$/,
loader: 'svg-url-loader?name=assets/[name].[ext]' // inline base64 URLs for <=10kb images, direct URLs for the rest
}, {
test: /\.css$/,
loader: "style!css"
}, {
test: /\.scss$/,
loader: "style!css!autoprefixer!sass"
}, {
test: /\.js$/,
exclude: /(node_modules)/,
loader: "ng-annotate?add=true!babel"
}, {
test: [/fontawesome-webfont\.svg/, /fontawesome-webfont\.eot/, /fontawesome-webfont\.ttf/, /fontawesome-webfont\.woff/, /fontawesome-webfont\.woff2/],
loader: 'file?name=fonts/[name].[ext]'
}]
},
plugins: [
new CopyWebpackPlugin([{
from: 'lib/assets',
to: wwwPath + '/lib/assets'
}]),
// HtmlWebpackPlugin: Simplifies creation of HTML files to serve your webpack bundles : https://www.npmjs.com/package/html-webpack-plugin
new HtmlWebpackPlugin({
filename: 'index.html',
pkg: pkg,
template: path.join(libPath, 'index.html')
}),
// OccurenceOrderPlugin: Assign the module and chunk ids by occurrence count. : https://webpack.github.io/docs/list-of-plugins.html#occurenceorderplugin
new webpack.optimize.OccurenceOrderPlugin(),
// Deduplication: find duplicate dependencies & prevents duplicate inclusion : https://github.com/webpack/docs/wiki/optimization#deduplication
new webpack.optimize.DedupePlugin()
]
};
module.exports = config;
关于javascript - webpack 不加载 svgs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37735283/
如何使用 d3 将多个带有 id 的 svgs 附加到正文? 这是我第一次尝试绘制 1 svg: // d
在fabricjs v1.5中,我加载了两个不同的svgs,颜色为红色,描边为黑色。现在选择任何 svg 并单击“克隆对象”按钮,它已正确克隆,但是当我选择两个 svg 并单击“克隆组”按钮
我正在尝试为网页创建按钮面板。我用 .svg 文件制作了按钮。使用边距和其他 css 属性,我将它们放到了代码中显示的位置。 我的问题:我不能让两个按钮都完全可点击,具体来说,我可以很好地使用橙色部分
这个问题在这里已经有了答案: clipPath in multiple SVG tags (1 个回答) 4年前关闭。 我在一页上有多个 svg,并已从 illustrator 中单独导出它们。我还通
我无法使用某个表格的内置编辑模式执行我想要的操作,但我将其用于应用程序中的其他表格,因此我想使用以下命令以自定义方式设置选定的单元格: Apple 使用相同的复选标记和空圆圈图标: 有谁知道如何获得以
我用 inkscape 画了一些矢量图。 现在我正在尝试将这些 svg 定位到垂直导航栏中。我想将每个插图定位到相应的位置(使用内联 SVG)。我读过css-tricks: scale-svg这对我很
我有以下应用程序结构: /webapp /lib /assets ic_add_black_24px.svg ic_clear_black_24px.svg
我目前正在做一个元素,我必须在其中构建一个加载屏幕,其中包括一个百分比和定制的 svgs 动画。我在整个互联网上都看过,但找不到任何似乎是我需要的东西?我似乎连一个简单的加载栏都无法工作! 我在下面包
我正在尝试加载与 Angular 7 内联的 svgs。 到目前为止我尝试过: import icon = require('./icon.svg'); 结果为icon.svg由于文件加载器 impo
我正在使用 chrome 中的 React 应用程序,其中涉及大量内联 svg。 如果文本靠近内联 svg,文本周围将随机出现黑色边框。当我突出显示文本时,它有时会消失或出现。 唯一一致的是在出现边框
我通过 api 调用获取 svg 数据并将其附加到 DOM 中的 div。我正在获取 13-14 个 svg 元素并将其附加到单个 div。我想连续显示所有这些 svg。如果我给 svg 元素 wid
我创建了一个点阵视觉效果,如下面的代码片段所示。彩色圆圈代表值,灰色圆圈代表空/未使用。例如,在我的例子中,三种颜色代表来自 3 个国家(美国、加拿大和墨西哥)的项目的百分比形式的资金。灰色代表尚未筹
抱歉,如果我的问题措辞不好。我是初学者,不知道事物的正确标签。 我正在使用 d3.js 制作日本 map ,并想为每个都道府县分配一种颜色。每个都道府县都有自己的 svg。我有一个要使用的颜色的十六进
我用自己的矢量图形创建了一个相当专业的 JavaScript 应用程序。我想托管我自己的可热链接 API 来补充此应用程序,并且认为如果我可以将矢量图形直接嵌入到 API 中,那将非常整洁。 我知道这
我正在使用fabric.js 并将许多SVG 文件加载到其中。使用此代码显示这些导入的文件之一没有问题; fabric.loadSVGFromURL('ico-svg/drink.svg', func
我读过 sweet tutorial关于在 CSS-Tricks 上对 svg-image 中的元素进行动画处理。作者在 svg 中添加了 CSS 类来处理不同的元素。我想使用该技术,但不幸的是在背景
我想使用 svg 作为 div 元素的容器,该元素应包含多个元素。目前它看起来像这样: I'm a very
我有一个非常简单的 Webpack + TypeScript 设置,我正在尝试导入 svgs。我正在使用 svg-sprite-loader 如果我 require() 我的 svgs 如下所示,它会
我一直在对组使用 group.scale.y = -1; 技巧以正确的方式在 three.js 中呈现我的 svg。 然而,这与 y 坐标的概念混淆了,显示从我的组中心向上的正值。通常路径上的正 y
我正在尝试使用 D3 更新 HTML 表格中的数据。我需要更改多列中的数据,更新行数,并根据每个新数据数组为每行中的 SVG 制作动画。我已经尝试了多次尝试、教程、文档,而且我确信这对于对图书馆更有经
我是一名优秀的程序员,十分优秀!