kazupon / vue-cli-plugin-p11n

:electric_plug: Vue CLI 3 plugin to pluginize your Vue project
MIT License
113 stars 13 forks source link

rollup replace configure seems to not working #41

Open fifzteen opened 4 years ago

fifzteen commented 4 years ago

In vue.config.js, I set up rollup-plugin-replace option, but replacement dosen't work.

vue.config.js

const replace = require('rollup-plugin-replace')

module.exports = {
  pluginOptions: {
    p11n: {
      configureRollup: {
        plugins: [ replace({ imgpath: "'../src/assets/logo.png'"}) ]
      }
    }
  }
}

input(src/components/HelloWorld.vue)

<template>
  <div class="hello">
    <img v-bind:src="img">
  </div>
</template>

<script>
export default {
  name: 'HelloWorld',
  props: {
    msg: String
  },
  data: function(){
    return {
      img: require(imgpath)
    }
  }
}
</script>

output(p11ntest.esm.js)

var script = {
  name: 'HelloWorld',
  props: {
    msg: String
  },
  data: function data() {
    return {
      img: require(imgpath)  <- expected "require('../src/assets/logo.png')"
    };
  }
};

(for entire test project, view my repository. https://github.com/fifzteen/p11ntest/tree/master)

I also test to rollup directly. that is working correctly.

rollup.config.js

import path from 'path'
import babel from 'rollup-plugin-babel'
import commonjs from 'rollup-plugin-commonjs'
import vue from 'rollup-plugin-vue'
import replace from 'rollup-plugin-replace'

export default [{
  input: path.join(__dirname, '.', 'src', 'components', 'HelloWorld.vue'),
  output: [
    {
      file: 'dist/p11ntest_rollup.esm.js',
      format: 'es'
    }
  ],
  plugins: [
    vue({css: true}),
    replace({
      imgpath: "'../src/assets/logo.png'"
    }),
    commonjs(),
    babel({
      exclude: 'node_modules/**',
      runtimeHelpers: true
    }),
  ]
}]

output(p11ntest_rollup.sem.js)

var script = {
  name: 'HelloWorld',
  props: {
    msg: String
  },
  data: function data() {
    return {
      img: require('../src/assets/logo.png')
    };
  }
};

I'm happy to tell me solutions or whether this is a bug or not.