admin管理员组

文章数量:1023081

Can someone explain why I must embed the double quotes within single quotes in my Webpack configuration below? Why does it not work to just use double quotes?

module.exports = merge(prodEnv, {
  NODE_ENV: '"development"',
  API: '"http://localhost:8080"'
});

My app fails to load if I remove the single quotes, which seems really odd.

Can someone explain why I must embed the double quotes within single quotes in my Webpack configuration below? Why does it not work to just use double quotes?

module.exports = merge(prodEnv, {
  NODE_ENV: '"development"',
  API: '"http://localhost:8080"'
});

My app fails to load if I remove the single quotes, which seems really odd.

Share Improve this question edited Jun 6, 2017 at 6:19 Andrew Li 58k14 gold badges134 silver badges148 bronze badges asked Jun 6, 2017 at 6:10 blindsnowmobileblindsnowmobile 4,3387 gold badges38 silver badges51 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

This webpack plugin is going to be doing interpolation in your code. In other words, it will be replacing, at build time, process.env.NODE_ENV with whatever you have there.

So your code goes from console.log(process.env.NODE_ENV) to console.log("development"). If you left out the single quotes it would bee console.log(development), which would fail since there is no variable development.

Can someone explain why I must embed the double quotes within single quotes in my Webpack configuration below? Why does it not work to just use double quotes?

module.exports = merge(prodEnv, {
  NODE_ENV: '"development"',
  API: '"http://localhost:8080"'
});

My app fails to load if I remove the single quotes, which seems really odd.

Can someone explain why I must embed the double quotes within single quotes in my Webpack configuration below? Why does it not work to just use double quotes?

module.exports = merge(prodEnv, {
  NODE_ENV: '"development"',
  API: '"http://localhost:8080"'
});

My app fails to load if I remove the single quotes, which seems really odd.

Share Improve this question edited Jun 6, 2017 at 6:19 Andrew Li 58k14 gold badges134 silver badges148 bronze badges asked Jun 6, 2017 at 6:10 blindsnowmobileblindsnowmobile 4,3387 gold badges38 silver badges51 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

This webpack plugin is going to be doing interpolation in your code. In other words, it will be replacing, at build time, process.env.NODE_ENV with whatever you have there.

So your code goes from console.log(process.env.NODE_ENV) to console.log("development"). If you left out the single quotes it would bee console.log(development), which would fail since there is no variable development.

本文标签: npmWhy do I have to have double quotes inside single quotes in JavaScriptStack Overflow