javascript - webpack packaging will package all files under a directory
代言
代言 2017-06-30 09:52:21
0
1
813

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.

代言
代言

reply all (1)
漂亮男人

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.

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!