2021-09-27 12:49:36 +00:00
|
|
|
import { resolve } from 'pathe'
|
2021-10-02 16:01:17 +00:00
|
|
|
import VueLoaderPlugin from 'vue-loader/dist/pluginWebpack5.js'
|
|
|
|
import webpack from 'webpack'
|
2020-09-02 12:27:27 +00:00
|
|
|
import VueSSRClientPlugin from '../plugins/vue/client'
|
|
|
|
import VueSSRServerPlugin from '../plugins/vue/server'
|
2022-12-11 21:44:52 +00:00
|
|
|
import type { WebpackConfigContext } from '../utils/config'
|
2020-09-02 12:27:27 +00:00
|
|
|
|
|
|
|
export function vue (ctx: WebpackConfigContext) {
|
|
|
|
const { options, config } = ctx
|
|
|
|
|
2021-10-02 16:01:17 +00:00
|
|
|
// @ts-ignore
|
|
|
|
config.plugins.push(new (VueLoaderPlugin.default || VueLoaderPlugin)())
|
2020-09-02 12:27:27 +00:00
|
|
|
|
2022-08-26 15:47:29 +00:00
|
|
|
config.module!.rules!.push({
|
2020-09-02 12:27:27 +00:00
|
|
|
test: /\.vue$/i,
|
|
|
|
loader: 'vue-loader',
|
2022-03-17 22:17:59 +00:00
|
|
|
options: {
|
|
|
|
reactivityTransform: ctx.nuxt.options.experimental.reactivityTransform,
|
|
|
|
...options.webpack.loaders.vue
|
|
|
|
}
|
2020-09-02 12:27:27 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
if (ctx.isClient) {
|
2022-08-26 15:47:29 +00:00
|
|
|
config.plugins!.push(new VueSSRClientPlugin({
|
2022-08-16 11:19:39 +00:00
|
|
|
filename: resolve(options.buildDir, 'dist/server', `${ctx.name}.manifest.json`),
|
|
|
|
nuxt: ctx.nuxt
|
2020-09-02 12:27:27 +00:00
|
|
|
}))
|
|
|
|
} else {
|
2022-08-26 15:47:29 +00:00
|
|
|
config.plugins!.push(new VueSSRServerPlugin({
|
2020-09-02 12:27:27 +00:00
|
|
|
filename: `${ctx.name}.manifest.json`
|
|
|
|
}))
|
|
|
|
}
|
2020-09-21 13:26:48 +00:00
|
|
|
|
|
|
|
// Feature flags
|
|
|
|
// https://github.com/vuejs/vue-next/tree/master/packages/vue#bundler-build-feature-flags
|
|
|
|
// TODO: Provide options to toggle
|
2022-08-26 15:47:29 +00:00
|
|
|
config.plugins!.push(new webpack.DefinePlugin({
|
2020-09-21 13:26:48 +00:00
|
|
|
__VUE_OPTIONS_API__: 'true',
|
|
|
|
__VUE_PROD_DEVTOOLS__: 'false'
|
|
|
|
}))
|
2020-09-02 12:27:27 +00:00
|
|
|
}
|