Currently there is no way to import new webpack plugins to the vue.config.js. At least not that I know of. Please enlighten me if I'm mistaken.
My use case is that I've made modifications to an already existing webpack plugin, and I want to use my version instead.
// vue.config.js
import NameOfPlugin from 'path/to/plugin';
module.exports = {
configureWebpack: {
plugins: [
new NameOfPlugin()
]
}
};
This is already possible, see the docs.
Thanks for the answer!
After some more tests I've come to the result that it works with require, but not import.
Is this expected?
It's not clear to me why import will not work. My understanding is that import generally is the recommended way to include modules, but perhaps this is not the case?
Doesn't work:
import PreloadPlugin from '../preload-webpack-plugin';
Seems to work (although i have yet to confirm that the plugin is properly loaded):
const PreloadPlugin = require('../preload-webpack-plugin')
Using the import statement gives an error as:
Unexpected token import
vuejs.config.js is a file executed by vue-cli and thus nodejs (which doesn't support import/export syntax yet).
I see. Thanks for the clarification!
The original docs file linked by @Akryum has moved here: https://github.com/vuejs/vue-cli/blob/dev/docs/guide/webpack.md
Im litle bit confuse, docs say is finer use chainWebpack rather then use configureWebpack or there some options is better with chainWebpack and there some options like adding plugin is better with configureWebpack. what better to use?
Most helpful comment
The original docs file linked by @Akryum has moved here: https://github.com/vuejs/vue-cli/blob/dev/docs/guide/webpack.md