Webpack

VueJs + Webpack lazyload modules from ElementUI

巧了我就是萌 提交于 2020-12-29 06:41:36
问题 I would like to lazy-load a specific element of ElementUI in a Vue component. I tried this: import { Tree } from /* webpackChunkName : "element-ui" */ 'element-ui'; Vue.component(Tree.name, Tree); Vue.use(Tree); And this: { components: { 'el-tree': () => import(/* webpackChunkName : "element-ui" */ "element-ui").then(({Tree}) => Tree) } } But in both cases, the element-ui.js chunk file is not created, and the full library is inserted into the main.js file instead. How do I dynamically import

VueJs + Webpack lazyload modules from ElementUI

丶灬走出姿态 提交于 2020-12-29 06:41:35
问题 I would like to lazy-load a specific element of ElementUI in a Vue component. I tried this: import { Tree } from /* webpackChunkName : "element-ui" */ 'element-ui'; Vue.component(Tree.name, Tree); Vue.use(Tree); And this: { components: { 'el-tree': () => import(/* webpackChunkName : "element-ui" */ "element-ui").then(({Tree}) => Tree) } } But in both cases, the element-ui.js chunk file is not created, and the full library is inserted into the main.js file instead. How do I dynamically import

Create React App V2 - Multiple entry points

心已入冬 提交于 2020-12-29 03:50:21
问题 I'm trying to build a React app with 2 entry points, one for the App and one for the Admin panel. I'm starting with Create React App V2 and following this gitHub issue thread https://github.com/facebook/create-react-app/issues/1084 and this tutorial http://imshuai.com/create-react-app-multiple-entry-points/. I'm trying to port the instructions for adding multiple entry points from CRA V1 to work in V2 but I think I am missing something. After ejecting CRA, these are the paths I've changed

Create React App V2 - Multiple entry points

荒凉一梦 提交于 2020-12-29 03:49:11
问题 I'm trying to build a React app with 2 entry points, one for the App and one for the Admin panel. I'm starting with Create React App V2 and following this gitHub issue thread https://github.com/facebook/create-react-app/issues/1084 and this tutorial http://imshuai.com/create-react-app-multiple-entry-points/. I'm trying to port the instructions for adding multiple entry points from CRA V1 to work in V2 but I think I am missing something. After ejecting CRA, these are the paths I've changed

Create React App V2 - Multiple entry points

落花浮王杯 提交于 2020-12-29 03:48:05
问题 I'm trying to build a React app with 2 entry points, one for the App and one for the Admin panel. I'm starting with Create React App V2 and following this gitHub issue thread https://github.com/facebook/create-react-app/issues/1084 and this tutorial http://imshuai.com/create-react-app-multiple-entry-points/. I'm trying to port the instructions for adding multiple entry points from CRA V1 to work in V2 but I think I am missing something. After ejecting CRA, these are the paths I've changed

初始化构建React+Ts项目时出现:Module build failed (from ./node_modules/css-loader/dist/cjs.js): CssSyntaxError

