T
T
thehighhomie2019-05-01 13:04:04
Node.js
thehighhomie, 2019-05-01 13:04:04

VueJS: Import global?

How to attach global imports to vue cli?
https://github.com/terpiljenya/import-glob#readme
I couldn't set up vue.config.js correctly

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
ned4ded, 2019-05-01
@ned4ded

Good afternoon!
Content vue.config.js:

module.exports = {
  configureWebpack: {
    module: {
      rules: [{
          test: /\.js/,
          loader: 'import-glob'
        },
        {
          test: /\.scss/,
          loader: 'import-glob'
        }
      ]
    }
  }
}

src folder:
src/
├── App.vue
 ...
│   
├── lib
│   ├── example
│   │   └── example.js # example2
│   └── example.js # example1
└── main.js

In the example.js files, by default, a function is exported, the call of which writes the name of the function to the browser console.
App.vue content
// inside script tag
import modules from './lib/**/*.js'

const [module0, module1] = modules

module0.default()
module1.default()

// example1
// example2

To import vue files, you will need to add test, I inserted the config from the library repository, but it can be written in a compact way (again, by rewriting the test field).
You should put the webpack tag, your question is not directly related to vue, and nothing to do with node.

T
thehighhomie, 2019-05-02
@thehighhomie

I did the same as in your example.
Does not work:

* ./actions/*.js in ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_mo
dules/vue-loader/lib??vue-loader-options!./src/App.vue?vue&type=script&lang=js&

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question