Closed luozhihua closed 6 years ago
I moved html-webpack-include-assets-plugin
after html-webpack-plugin
was works now.
Hi :) I have same problem. In which file did you moved this line?
@yoasia just place using of HtmlWebpackPlugin
above usgin HtmlWebpackIncludeAssetsPlugin
in your config.plugins
.
same issue, but the solution move HtmlWebpackIncludeAssetsPlugin after HTMLWebpackPlugin
is not working for me,
I have multiple HtmlWebpackIncludeAssetsPlugin instances
const webpack = require('webpack')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const path = require('path')
const HTMLWebpackPlugin = require("html-webpack-plugin")
const glob = require('glob')
const HappyPack = require('happypack')
const os = require('os')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const HtmlWebpackIncludeAssetsPlugin = require('html-webpack-include-assets-plugin')
const root = path.join(__dirname, '../')
const srcPath = path.join(root, 'client')
const distPath = path.join(root, 'dist/client')
const env = process.env.NODE_ENV || 'development'
// webpack 4 mode只有 production/development/none 其他取值会报错
const mode = env === 'production' ? 'production' : 'development'
const entry = {}
const plugins = []
const happyThreadPool = HappyPack.ThreadPool({ size: os.cpus().length });
glob.sync('views/**/*.js', {cwd: srcPath})
.forEach( (filePath) => {
let chunk = filePath.slice(0 , path.extname(filePath).length * -1)
entry[chunk] = [`./${chunk}`]
} )
glob.sync('views/**/*.html', {cwd: srcPath})
.forEach( (filePath) => {
let chunk = filePath.slice(0, path.extname(filePath).length * -1)
plugins.push(new HTMLWebpackPlugin({
filename: filePath,
template: filePath,
minify: false,
inject: false,
chunks: entry[chunk] ? [ chunk ] : []
}))
})
plugins.push(new HtmlWebpackIncludeAssetsPlugin({
assets: [
{
path: 'client/',
globPath: distPath,
glob: 'vendors*.js'
}
],
append: false
}),)
const config = {
mode: mode,
entry: entry,
context: srcPath,
devtool: 'cheap-module-source-map',
output: {
...
},
module: {
rules: [
...
]
},
plugins: [
new HappyPack({
id: 'js',
...
}),
new HappyPack({
id: 'style',
...
}),
new webpack.HotModuleReplacementPlugin(),
new ExtractTextPlugin({
allChunks: true,
filename: '[name].css'
}),
].concat(plugins),
resolve: {
modules: [
srcPath,
'node_modules'
],
extensions: ['.js', '.jsx', '.json', '.less']
},
optimization: {
splitChunks: {
chunks: 'all',
minSize: 30000,
maxSize: 0,
minChunks: 2,
maxAsyncRequests: 5,
maxInitialRequests: 3,
automaticNameDelimiter: '-',
name: true,
cacheGroups: {
plugins: {
test: /[\\/]node_modules[\\/]/,
priority: -10
},
default: {
minChunks: 2,
priority: -20,
reuseExistingChunk: true
}
}
}
}
}
module.exports = config
I moved
html-webpack-include-assets-plugin
afterhtml-webpack-plugin
was works now.
same problem here. and changing order did not solve the problem in my case
@viatoswelz did you solve the problem ?
This is an issue with any two plugins not interacting properly with each other.
Make sure there are no typos in your import/require statements and then that you call all your plugins in the right order. Then it should work fine.
What is the right order?
"html-webpack-plugin": "^3.2.0", This version all OK, but not @next
The full test suite for this plugin is run and passes with both versions of html-webpack-plugin
so if you’re having issues it’s likely something to do with your webpack config.
You might want to read the section in the README.md
about plugin ordering.
For what it's worth, I had this error, and solved it by (what else) deleting my node_modules folder, package.json & running npm install
.
webpack v4.5