easy-team / easywebpack Goto Github PK
View Code? Open in Web Editor NEWA Simple, Powerful Webpack Front-End Development Solution
Home Page: https://easyjs.cn/easywebpack
License: MIT License
A Simple, Powerful Webpack Front-End Development Solution
Home Page: https://easyjs.cn/easywebpack
License: MIT License
重现步骤:
结果,报 TypeError 错误
D:\lab\easywebpack\01\node_modules\webpack-tool\lib\tool.js:115
compiler.plugin('done', compilation => {
^
TypeError: compiler.plugin is not a function
at WebpackTool.build (D:\lab\easywebpack\01\node_modules\webpack-tool\lib\to
ol.js:115:14)
at Object.exports.build (D:\lab\easywebpack\01\node_modules\easywebpack\inde
x.js:47:28)
at build (D:\lab\easywebpack\01\node_modules\easywebpack-cli\lib\builder.js:
87:13)
at Object.exports.build (D:\lab\easywebpack\01\node_modules\easywebpack-cli\
lib\builder.js:100:10)
at Command.program.command.description.action.env (D:\lab\easywebpack\01\nod
e_modules\easywebpack-cli\bin\cli.js:108:13)
at Command.listener (D:\lab\easywebpack\01\node_modules\commander\index.js:3
15:8)
at emitTwo (events.js:126:13)
at Command.emit (events.js:214:7)
at Command.parseArgs (D:\lab\easywebpack\01\node_modules\commander\index.js:
目前 extract-text-webpack-plugin
最新版本不支持 Webpack 4.3.0 版本. Webpack 4.2.0 一下可用。
目前从 extract-text-webpack-plugin issues 了解, 未来 extract-text-webpack-plugin 将废弃,作者建议使用 mini-css-extract-plugin
easywebpack 工程化方案近期会适配。
easywebpack 4 依赖的 webpack(webpack-tool) 目前已锁定 Webpack 4.2.0 版本
如题.
我的项目根据需要必须用多个html片段组成页面,片段的引用都是按路径读取磁盘的文件,导致在dev环境下开发没得搞(找不到文件)
nodejs.Error: read webpack memory file[/Users/xxx/Documents/xxx/chasing_the_wind/app/view/index.js] content is empty, please check if the file exists at /Users/xxx/Documents/xxx/chasing_the_wind/node_modules/egg-webpack-react/app.js:20:17 at Generator.next (<anonymous>) at onFulfilled (/Users/chuans/Documents/chuans/chasing_the_wind/node_modules/co/index.js:65:19) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7)
这个是目前报错的信息,但是我如果吧tsx的后缀改成js或者jsx 一切正常,请问下 这个是什么问题呢
https://doc.webpack-china.org/configuration/node/#node-console
按照以下方法
https://github.com/eggjs/egg-sequelize/tree/master/test/fixtures/apps/model-app
想测试egg-sequelize model的配置
但是发现easywebpack生成的package.json没有包含egg-bin的命令
求解惑
你好,请问下如何解决,单页应用,直接在地址栏输入地址回车出现404的问题呢 ?
可以使用webpack-node-externals,省的生成一个很长很长的node_modules模块list
entryFile
这个变量一般是 babel-loader!xxx-loader!index.vue
的形式
entryTemplate = replace(/vue$/, 'html')
导致entryTemplate路径不存在
也就导致html-webpack
使用不了相对路径自定义的template
ERROR in Entry module not found: Error: Can't resolve 'thread-loader'
请教下entry.loader是怎么实现的
直接用 include: [ 'page/*/index.vue' ]
glob
表达式配置include会不会清晰灵活一点
复现步骤
新手问题,请多包涵。
easywebpack 工程化方案 dependencies
内置常用的 loader
和 plugin
,部分默认禁用的loader
和 plugin
是没有内置到 dependencies
里面,当开启时,需要用户手动安装依赖。
install:{
npm: 'npm', // 默认是 npm, 可以是 cnpm
check: true // 默认为禁用,自动安装缺少的 loader 和 plugin,建议首次 运行成功后,改成 false,加快构建速度
},
easywebpack-cli
已支持 easy install --mode cnpm
安装缺失的依赖
代码:
https://github.com/hubcarl/easywebpack/blob/master/lib/base.js#L337
https://github.com/hubcarl/easywebpack/blob/master/lib/base.js#L408
https://github.com/hubcarl/easywebpack/blob/master/lib/base.js#L377
使用portfinder
查询当前端口是否可用 不可用则返回一个新端口 然后把新的端口号赋给webpack
How can i add additional scripts in easywebpack-vue-ssr Render function
I want to add an additional Js ( vconsole.js ) just for some specified users. So i want to add some string in ssr renderString. Is there an option just like vue-ssr renderToString function in easy-webpack-vue render function ? Thx.
add additional scripts in vue-ssr
const renderer = vueSSR.createBundleRenderer(// ...);
const html = await renderer.renderToString({
links: `
<script src="/dist/vconsole.min.js"></script>
<script>
var vConsole = new VConsole( );
</script>
`
})
easy-webpack-vue-ssr
async index() {
await this.ctx.render('app/app.js', {
url: this.ctx.url.replace(/\/app/, '')
// how can i add my additioanl scripts here
});
}
'use strict';
const path = require('path');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const optimizeCssAssets = require('optimize-css-assets-webpack-plugin');
const Oss = require('./plugins/oss');
module.exports = {
egg: true,
framework: 'vue',
entry: {
include: ['app/web/page'],
exclude: ['app/web/page/[a-z]+/(component|store)'],
loader: {
client: 'app/web/framework/vue/entry/client-loader.ts',
server: 'app/web/framework/vue/entry/server-loader.ts'
}
},
// publicPath: process.env.NODE_ENV === 'production' ? 'https://cdn.dooprime.com/clearing-website/dist/' : '/public/',
alias: {
server: 'app/web/framework/vue/entry/server.ts',
client: 'app/web/framework/vue/entry/client.ts',
component: 'app/web/component',
framework: 'app/web/framework',
},
dll: ['vue'],
loaders: {
typescript: true,
less: true,
stylus: true
},
plugins: {
vueLoader: {
name: new VueLoaderPlugin()
},
optimizeCssAssets: {
name: new optimizeCssAssets(),
env: ['prod']
}
}
};
在4.10.0版本中发现process is not defined,使用process的是_process-nextick-args@2.0.0@process-nextick-args 这个插件,使用这个插件的是cheerio插件
环境部署项目的时候想指定vendor.js
类似我想编译成这样
/xxx.html
/aaa.html
/static/js/xx.js
/static/css/css.js
感觉自己脑洞不够大。。在不改程序,现有逻辑下自己绕不过去
These global enviroment is undefined
// .vue
console.log( EASY_ENV_IS_DEV ) // undefined
有golang+vue+easywebpack+ssr的demo吗?
是不是不支持reactssr的配置项啊,,,我在项目通过注释的写法
/* webpackChunkName: "show" */ 去异步引入组件 渲染是可以渲染 但是还是渲染到目录为enrty ssr.js�里面了,并没有chunk?????生成 我webpack.config.js 也配置了也不行。。。。
我需要改变html输出的目录
entry: 'app/web/**/*.js',
output: {
path: path.resolve(__dirname, 'app/public'),
publicPath: 'public',
},
plugins: {
html: {
minify: false,
filename: path.resolve('./app/view/[name].html')
},
},
配置后输出的文件名变成了0,1,2这种,我怎么用entry的js文件名作为html文件名(不更改l输出目录默认是用的entry的js文件名),就是[name]那个地方怎么取
在构建时现在会提示很多的警告信息
Replace Autoprefixer browsers option to Browserslist config.
Use browserslist key in package.json or .browserslistrc file.
Using browsers option cause some error. Browserslist config
can be used for Babel, Autoprefixer, postcss-normalize and other tools.
If you really need to use option, rename it to overrideBrowserslist.
Learn more at:
https://github.com/browserslist/browserslist#readme
https://twitter.com/browserslist
问题在于easywebpack中config/postcss.config.js
文件中需要将配置进行升级
module.exports = {
plugins: [
require('autoprefixer')({ browsers: ['iOS >= 7', 'Android >= 4.0'] })
]
}
更新为:
module.exports = {
plugins: [
require('autoprefixer')({ overrideBrowserslist: ['iOS >= 7', 'Android >= 4.0'] })
]
}
前端vue的东西修改发生热更新,过一段时间之后报错如下。
看网上的方案是在dev的时候加上node --max_old_space_size=4096
。
但是只能延缓出现这个错误的时间。
暂时的解决方法就是重启dev。
感觉很繁琐,有没有更好的办法解决一下。
看了vue-cli生成的项目不会出现这个问题,所以是否可以借鉴下它的内部是如何运作热更新释放内存中的资源。
<--- Last few GCs --->
[9680:00000227BACCE0F0] 65343019 ms: Mark-sweep 4062.1 (4159.1)
-> 4062.1 (4159.6) MB, 387.6 / 0.0 ms allocation failure GC in
old space requested
[9680:00000227BACCE0F0] 65343350 ms: Mark-sweep 4062.1 (4159.6)
-> 4062.0 (4126.6) MB, 330.4 / 0.0 ms last resort GC in old space requested
[9680:00000227BACCE0F0] 65343678 ms: Mark-sweep 4062.0 (4126.6)
-> 4062.0 (4125.1) MB, 328.1 / 0.0 ms last resort GC in old space requested
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 00000069B2A257C1 <JSObject>
1: stringSlice(aka stringSlice) [buffer.js:560] [bytecode=000001C5AA852929 offset=94](this=0000000D73E022D1 <undefined>,buf=0000013E51013641 <Uint8Array map = 000001BB71136601>,encoding=00000069B2A34EB1 <String[4]: utf8>,start=0,end=500637)
2: toString [buffer.js:633] [bytecode=000001C5AA852579 offset=145](this=0000013E51013641 <Uint8Array map = 000001BB71136601>,encoding=00000069B2A34...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript
heap out of memory
1: node_module_register
2: v8::internal::FatalProcessOutOfMemory
3: v8::internal::FatalProcessOutOfMemory
4: v8::internal::Factory::NewRawTwoByteString
5: v8::internal::Factory::NewStringFromUtf8
6: v8::String::NewFromUtf8
7: v8_inspector::V8InspectorClient::currentTimeMS
8: node::Buffer::New
9: v8::internal::wasm::SignatureMap::Find
10: v8::internal::Builtins::CallableFor
11: v8::internal::Builtins::CallableFor
12: v8::internal::Builtins::CallableFor
13: 000003D3A46843C1
package.json
...
{
"scripts": {
...
"dev": "npm run tsc:w && node --max_old_space_size=4096 index.js"
...
}
"dependencies": {
"axios": "^0.18.0",
"countup": "^1.8.2",
"egg": "^2.7.1",
"egg-cors": "^2.0.0",
"egg-logger": "^1.6.2",
"egg-scripts": "^2.6.0",
"egg-validate": "^1.0.0",
"egg-view-vue-ssr": "^3.0.8",
"extend": "~3.0.1",
"iview": "^2.13.1",
"iview-area": "^1.5.17",
"js-cookie": "^2.2.0",
"jsbarcode": "^3.9.0",
"lodash": "^4.17.5",
"moment": "^2.22.1",
"mysql": "^2.15.0",
"reflect-metadata": "^0.1.12",
"server-side-render-resource": "^1.0.3",
"tinymce": "^4.7.11",
"typeorm": "^0.2.1",
"vue": "^2.5.16",
"vue-hot-reload-api": "^2.3.0",
"vue-router": "^3.0.1",
"vue-server-renderer": "^2.5.16",
"vue-virtual-scroller": "^0.11.7",
"vuex": "^3.0.1",
"vuex-router-sync": "^5.0.0"
},
"devDependencies": {
"autod-egg": "^1.1.0",
"autoprefixer": "^8.3.0",
"babel-core": "^6.26.0",
"babel-helper-vue-jsx-merge-props": "^2.0.3",
"babel-loader": "^7.1.4",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-jsx-v-model": "^2.0.3",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"babel-plugin-syntax-jsx": "^6.18.0",
"babel-plugin-transform-object-assign": "^6.22.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-plugin-transform-vue-jsx": "^3.7.0",
"babel-preset-env": "^1.6.1",
"canvas": "^1.6.10",
"cross-env": "^5.1.4",
"cz-conventional-changelog": "^2.1.0",
"directory-named-webpack-plugin": "^2.3.0",
"easywebpack-cli": "^3.11.1",
"easywebpack-vue": "^4.0.4",
"egg-logview": "^2.0.0",
"egg-webpack": "^4.1.1",
"egg-webpack-vue": "^2.0.1",
"eslint": "^4.19.1",
"eslint-config-standard": "^11.0.0",
"eslint-loader": "^2.0.0",
"eslint-plugin-import": "^2.11.0",
"eslint-plugin-node": "^6.0.1",
"eslint-plugin-promise": "^3.7.0",
"eslint-plugin-standard": "^3.0.1",
"eslint-plugin-vue": "^2.1.0",
"imagemin-webpack-plugin": "^2.1.1",
"ip": "^1.1.5",
"postcss-loader": "^2.1.4",
"progress-bar-webpack-plugin": "^1.11.0",
"pug": "^2.0.3",
"stylus": "^0.54.5",
"stylus-loader": "^3.0.2",
"ts-loader": "^4.2.0",
"tslint": "^5.9.1",
"tslint-loader": "^3.6.0",
"typescript": "^2.8.3",
"uglifyjs-webpack-plugin": "^1.2.5",
"vconsole": "^3.2.0",
"vue-template-compiler": "^2.5.16",
"webpack-manifest-resource-plugin": "^4.2.3"
}
...
}
Line 242 in e2bc0a8
https://github.com/hubcarl/easywebpack/blob/master/utils/utils.js#L88
在我电脑上,这里 path.posix.join 返回结果为
temp/cache.json
对应 path.win32.join 返回结果为
D:\codes\egg-vue-webpack-boilerplate\node_modules\easywebpack-vue\node_modules\easywebpack\temp\cache.json
上面那个会导致找不到 module
就像我之前提的 pr 一样,一开始也是把 path 换成 path.posix,马上发现没这么简单。
win32 下我遇到的主要问题在于 entry 的路径,参见 https://github.com/jacksky007/easywebpack/blob/master/utils/utils.js#L53
支持nodejs 8.x么??
我试着用webpack4的 splitChunks及 easywebpack的 pack 以及 dll都实现不了
例子是 egg-vue-webpack-boilerplate element.vue中把element-ui 单独打包成公用elementUi.js 使得router.vue 和 element.vue可以复用
easywebpack-vue开发环境(npm run dev)中怎么打开静态资源,比如我上传了一个文件保存到/public目录下和app/public下都无法打开;但是在(npm run start)中就可以打开。需要在哪个文件设置?
html: {
minify: false,
template: path.resolve(__dirname, 'app/web/page/[entryName]/[entryName].js')
},
多页面怎么自定义template,就是entryName那个地方怎么才能拿到入口文件的名称(在配置文件中)
你好,我的项目中没有开启service-worker 但是 还是会有
http://localhost:7001/service-worker.8ddbbade.js 这样的请求出现,是什么原因呢?
webpack.config.js
plugins: {
serviceworker: false
},
plugin.local.js
exports.webpack = {
enable: true,
package: 'egg-webpack'
};
exports.webpackvue = {
enable: true,
package: 'egg-webpack-vue'
};
提交了合并,不知是否这样修复这个 Bug
node_modules/easywebpack-vue/node_modules/easywebpack/index.js:13
exports.getConfig = config => require('./lib/config')(config);
^
TypeError: Class constructor Config cannot be invoked without 'new'
webpack.config.js
{ egg: true, framework: 'vue', publicPath: 'http://xxx.cdn.com/public/', ... }
报错:
`yarn build
yarn run v1.9.4
$ easywebpack build prod
clean-webpack-plugin: /Users/xxx/public has been removed.
webpack build [========== ] 10% (0.0 seconds){ parser: "babylon" } is deprecated; we now treat it as { parser: "babel" }.
webpack build [====================================================================================================] 100% (15.8 seconds)
Build completed in 15.771s
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.`
打包出来的mainfest.json
{ "app.css": "http://xxx.cdn.com/public/css/app.c2131bfb.css", "app.js": "http://xxx.cdn.com/public/js/chunk/app.3024194f.js", "runtime.js": "http://xxx.cdn.com/public/js/runtime.cdf3621f.js", "font/iconfont.css": "http://xxx.cdn.com/public/font/iconfont.ba9be85f.woff", "img/default-avatar.png": "http://xxx.cdn.com/public/img/default-avatar.bf66d842.png", "img/user-menu.vue": "http://xxx.cdn.com/public/img/icon-yixinli.61229039.png", "img/iconfont.css": "http://xxx.cdn.com/public/img/iconfont.d2a86037.svg", "img/list.vue": "http://xxx.cdn.com/public/img/no-artical.19d06407.png", "img/theme-entry.png": "http://xxx.cdn.com/public/img/theme-entry.619bb2b3.png", "vendor.js": "/public/js/vendor.1d4da928.js", "deps": { "app.js": { "js": [ "/public/js/vendor.1d4da928.js", "http://xxx.cdn.com/public/js/runtime.cdf3621f.js", "http://xxx.cdn.com/public/js/chunk/app.3024194f.js" ], "css": [ "http://xxx.cdn.com/public/css/app.c2131bfb.css" ] } }, "info": { "publicPath": "http://xxx.cdn.com/public/", "buildPath": "public", "mapped": true } }
报错后文件根目录public文件夹丢失。
cdn配置项也是如此
Line 37 in 54f3cf8
这个地方的merge最终会导致webpack.config.js定义的Loader加两次
例如webpack.config.js配置:
// webpack.config.js
loaders: {
html: {
test: /\.html$/,
use: [
{
loader: 'html-loader',
options: {
interpolate: 'require', // supported html `${}` sytax
attrs: [ ':src' ],
},
},
],
},
}
最终的结果:
小图片我们会使用url-loader让它直接base64,但有一些图片压缩前很大,imagemin之后很小,这些文件如果用imagemin-webpack-plugin它不会base64,因为loader在plugin之前执行,url-loader limit比较的是压缩前的大小,发布出去发现有很多小图片
可以这样:
urlimage: {
use: [
{
loader: 'url-loader',
options: {
limit: 1024 * 5,
fallback: 'file-loader',
// img output path
name: `img/[name].[hash:8].[ext]`,
},
},
{
loader: 'image-webpack-loader',
},
],
},
no label version , both webpack2 and webpack3 support
plugins: [
{
html: false
},
{
env: 'prod',
name: new CleanWebpackPlugin('app/view')
},
new HtmlWebpackPlugin({template, filename, minify, hash, inject, chunks}),
new HtmlWebpackPlugin({template, filename, minify, hash, inject, chunks}),
new HtmlWebpackPlugin({template, filename, minify, hash, inject, chunks})
]
类似这样我把easywebpack的增强配置html禁用掉,配上原生的HtmlWebpackPlugin,就只会生成最后一条配置的html,前面两个就没生成出html文件
弄了半天没天明白这玩意怎么配,这文档写给牛看的
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.