我在具有生产环境的webpack.config.js中进行设置,这个问题一直困扰着我。关键是没有错误。
请我添加更多文本。以下与问题无关。 MDN表示:异步函数声明用于定义返回AsyncFunction对象的异步函数。异步函数是通过事件循环异步执行的函数,并且它通过隐式Promise返回结果。 简而言之,如果在函数前面使用async关键字,则该函数将返回一个promise。如果不返回承诺,JavaScript会自动将值“包装”为Promise解析值。例如
new HtmlWebpackPlugin({
filename:path.resolve(__dirname,'dist/index.html'),
template:'./index.html',
inject: true,//默认值 script位于body底部
// favicon: 'path/to/my_favicon.ico',
//压缩
// minify: {
// removeComments: true,
// collapseWhitespace: true,
// removeAttributeQuotes: true
// // more options:
// // https://github.com/kangax/html-minifier#options-quick-reference
// },
chunksSortMode:'none'
}),
//webpack4 css提取 webpack3用得ExtractTextPlugin
new MinicssExtractPlugin({
filename: 'css/[name].[contenthash].css',
}),
//优化压缩css资源 与vue-cli用的一样
//详细见 http://www.mamicode.com/info-detail-2316064.html
new OptimizeCssAssetsPlugin({
assetNameRegExp: /\.css\.*(?!.*map)$/g,//先行否定断言 .css后面不带 .map
cssProcessorOptions: {
discardComments: { removeAll: true },
safe: true,
autoprefixer: false,//不 处理前缀
},
}),
//固定module id
new webpack.HashedModuleIdsPlugin(),
//固定chunk id
new webpack.NamedModulesPlugin(chunk => {
console.log(chunk);
if (chunk.name) {
return chunk.name;
}
const modules = Array.from(chunk.modulesIterable);
if (modules.length > 1) {
const hash = require("hash-sum");
const joinedHash = hash(modules.map(m => m.id).join("_"));
let len = nameLength;
while (seen.has(joinedHash.substr(0, len))) len++;
seen.add(joinedHash.substr(0, len));
return `chunk-${joinedHash.substr(0, len)}`;
} else {
return modules[0].id;
}
}),
//CopyWebpackPlugin ...
new CopyWebpackPlugin([
{ from: path.join(__dirname, "./static/"), to: path.join(__dirname, "./dist/static") }
]),
new htmlWebpackIncludeAssetsPlugin({
//这里的路径与CopyWebpackPlugin路径对应
assets: [
"/static/ueditor/ueditor.config.js",
"/static/ueditor/ueditor.all.min.js",
"/static/ueditor/lang/zh-cn/zh-cn.js"
],
publicPath: config.publicPath,
append: false//将资源放在其他资源之前
}),
但在我的index.js中无效
<body>
<div id="app"></div>
<script src="https://cdn.bootcss.com/vue/2.6.10/vue.min.js"></script>
<script src="https://cdn.bootcss.com/vuex/3.0.0/vuex.min.js"></script>
<script src="https://cdn.bootcss.com/vue-router/3.0.3/vue-router.min.js"></script>
<script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>
<script src="https://cdn.bootcss.com/iview/3.3.2/iview.min.js"></script>
<script type="text/javascript" src="/js/app.6f5205ca750472aa25c2.js"></script><script type="text/javascript" src="/js/runtime~app.ebb802c9b4e16089f348.js"></script><script type="text/javascript" src="/js/vendor.c7141cc527e864574ed4.js"></script></body>
</html>
没有我想要的静态文件,也没有错误提示