hzsrc / js-conditional-compile-loader Goto Github PK
View Code? Open in Web Editor NEWA javascript conditional compile loader for webpack. 一个javascript条件编译的webpack loader。
License: MIT License
A javascript conditional compile loader for webpack. 一个javascript条件编译的webpack loader。
License: MIT License
Hi, I'm trying to get compiled different versions depending on some runtime values and I found this plugin very usefull, but I think I have found a bug.
When using this plugin on several webpack config objects, the output bundles always match the first of the passed objects.
For example this config object was always creating bundles matching the first of the objects in the array (page1):
module.exports = [
{
entry: {
page1: "./src/index.js",
},
...
module: {
rules: [
{
loader: "js-conditional-compile-loader",
options: {
gallery: false,
hero: true,
slider: false,
},
},
],
},
},
{
entry: {
page2: "./src/index.js",
},
...
module: {
rules: [
{
loader: "js-conditional-compile-loader",
options: {
gallery: false,
hero: true,
slider: true,
},
},
],
},
},
{
entry: {
page3: "./src/index.js",
},
...
module: {
rules: [
{
loader: "js-conditional-compile-loader",
options: {
gallery: true,
hero: false,
slider: false,
},
},
],
},
},
];
After debugging a little the code of the loader, I found that in the index.js file, the options variable is defined outside of the exported function, it's always taking the value of the first call done to it, and not taking the passed config on succesive executions. This gets solved by removing the if on line #7.
Hope you find this useful.
Cheers!
option如下配置的话,可以在代码里设置多个条件编译吗
{
ALI:true,
TENCENT: true
}
/* IFTRUE_ALI */
console.log('ali')
/* FITRUE_ALI */
/* IFTRUE_TENCENT */
console.log('TENCENT')
/* FITRUE_TENCENT*/
比如 IF_NOTTRUE_xxxx
What about the Else case
请问json的条件编译是不支持吗?
/* IFDEBUG */
/* IFTRUE_envTest */
import xx from 'test.debug.js'
/* FITRUE_envTest */
/* IFTRUE_envBeta */
import xx from 'beta.debug.js'
/* FITRUE_envBeta */
/* FIDEBUG */
Hello,
Thanks for the tool that is a great way to deal with conditional rendering.
We use the conditional rendering in a Vue project to conditionally generate some parts in Vue components and in javascript files.
We have an issue though to generate the conditional rendering "automatically": when we want to switch from one condition to the other, compiling the code again (using npm run serve --optionX) will not make a difference. To apply the condition, we have to make a change in each files containing the directive /*IFTRUE_XXX (a space after the directive for example), then save. The next compilation will produce the code as expected.
I'm not sure if that's a bug or a problem from our setup?
Here is the extract our vue.config.json
module.exports = {
/* IFTRUE_isMicrobit */
configureWebpack: {
devtool: "source-map",
plugins: [
new MoveAssetsPlugin({
clean: true,
patterns: [
{
from: "dist/pythonLib",
to: "dist/",
},
],
}),
],
},
/* FITRUE_isMicrobit */
chainWebpack: (config) => {
config.module
.rule("conditionalCompilerVue")
.test(/\.vue$/)
.use("vue-loader")
.loader("js-conditional-compile-loader")
.options( {
isPurePython: process.env.npm_config_python,
isMicrobit: process.env.npm_config_microbit,
});
config.module
.rule("conditionalCompilerTS")
.test(/\.ts$/)
.use("vue-loader")
.loader("js-conditional-compile-loader")
.options( {
isPurePython: process.env.npm_config_python,
isMicrobit: process.env.npm_config_microbit,
});
},
publicPath: (process.env.npm_config_python)?"/editor/":"/microbit/",
pluginOptions: {
i18n: {
locale: "en",
fallbackLocale: "en",
localeDir: "localisation",
enableInSFC: false,
},
},
}
Thank you so much for your help - if any other file is needed to explore this issue, please let me know
你好,有个问题请教一下,比如页面有20个路由,我设置了默认打包只打15个,另外5个单独打包(单独的没有入口所以无法独立运行),如果我在部署的时候另一个环境需要修改这五个路由里面的某处(全部打包太麻烦,所以修改具体地方,打包那五个路由模块即可),如何将两个打包后的文件组装起来了?因为生成后的哈希值不可控,默认没有那五个路由,打完之后需要手动去修改路由以及那五个模块,尝试了很多方案目前还没有解决
Hi,
I am developing something in Vue and I want conditional complilation at the entry point for my application - i.e. index.html.
However, js-conditional-compile-loader does not seem to be working there.
Can you help me please?
先谢谢作者提供的插件,解决了我的一些实际问题。
今天在调试时发现,启用之后,SourceMap定位错误的问题,因为插件具体技术细节不了解,所以请作者判断下,如果有影响,又是否有解决的办法,谢谢!
else 的情况怎么解决呢?
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.