webpack的插件
代码压缩
- 如果不需要自定义压缩的参数,可以使用
./node_modules/.bin/webpack -p
来实现压缩 - 自带的js代码压缩插件:UglifyJSPlugin
示例:
// webpack.config.js中的内容
const path = require('path');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
module.exports = {
entry: './app/index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
},
plugins: [
new UglifyJSPlugin()
]
};
Webpack错误
- 错误一
Invalid configuration object. Webpack has been initialised using a configuration
object that does not match the API schema.
- configuration.resolve.extensions[0] should not be empty.
修改:
resolve: {
extensions: ['', '.js', '.jsx']
},
//删除:'',改为:
resolve: {
extensions: ['.js', '.jsx']
},
- 错误二:
Module not found: Error: Can't resolve 'fsevents' in 'E:\Web\Workspaces\Vue-Component\flexbox-vue\node_modules\chokidar\lib'
@ ./~/chokidar/lib/fsevents-handler.js 7:17-36
@ ./~/chokidar/index.js
@ ./~/watchpack/lib/DirectoryWatcher.js
@ ./~/watchpack/lib/watcherManager.js
@ ./~/watchpack/lib/watchpack.js
@ (webpack)/lib/node/NodeWatchFileSystem.js
@ (webpack)/lib ^.*$
@ (webpack)/lib/webpack.js
@ ./webpack.config.js
@ multi ./src/plugin/index.js ./webpack.config.js
修改:
webpack.config.js中增加:
node: {
fs: "empty"
}
- 错误三
ERROR in ./~/babel-loader/lib!./~/vue-loader/lib/selector.js?type=script&index=0!./src/App.vue
Module not found: Error: Can't resolve 'flexbox-vue' in 'E:\Web\Workspaces\test-marquee-vue\src'
@ ./~/babel-loader/lib!./~/vue-loader/lib/selector.js?type=script&index=0!./src/App.vue 15:0-38
@ ./src/App.vue
@ ./src/main.js
类似于上面这种错误,改为:
webpack --config webpacck.config.js
即可
网友评论