[英]How to include this node_module's .html asset in webpack?
I am using the package electron-notifications
and it relies on a .html
and .css
file in its assets
folder. 我正在使用
electron-notifications
包,它依赖于其assets
文件夹中的.html
和.css
文件。 This assets folder is not included in webpack (1.14.0) though. 但是,此资产文件夹未包含在webpack(1.14.0)中。
I know I should not add a module as an entry point. 我知道我不应该将模块添加为入口点。 I have come across a concept called code splitting, but I'm not clear on how that works and if that is what I need to be looking into further.
我遇到了一个称为代码拆分的概念,但是我不清楚它是如何工作的,是否需要进一步研究。 Any advice you can give would be greatly appreciated.
您可以提供的任何建议将不胜感激。
webpack.config.production.js webpack.config.production.js
import path from 'path';
import webpack from 'webpack';
import validate from 'webpack-validator';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import merge from 'webpack-merge';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import BabiliPlugin from 'babili-webpack-plugin';
import baseConfig from './webpack.config.base';
export default validate(merge(baseConfig, {
devtool: 'inline-source-map',
entry: [
'babel-polyfill',
'./app/index'
],
output: {
path: path.join(__dirname, 'app/dist'),
publicPath: '../dist/'
},
module: {
loaders: [
// Extract all .global.css to style.css as is
{
test: /\.global\.css$/,
// loaders: [
loader: ExtractTextPlugin.extract(
'style-loader',
'css-loader?sourceMap'
)
// ]
},
// Pipe other styles through css modules and append to style.css
{
test: /^((?!\.global).)*\.css$/,
// loaders: [
loader: ExtractTextPlugin.extract(
'style-loader',
'css-loader?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]'
)
},
// Fonts
{ test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/font-woff' },
{ test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/font-woff' },
{ test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/octet-stream' },
{ test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: 'file' },
{ test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=image/svg+xml' },
// Images
{
test: /\.(?:ico|gif|png|jpg|jpeg|webp)$/,
loader: 'url-loader'
}
]
},
plugins: [
// https://webpack.github.io/docs/list-of-plugins.html#occurrenceorderplugin
// https://github.com/webpack/webpack/issues/864
new webpack.optimize.OccurrenceOrderPlugin(),
// NODE_ENV should be production so that modules do not perform certain development checks
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
}),
new BabiliPlugin(),
new ExtractTextPlugin('style.css', { allChunks: true }),
new HtmlWebpackPlugin({
filename: '../app.html',
template: 'app/app.html',
inject: false
})
],
// https://github.com/chentsulin/webpack-target-electron-renderer#how-this-module-works
target: 'electron-renderer'
}));
If you want that packages' CSS to be recognised by the webpack, you just add it to the style's(CSS's) loader block, as an include
attribute along with "test" and "loader". 如果您希望Webpack识别包的CSS,只需将其添加到样式的CSS加载器块中,作为
include
属性以及“ test”和“ loader”一起使用。 In the include attribute point it to the node_modules/electron_notification path. 在包含属性中,将其指向node_modules / electron_notification路径。
HTML of that package need not be included, since your Single Page Application, has it's own HTML, if needed try to replicate the class names there. 该包的HTML无需包含在内,因为您的单页应用程序具有自己的HTML,如果需要,请尝试在其中复制类名。 But I doubt if you need to do that.
但我怀疑您是否需要这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.