本文主要是介绍webpack多入口文件的配置及输出,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
目录:
common.js:
export const common = '公共的文件';
main1.js:
import Vue from 'vue';
import {common} from './common.js';console.log(Vue, 'main1${common}');
main2.js:
import Vue from 'vue';
import { common } from './common.js';console.log(Vue, 'main2${common}');
webpack.config.js:
const path = require('path');module.exports = {// 入口文件entry: {// 多入口'main1': './src/main1.js','main2': './src/main2.js'},// 出口文件output: {path: path.resolve('./dist'), //相对转绝对filename: '[name].js'},// 文件监视改动,自动产出build.jswatch: true
}
package.json:
{"name": "03es6","version": "1.0.0","description": "","main": "index.js","scripts": {"test": "echo \"Error: no test specified\" && exit 1","build": "webpack-dev-server --open --hot --inline","dev": "webpack"},"keywords": [],"author": "","license": "ISC","devDependencies": {"babel-core": "^6.26.3","babel-loader": "^7.1.5","babel-plugin-transform-runtime": "^6.23.0","babel-preset-env": "^1.7.0","css-loader": "^0.28.11","html-webpack-plugin": "^2.24.1","style-loader": "^0.23.1","vue": "^2.6.14","vue-loader": "^14.1.1","vue-template-compiler": "^2.5.17","webpack": "^3.12.0","webpack-dev-server": "^2.10.0"},"dependencies": {"vue": "^2.6.14"}
}
终端执行:npm run dev,生成dist文件夹:
存在的问题:main1.js、main2.js中均包含vue.js第三方库和common.js公共组件,文件大,加载慢。
这篇关于webpack多入口文件的配置及输出的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!