ymzuiku / parcel-plugin-change-file

parcel 的文件处理插件 \ Jump parcel bundler in html & Replace html string & Copy files at parcel builded
MIT License
16 stars 8 forks source link

configFilePath is not defined #1

Closed rogeriomq closed 6 years ago

rogeriomq commented 6 years ago

When I run parcel watch src / index.html --public-url ./ - out-dir dist / I have the following output: ⚠️ configFilePath is not defined at Object.<anonymous> (/home/man1gold/Projetos/www/cnt/www/modulos/administrativo/relatorio/node_modules/parcel-plugin-change-file/index.js:8:26) at Module._compile (/home/man1gold/.npm-global/lib/node_modules/parcel/node_modules/v8-compile-cache/v8-compile-cache.js:178:30) at Object.Module._extensions..js (module.js:664:10) at Module.load (module.js:566:32) at tryModuleLoad (module.js:506:12) at Function.Module._load (module.js:498:3) at Module.require (module.js:597:17) at require (/home/man1gold/.npm-global/lib/node_modules/parcel/node_modules/v8-compile-cache/v8-compile-cache.js:159:20) at localRequire (/home/man1gold/.npm-global/lib/node_modules/parcel/src/utils/localRequire.js:10:10) at <anonymous> And the script in my index.html still remains commented out in dist / index.html:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>CNT Sistemas - Gerenciador de Relatórios.</title>
  </head>
  <body>
    <div id="app"></div>
    <!-- Note the reference to src here. Parcel will rewrite it on build. -->
    <script src="main.js"></script>
    <!--[ <script src="test.js"></script>
    <script>
      activeName('Gerenciador de Relatórios');
    </script> ]-->
  </body>
</html>
taj commented 6 years ago

@rogeriomq @ymzuiku I do get the same error as well.

SeriousM commented 6 years ago

I had the quite same issue. One look into the sourcecode shows that the plugin is trying to either A: get the config from the package.json B: read the confg from the file parcel-plugin-change-file.js

In my case (and yours) the file can't be read but you can still place the configuration in the package.json like this:

{
  "name": "app",
  "version": "1.0.0",
  "private": true,
  "dependencies": {
    "parcel-bundler": "^1.10.3"
  },
  "devDependencies": {
    "parcel-plugin-change-file": "1.3.0"
  },
  "parcel-plugin-change-file": {
    "timeout": 30, // setTimeout replace Html file
    "replaceName": "parcel-plugin-change-file", // default html replaceName
    "html": ['hello'], // change string to html
    "copy": ["src/assets"], // copy files in outDir
  }
}
rogeriomq commented 6 years ago

I had the quite same issue. One look into the sourcecode shows that the plugin is trying to either A: get the config from the package.json B: read the confg from the file parcel-plugin-change-file.js

In my case (and yours) the file can't be read but you can still place the configuration in the package.json like this:

{
  "name": "app",
  "version": "1.0.0",
  "private": true,
  "dependencies": {
    "parcel-bundler": "^1.10.3"
  },
  "devDependencies": {
    "parcel-plugin-change-file": "1.3.0"
  },
  "parcel-plugin-change-file": {
    "timeout": 30, // setTimeout replace Html file
    "replaceName": "parcel-plugin-change-file", // default html replaceName
    "html": ['hello'], // change string to html
    "copy": ["src/assets"], // copy files in outDir
  }
}

Very Nice! Actually, I think there should be only the option via package.json should exist.

Charbo23 commented 5 years ago

@SeriousM The plan B you mentioned is quite easy to realize by adding the following code to the index.js of this plugin (can be found in the node_modules or just simply click the error log 😝 )

const configFilePath = path.resolve(process.cwd(), 'parcel-plugin-change-file.js');
// Assuming your parcel-plugin-change-file.js is in the root directory

Though you need to do this every time you install the plugin 😕

dobesv commented 5 years ago

You can use patch-package to save changes you make to node modules and apply them after each install.

Charbo23 commented 5 years ago

Aha great idea, the problem is perfectly solved then