Home  >  Q&A  >  body text

javascript - webpack packaging will package all files under a directory

If configured in the following way, the imported VUE file will only be packaged with the vue I need

import Vue from 'vue'
import vueTap from 'v-tap';
import $ from '@/public/libs/zepto.min';
import pkg from '../package.json';


window.wx = require('@/public/libs/weixin-1.0.0');
window.APP = require('@/public/libs/APP');
window.Share = require('@/public/libs/share');
import '@/public/style/reset.css';

Vue.use(vueTap);
Vue.config.productionTip = false;

const App = require(`@/page/dialog.vue`);

new Vue({
  el: "#app",
  render: h => h(App)
});

But if I want to set the vue files that need to be imported according to the configuration, all vue under the above page directory will be packaged

import Vue from 'vue'
import vueTap from 'v-tap';
import $ from '@/public/libs/zepto.min';
import pkg from '../package.json';


window.wx = require('@/public/libs/weixin-1.0.0');
window.APP = require('@/public/libs/APP');
window.Share = require('@/public/libs/share');
import '@/public/style/reset.css';

Vue.use(vueTap);
Vue.config.productionTip = false;

var templateName = pkg.template;
const App = require(`@/page/${templateName}.vue`);

new Vue({
  el: "#app",
  render: h => h(App)
});

The difference is:
const App = require(@/page/${templateName}.vue);
and
const App = require(@ /page/dialog.vue);

Purpose: According to my configuration, only the configured vue files are packaged each time, and not all vue files are packaged.

代言代言2647 days ago837

reply all(1)I'll reply

  • 漂亮男人

    漂亮男人2017-06-30 09:54:21

    Dynamic dependencies cannot determine the dependencies at compile time, so webpack will try to package all modules that may be referenced to ensure normal runtime.

    Provide two ideas for packaging according to configuration

    1. Write configuration as environment variables instead of program variables.

    2. Achieved through multiple entrances.

    reply
    0
  • Cancelreply