Skip to content

Commit 8171f3e

Browse files
authored
feat: use EJS on html files, inject process.env.* vars (Kocal#336)
| Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | ~ <!-- #-prefixed issue number(s), if any --> In order to load Vue Devtools remote `<script>` (Kocal#334 (comment)) only for development environment, a good solution is to use a condition (with EJS) on HTML files. That means you can write: ```html <% if (NODE_ENV === 'development') { %> <script src="http://localhost:8098/"></script> <% } %> ```
1 parent 56c7a51 commit 8171f3e

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

template/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
"copy-webpack-plugin": "^4.5.3",
7979
"cross-env": "^5.2.0",
8080
"css-loader": "^0.28.11",
81+
"ejs": "^2.6.1",
8182
"file-loader": "^1.1.11",
8283
"mini-css-extract-plugin": "^0.4.4",
8384
"node-sass": "^4.9.3",

template/src/options/options.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
<meta charset="UTF-8">
55
<title>{{ name }} - Options</title>
66
<link rel="stylesheet" href="options.css">
7+
<% if (NODE_ENV === 'development') { %>
8+
<!-- Load some resources only in development environment -->
9+
<% } %>
710
</head>
811
<body>
912
<div id="app"></div>

template/src/popup/popup.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
<meta charset="UTF-8">
55
<title>Title</title>
66
<link rel="stylesheet" href="popup.css">
7+
<% if (NODE_ENV === 'development') { %>
8+
<!-- Load some resources only in development environment -->
9+
<% } %>
710
</head>
811
<body>
912
<div id="app">

template/webpack.config.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const webpack = require('webpack');
2+
const ejs = require('ejs');
23
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
34
const WebpackShellPlugin = require('webpack-shell-plugin');
45
const CopyWebpackPlugin = require('copy-webpack-plugin');
@@ -60,8 +61,8 @@ const config = {
6061
}),
6162
new CopyWebpackPlugin([
6263
{ from: 'icons', to: 'icons', ignore: ['icon.xcf'] },
63-
{ from: 'popup/popup.html', to: 'popup/popup.html' },{{#options}}
64-
{ from: 'options/options.html', to: 'options/options.html' },{{/options}}
64+
{ from: 'popup/popup.html', to: 'popup/popup.html', transform: transformHtml },{{#options}}
65+
{ from: 'options/options.html', to: 'options/options.html', transform: transformHtml },{{/options}}
6566
{
6667
from: 'manifest.json',
6768
to: 'manifest.json',
@@ -99,4 +100,10 @@ if (process.env.HMR === 'true') {
99100
]);
100101
}
101102

103+
function transformHtml(content) {
104+
return ejs.render(content.toString(), {
105+
...process.env,
106+
});
107+
}
108+
102109
module.exports = config;

0 commit comments

Comments
 (0)