Files
Igor Randjelovic 575130c712 feat: external config loading
+refactor many pieces
2021-03-02 20:23:04 -08:00

56 lines
1.4 KiB
TypeScript

import base from './base';
import Config from 'webpack-chain';
import { VueLoaderPlugin } from 'vue-loader';
import { env as _env, IWebpackEnv } from '../index';
import { merge } from 'webpack-merge';
import { getPlatform } from '../helpers/project';
export default function (config: Config, env: IWebpackEnv = _env): Config {
base(config, env);
const platform = getPlatform();
// resolve .vue files
// the order is reversed because we are using prepend!
config.resolve.extensions.prepend('.vue').prepend(`.${platform}.vue`);
// add a rule for .vue files
config.module
.rule('vue')
.test(/\.vue$/)
.use('vue-loader')
.loader('vue-loader')
.tap((options) => {
return {
...options,
// todo: should be a compiler object
// but we want it as an external dependency
compiler: 'nativescript-vue-template-compiler',
};
})
.end();
// set up ts support in vue files
config.module
.rule('ts')
.use('ts-loader')
.loader('ts-loader')
.tap((options = {}) => {
return merge(options, {
appendTsSuffixTo: ['\\.vue$'],
});
});
// add VueLoaderPlugin as the first plugin
config
.plugin('VueLoaderPlugin')
// @ts-ignore
.before(config.plugins.values()[0].name)
.use(VueLoaderPlugin);
// add an alias for vue, since some plugins may try to import it
config.resolve.alias.set('vue', 'nativescript-vue');
return config;
}