Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use wildcards in Vue Single-File-Components files #35

Open
chamberlainpi opened this issue Jul 12, 2019 · 1 comment
Open

Cannot use wildcards in Vue Single-File-Components files #35

chamberlainpi opened this issue Jul 12, 2019 · 1 comment

Comments

@chamberlainpi
Copy link

Importing a full directory of files only seems to work when the statement is used in a *.js file.
I can at least import other file types (like *.vue files) but unfortunately I'm trying to get the initial import statement to work in a root app.vue file, instead of falling back on importing a separate *.js file that serves as an "includes" file for the directories I need to import.

Example, a folder structure containing:

  • app.vue
    ./ui/
    - button.vue
    - checkbox.vue
    ./views/
    - projects.vue
    - demos.vue

In app.vue:

import * as ui from './ui/*';
import * as views from './views/*';

export default {
        components: _.extend( {}, ui, views ),
 ...
}

I get this error:

Error: Can't resolve './ui/*' in 'D:\path-of-my-project\vue'

@chamberlainpi
Copy link
Author

chamberlainpi commented Jul 12, 2019

In case it helps to identify the issue, here's my Webpack config settings.

{
mode: 'development',

entry: { 'bundle': entry },

output: {
	path: path.resolve( p.dist ),
	filename: "[name].js"
},

module: {
	rules: [
		{
			test: /\.(js|vue)$/, use: { // <-- Could this test be wrong?
				loader: 'babel-loader',
				options: {
					"presets": [
						"@babel/preset-env"
					],
					"plugins": [
						[
							"wildcard",
							{
								"noCamelCase": true,
								"exts": [
									"js",
									"vue"
								]
							}
						]
					]
				}
			}
		},
		{
			test: /\.vue$/, use: {
				loader: 'vue-loader',
				options: {
					loaders: {
						template: 'html-loader',
						js: 'babel-loader',
						//scss: 'vue-style-loader!css-loader!sass-loader?indentedSyntax',
					}
				}
			}
		},
		{ test: /\.scss$/, use: ['vue-style-loader','css-loader','sass-loader'] },
		{ test: /\.css$/, use: ['style-loader', 'css-loader'] },
	]
},

resolve: {
	modules: node_modules,
	alias: {
		'~bpa': p._bpa.root,
		'~bpa-libs': p._bpa.server,
		'~bpa-app': bpaAppPath(),
		'~bpa-common': bpaCommon(),
		'~bpa-vue': bpaCommon( 'vue' ),
		'~bpa-js': bpaCommon( 'js' ),
		'~bpa-css': bpaCommon( 'css' ),
		'~app': appPath(),
		'~vue': appPath( 'vue' ),
		'~js': appPath( 'js' ),
		'~css': appPath( 'css' ),
		'~extensions': p._bpa.server + '/extensions.js',
		'~constants': p._bpa.server + '/constants.js',
		'~libs': p.server,
	}
},

resolveLoader: {
	modules: node_modules,
	alias: {
		'scss-loader': 'sass-loader',
	},
},

optimization: {
	minimize: $$$.env.isProd,
},

plugins: [
	new webpack.DefinePlugin( { ENV: JSON.stringify($$$.env) } )
]
}

Maybe I'm not correctly catching the *.vue and *.js files with my modification to the test regex?
test: /\.(js|vue)$/ should this be changed to something else?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant