afterwind-io / preprocessor-loader

Bring the awesome "Conditional Compilation" to the Webpack, and more.
MIT License
40 stars 12 forks source link

有时候打包构建后的项目,条件判断会失效 #27

Open a857430369 opened 2 years ago

a857430369 commented 2 years ago

Vue3,vue-cli

a857430369 commented 2 years ago

.vue

<template> 
<div>
<!-- #!if sfly -->
                    <span v-if="data.balance_currency">
                        ({{data.balance_currency}})
                    </span>
 <!-- #!endif -->
</div>
</template>

vue.config.js

const webpackLoaderOption = {
            sfly: process.env.VUE_APP_OUT_DIR == 'fly'
 }
let vueRule = config.module.rule('vue')
        vueRule
            .test(/\.vue$/)
            .use("webpack-preprocessor-loader")
            .loader("webpack-preprocessor-loader")
            .tap(() => {

                return {
                    params: webpackLoaderOption
                };
            })
            .end();

        let htmlRule = config.module.rule('js-html')
        htmlRule
            .test(/\.js$/)
            .use("webpack-preprocessor-loader")
            .loader("webpack-preprocessor-loader")
            .tap(() => {

                return {
                    params: webpackLoaderOption
                };
            })
            .end();