After the package is developed and packaged with webpack, it is quoted as' NODE_ENV' of undefined'in the project.

I referenced the components of element and wanted to transform it into my own UI library. After packaging, I introduced the project, npm run dev and reported the following error:
introduced package: node_modules/ipst/dist/ipst.js error:

    Uncaught TypeError: Cannot read property "NODE_ENV" of undefined
    at Object.eval (ipst.js?df1b:formatted:346)
    at t (ipst.js?df1b:formatted:15)
    at Object.eval (ipst.js?df1b:formatted:28432)
    at t (ipst.js?df1b:formatted:15)
    at Object.eval (ipst.js?df1b:formatted:8917)
    at t (ipst.js?df1b:formatted:15)
    at Object.eval (ipst.js?df1b:formatted:28432)
    at t (ipst.js?df1b:formatted:15)
    at Object.eval (ipst.js?df1b:formatted:28432)
    at t (ipst.js?df1b:formatted:15)

directory structure:

clipboard.png

webpack.base.conf.js


webpack.prod.conf.js


:

clipboard.png

example/main.js, reference

import Vue from "vue";
import App from "./App";
import router from "./router";
// dev
// import "ele/theme-chalk/src/index.scss";
// import Ipst from "@/index.js";

// dist
import "../dist/static/ipst.css";
import Ipst from "../dist/ipst.js";

Vue.config.productionTip = false;
Vue.use(Ipst);

/* eslint-disable no-new */
new Vue({
  el: "-sharpapp",
  router,
  components: { App },
  template: "<App/>"
});

console sets this environment variable NODE_ENV='production'


export NODE_ENV=development & & npm run dev

ipst what is the package? there is something wrong with this package. The startup of a normal package cannot rely on complete environment variables. For example, webpack itself has a default value. If you are sure that only this package has a problem, it is suggested to go to issue to mention it, and if there is no one to maintain it, you will fork to change it.


need to use the plug-in webpack defineplugin

https://webpack.js.org/plugin.

https://codeshelper.com/l/15.

Menu