风流意气都作罢 提交于 2020-12-29 03:13:40
具体错误 ERROR in ./src/index.tsx Module build failed (from ./node_modules/css-loader/dist/cjs.js): CssSyntaxError (2:1) Unknown word var content = require("!!./index.tsx"); if(typeof content === 'string') content = [[module.id, content, '']] webpack.config.js const path = require("path"); const HtmlWebpackPlugin = require("html-webpack-plugin"); function resolve(dir) { return path.join(__dirname, dir); } module.exports = { entry: path.join(__dirname, "../src/index.tsx"), output: { filename: "bundle.js", path: path.join(__dirname, "dist") }, module: { rules: [ { test: /\.js$/, use: ["babel-loader"

详解Vue前端生产环境发布配置实战篇

二次信任 提交于 2020-12-29 01:57:58
前言 首先这篇文章是写给Vue新手的,老司机基本不用看了。 当我们刚接触vue的时候,特别是对于第一次用前端框架的同学来说,心情可以说是比较激动的,框架带来的种种新体验,是以前jQuery无法给你的兴奋和满足感。但是在体验了几个demo的新鲜感之后,我们就要考虑如何把框架结合到我们实际的开发中如何应用的问题了。 下面我主要总结三个和生产发布相关的问题:资源文件发布文件夹配置,图片文件的引用,以及后台接口调试方法。 一,资源文件发布配置 一般项目都是用vue-cli脚手架搭建项目,然后编写自己的代码。vue-cli脚手架生成的配置,默认资源文件都在static文件夹下面,build发布的js和css文件也是在static文件夹下面,index.html文件则是和static形成相对路径关系。 而实际我们的生产发布环境中,页面文件和资源文件不一定在同一目录下,页面文件和js,css文件也不在同一目录下。 以php的Yii2环境为例,页面文件一般都放在views文件夹,页面访问路径可能是 “http://xxxx.com/index.php/sales-task/create ” 这样的url形式。而js,css,image等资源文件则需要放在web文件夹下,访问路径则是从根目录开始访问的。如果在web目录下新建static文件夹,访问路径是 “http://freelancer

vue异步组件

浪子不回头ぞ 提交于 2020-12-28 20:01:17
路由懒加载 当打包构建应用时,Javascript 包会变得非常大,影响页面加载速度。如果我们能把不同路由对应的组件分割成不同的代码块,然后当路由被访问的时候才加载对应组件,这样就更加高效了。 结合 Vue 的 异步组件 和 Webpack 的 代码分割功能 ,轻松实现路由组件的懒加载。如: const Foo = () => import('./Foo.vue')    异步组件 在大型应用中,我们可能需要将应用分割成小一些的代码块,并且只在需要的时候才从服务器加载一个模块。为了简化,Vue 允许你以一个工厂函数的方式定义你的组件,这个工厂函数会异步解析你的组件定义。Vue 只有在这个组件需要被渲染的时候才会触发该工厂函数,且会把结果缓存起来供未来重渲染。例如: Vue.component('async-example', function (resolve, reject) { setTimeout(function () { // 向 `resolve` 回调传递组件定义 resolve({ template: '<div>I am async!</div>' }) }, 1000) })   如你所见,这个工厂函数会收到一个 resolve 回调,这个回调函数会在你从服务器得到组件定义的时候被调用。你也可以调用 reject(reason) 来表示加载失败。这里的

webpack的插件 http-webpack-plugin。 webpack-dev-server

删除回忆录丶 提交于 2020-12-26 10:08:56
自动的生成: bundle.js 和 index.html 在该项目的目录下: npm init -yes npm install vue -D npm install webpack@3.12.0 -D npm install css-loader -D; npm install style-loader -D npm install http-webpack-plugin npm install http-server “dev”:"webpack" 一定要配置上, 这样才能使用。 npm run dev dev名字可以随便换无所谓。 出口这里的这个 path: path. resolve( './dist') , 就是一个相对路径转绝对绝对路径 然后再去拼接后面的 ./bundle.js文件的。 这里的这个index.html 只是一个参照物。 让 html-webpack-plugin 参照这个, 取到dist目录下生成 index.html npm install -g http-server 这个东西就是用来做一些测试的。需要注意的就是 -g 要下载到全局去。 使用: hs -o -p 9999 (9999 是端口号) webpack-dev-server 生成环境下的,一个插件 npm install webpack-dev-server@2.9.0 -D 目录结构,

深入解析webpack 插件html-webpack-plugin

强颜欢笑 提交于 2020-12-26 10:08:42
这个插件用来简化创建服务于 webpack bundle 的 HTML 文件,尤其是对于在文件名中包含了 hash 值,而这个值在每次编译的时候都发生变化的情况。你既可以让这个插件来帮助你自动生成 HTML 文件,也可以使用 lodash 模板加载生成的 bundles,或者自己加载这些 bundles。 Installation 使用 npm 安装这个插件 $ npm install html-webpack-plugin@2 --save-dev Basic Usage 这个插件可以帮助生成 HTML 文件,在 body 元素中,使用 script 来包含所有你的 webpack bundles,只需要在你的 webpack 配置文件中如下配置: var HtmlWebpackPlugin = require('html-webpack-plugin') var webpackConfig = { entry: 'index.js', output: { path: 'dist', filename: 'index_bundle.js' }, plugins: [new HtmlWebpackPlugin()] } 这将会自动在 dist 目录中生成一个名为 index.html 的文件,内容如下: <!DOCTYPE html> <html> <head> <meta