Closed 123liyuan123 closed 3 years ago
Can you put together a reproduction? One I can clone and run locally to see the error
var path = require('path'); var webpack = require('webpack'); var HtmlWebpackPlugin = require('html-webpack-plugin'); var ExtractTextPlugin = require("extract-text-webpack-plugin"); var ParallelUglifyPlugin = require('webpack-parallel-uglify-plugin'); // var AddAssetHtmlPlugin = require('add-asset-html-webpack-plugin'); // var config = require('./webpack.base.config.js'); var MyPlugin = require('./MyPlugin.js'); var _ = require('lodash'); // 项目根目录 var rootPath = path.resolve(__dirname, '..');
module.exports = _.merge(config, { devtool: 'none', entry: { //业务代码 bundle: './src/main', }, output: { filename: "js/[name]-[chunkhash:6].js", chunkFilename: "js/[name]-[chunkhash:6].js", // publicPath: './dist/', publicPath: '/', path: path.resolve(rootPath, "dist"),
}, module: { rules: [{ test: /.jsx?$/, loader: 'babel-loader?cacheDirectory,presets[]=es2015,presets[]=stage-0,presets[]=react', query: { plugins: [ ["transform-runtime", {polyfill: false}], ["import", [{"style": "css", "libraryName": "antd-mobile"},{"style": "css", "libraryName": "antd"}]] ] }, exclude: /node_modules/ }, { test: /.scss$/, use: ExtractTextPlugin.extract({ fallback: "style-loader", use: "css-loader!postcss-loader!sass-loader" }) },{ test: /.css$/, loaders: ["style-loader", "css-loader", "postcss-loader"], },{ test: /.(jpe?g|png|gif|svg)$/, loader: 'url-loader', query: {limit: 10240}, },{ test: /.(woff|woff2|svg|eot|ttf)\??.$/, loader: "url-loader", query: { limit: 1024, }, }] }, plugins: [ new webpack.DllReferencePlugin({ manifest: require("../vendor/manifest.json"), context: __dirname }), // 自定义插件用来把直接插入在body中 new MyPlugin({ paths: [ "./src/static/lib/crypto1/crypto/crypto.js", "./src/static/lib/crypto1/hmac/hmac.js", "./src/static/lib/crypto1/sha1/sha1.js", "./src/static/lib/base64.js", "./src/static/lib/plupload-2.1.2/js/plupload.full.min.js", "./src/static/lib/hostRoute/hostRoute.js", // "./vendors.js", ] }), new HtmlWebpackPlugin({ template: 'index.tpl.html', inject: 'body', filename: 'index.html' }), new ExtractTextPlugin("bundle.css"), new ParallelUglifyPlugin({ exclude: /\/node_modules/, // test: /.js$/g, // workerCount: '10',//线程不需要开启,使用默认的 cacheDir: '.cache/', sourceMap: false, uglifyJS:{ mangle: true, output: { comments: false, }, compress: { // warnings: false, drop_debugger: true, drop_console: true, comparisons: false } } }), new webpack.NoEmitOnErrorsPlugin(), new webpack.BannerPlugin('构建时间:'+new Date()), new webpack.DefinePlugin({ "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV) }), // new AddAssetHtmlPlugin([ // { filepath: path.resolve(rootPath, 'vendor/.js') }, // ]) ], });
------------------ 原始邮件 ------------------ 发件人: "SimenB/add-asset-html-webpack-plugin" <notifications@github.com>; 发送时间: 2021年3月2日(星期二) 下午5:40 收件人: "SimenB/add-asset-html-webpack-plugin"<add-asset-html-webpack-plugin@noreply.github.com>; 抄送: "123"<1638102586@qq.com>;"Author"<author@noreply.github.com>; 主题: Re: [SimenB/add-asset-html-webpack-plugin] Cannot read property 'compilation' of undefined (#200)
Can you put together a reproduction? One I can clone and run locally to see the error
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
that doesn't help me much with reproducing. https://stackoverflow.com/help/minimal-reproducible-example is a good guide explaining how to put together what I want/need 🙂
I found the problem, because I used webpack version is 2 ,so project have some incompatibility problem , i am sorry for you
------------------ 原始邮件 ------------------ 发件人: "SimenB/add-asset-html-webpack-plugin" <notifications@github.com>; 发送时间: 2021年3月2日(星期二) 晚上6:30 收件人: "SimenB/add-asset-html-webpack-plugin"<add-asset-html-webpack-plugin@noreply.github.com>; 抄送: "123"<1638102586@qq.com>;"Author"<author@noreply.github.com>; 主题: Re: [SimenB/add-asset-html-webpack-plugin] Cannot read property 'compilation' of undefined (#200)
that doesn't help me much with reproducing. https://stackoverflow.com/help/minimal-reproducible-example is a good guide explaining how to put together what I want/need 🙂
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
Great you found the issue 👍
new webpack.DllReferencePlugin({ manifest: require("../vendor/manifest.json"), context: __dirname }), // 自定义插件用来把直接插入在body中 new MyPlugin({ paths: [ "./src/static/lib/crypto1/crypto/crypto.js", "./src/static/lib/crypto1/hmac/hmac.js", "./src/static/lib/crypto1/sha1/sha1.js", "./src/static/lib/base64.js", "./src/static/lib/plupload-2.1.2/js/plupload.full.min.js", "./src/static/lib/hostRoute/hostRoute.js", // "./vendors.js", ] }), new HtmlWebpackPlugin({ template: 'index.tpl.html', inject: 'body', filename: 'index.html' }), new ExtractTextPlugin("bundle.css"), new ParallelUglifyPlugin({ exclude: /\/node_modules/, // test: /.js$/g, // workerCount: '10',//线程不需要开启,使用默认的 cacheDir: '.cache/', sourceMap: false, uglifyJS:{