仅将主要的 javascript 文件添加为条目,并通过以下方式要求所有字体和样式require('./style.css')
webpack.config.js:
entry: {
'main': 'app/main',
},
output: {
path: 'static',
publicPath: '/static/',
filename: '[name].bundle.js',
chunkFilename: '[chunkhash].bundle.js',
},
module: {
rules: [
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: 'css-loader'
}),
}]
},
plugins: [
new ExtractTextPlugin('[name].bundle.css'),
],
这将为您/static/main.bundle.css
提供 app/main.js 中包含的所有 css(传递性)。
字体也一样,但您需要第二个 ExtractTextPlugin 实例,例如:
const extractCSS = new ExtractTextPlugin('stylesheets/[name].bundle.css');
const extractFonts = new ExtractTextPlugin('stylesheets/[name].bundle.woff');
module.exports = {
module: {
rules: [
{
test: /\.css$/,
use: extractCSS.extract([ 'css-loader', 'postcss-loader' ])
},
{
test: /\.woff$/i,
use: extractFonts.extract([ 'url-loader' ])
},
]
},
plugins: [
extractCSS,
extractFonts
]
};
有关更多信息,请参阅文档 - 多个实例。