Skip to content
This repository has been archived by the owner on Dec 1, 2020. It is now read-only.

rollup replace configure seems to not working #41

Open
fifzteen opened this issue Mar 11, 2020 · 0 comments
Open

rollup replace configure seems to not working #41

fifzteen opened this issue Mar 11, 2020 · 0 comments

Comments

@fifzteen
Copy link

fifzteen commented Mar 11, 2020

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant