これはバグであるか、私の設定であるかわからない場合、CommonsChunkPluginを使用してプロジェクトの3つのエントリポイントに対してcommon.jsを、 cssファイルを取得するには、extract-text-webpack-pluginを使用します。私のエントリーポイントはapp、login、registerです。私が取得することができています:extract-text-webpack-pluginを使用して共通のチャンクでCSSが抽出されない
app.js
app.vendor.js
login.js
register.js
common.js
CSSの:
app.css
register.css
login.css
私はcommon.cssが発生したように見えることはできません。すべてのcssは1つのapp.cssファイルにまとめられます。
私のプロジェクトはvuetifyのWebPACKのテンプレートに基づいて設定される:ここで https://github.com/vuetifyjs/webpack-advanced
は私の設定です:
3のエントリポイント:
module.exports = {
entry: {
app: './src/main.js',
login: './src/Login/login.js',
register: './src/Register/register.js'
},
プラグイン - 私は、各エントリのHtmlWebpackPluginを持っていますポイント(1つのみ表示):
new HtmlWebpackPlugin({
filename: process.env.NODE_ENV === 'testing'
? 'index.html'
: config.build.index,
template: 'index.html',
inject: false,
hash: true,
minify: {
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: false,
minifyJS: true
},
chunksSortMode: appChunkOrder
}),
の
共通チャンク:
new webpack.optimize.CommonsChunkPlugin({
name: 'app.vendor',
chunks: ['app'],
minChunks: isVendor,
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'login.vendor',
chunks: ['login'],
minChunks: isVendor,
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'register.vendor',
chunks: ['register'],
minChunks: isVendor,
}),
// Extract chunks common to both app and login
new webpack.optimize.CommonsChunkPlugin({
name: 'common',
chunks: ['app.vendor', 'login.vendor', 'register.vendor', 'app', 'login', 'register'],
minChunks: (module, count) => count >= 2 && isVendor(module),
}),
フル設定:
plugins: [
new webpack.DefinePlugin({'process.env': env }),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
},
sourceMap: true
}),
// extract css into its own file
new ExtractTextPlugin({
filename: utils.assetsPath('css/[name].[contenthash].css')
}),
new OptimizeCSSPlugin({
cssProcessorOptions: {
safe: true
}
}),
// generate Html index files for 3 entries:
new HtmlWebpackPlugin({
filename: process.env.NODE_ENV === 'testing'
? 'index.html'
: config.build.index,
template: 'index.html',
inject: false,
hash: true,
minify: {
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: false,
minifyJS: true
},
chunksSortMode: appChunkOrder
}),
new HtmlWebpackPlugin({
filename: process.env.NODE_ENV === 'testing'
? 'src/Login/login.html'
: config.build.login,
template: 'src/Login/login.html',
inject: false,
hash: true,
minify: false,
chunksSortMode: loginChunkOrder
}),
new HtmlWebpackPlugin({
filename: process.env.NODE_ENV === 'testing'
? 'src/Register/register.html'
: config.build.register,
template: 'src/Register/register.html',
inject: false,
hash: true,
minify: false,
chunksSortMode: registerChunkOrder
}),
// Chunks:
new webpack.optimize.CommonsChunkPlugin({
name: 'app.vendor',
chunks: ['app'],
minChunks: isVendor,
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'login.vendor',
chunks: ['login'],
minChunks: isVendor,
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'register.vendor',
chunks: ['register'],
minChunks: isVendor,
}),
// Extract chunks common to both app and login
new webpack.optimize.CommonsChunkPlugin({
name: 'common',
chunks: ['app.vendor', 'login.vendor', 'register.vendor', 'app', 'login', 'register'],
minChunks: (module, count) => count >= 2 && isVendor(module),
}),
// copy custom static assets
new CopyWebpackPlugin([
{
from: path.resolve(__dirname, '../static'),
to: config.build.assetsSubDirectory,
ignore: ['.*']
}
])
任意の助けに感謝!
ご返信いただきありがとうございます!私は 'vuetify'からのVuetifyのようなサードパーティのパッケージをインポートしています。この場合、cssファイルの処理方法はわかりません。別にインポートする必要がありますか? – JerryH
私は第三者のライブラリに付属しているCSSを分けることができると期待しています。しかし、私はファイル名で直接インポートしていません... – JerryH