web -> desktop
This commit is contained in:
20
build/start.js
Normal file
20
build/start.js
Normal file
@ -0,0 +1,20 @@
|
||||
const childProcess = require("child_process");
|
||||
const electron = require("electron");
|
||||
const webpack = require("webpack");
|
||||
const config = require("./webpack.app.config");
|
||||
|
||||
const env = "development";
|
||||
const compiler = webpack(config(env));
|
||||
let electronStarted = false;
|
||||
|
||||
const watching = compiler.watch({}, (err, stats) => {
|
||||
if (!err && !stats.hasErrors() && !electronStarted) {
|
||||
electronStarted = true;
|
||||
|
||||
childProcess
|
||||
.spawn(electron, ["."], { stdio: "inherit" })
|
||||
.on("close", () => {
|
||||
watching.close();
|
||||
});
|
||||
}
|
||||
});
|
16
build/webpack.app.config.js
Normal file
16
build/webpack.app.config.js
Normal file
@ -0,0 +1,16 @@
|
||||
const path = require("path");
|
||||
const merge = require("webpack-merge");
|
||||
const base = require("./webpack.base.config");
|
||||
|
||||
module.exports = env => {
|
||||
return merge(base(env), {
|
||||
entry: {
|
||||
background: "./src/background/background.js",
|
||||
app: "./src/app/index.js"
|
||||
},
|
||||
output: {
|
||||
filename: "[name].js",
|
||||
path: path.resolve(__dirname, "../app")
|
||||
}
|
||||
});
|
||||
};
|
40
build/webpack.base.config.js
Normal file
40
build/webpack.base.config.js
Normal file
@ -0,0 +1,40 @@
|
||||
const path = require("path");
|
||||
const nodeExternals = require("webpack-node-externals");
|
||||
const FriendlyErrorsWebpackPlugin = require("friendly-errors-webpack-plugin");
|
||||
|
||||
module.exports = env => {
|
||||
return {
|
||||
target: "node",
|
||||
node: {
|
||||
__dirname: false,
|
||||
__filename: false
|
||||
},
|
||||
externals: [nodeExternals()],
|
||||
resolve: {
|
||||
alias: {
|
||||
env: path.resolve(__dirname, `../config/env_${env}.json`)
|
||||
}
|
||||
},
|
||||
devtool: "source-map",
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.js$/,
|
||||
exclude: /node_modules/,
|
||||
use: ["babel-loader"]
|
||||
},
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: ["style-loader", "css-loader"]
|
||||
},
|
||||
{
|
||||
test: /\.(?:ico|gif|png|jpg|jpeg|webp)$/,
|
||||
use: ['url-loader']
|
||||
}
|
||||
]
|
||||
},
|
||||
plugins: [
|
||||
new FriendlyErrorsWebpackPlugin({ clearConsole: env === "development" })
|
||||
]
|
||||
};
|
||||
};
|
29
build/webpack.e2e.config.js
Normal file
29
build/webpack.e2e.config.js
Normal file
@ -0,0 +1,29 @@
|
||||
const merge = require("webpack-merge");
|
||||
const jetpack = require("fs-jetpack");
|
||||
const base = require("./webpack.base.config");
|
||||
|
||||
// Test files are scattered through the whole project. Here we're searching
|
||||
// for them and generating entry file for webpack.
|
||||
|
||||
const e2eDir = jetpack.cwd("e2e");
|
||||
const tempDir = jetpack.cwd("temp");
|
||||
const entryFilePath = tempDir.path("e2e_entry.js");
|
||||
|
||||
const entryFileContent = e2eDir
|
||||
.find({ matching: "*.e2e.js" })
|
||||
.reduce((fileContent, path) => {
|
||||
const normalizedPath = path.replace(/\\/g, "/");
|
||||
return `${fileContent}import "../e2e/${normalizedPath}";\n`;
|
||||
}, "");
|
||||
|
||||
jetpack.write(entryFilePath, entryFileContent);
|
||||
|
||||
module.exports = env => {
|
||||
return merge(base(env), {
|
||||
entry: entryFilePath,
|
||||
output: {
|
||||
filename: "e2e.js",
|
||||
path: tempDir.path()
|
||||
}
|
||||
});
|
||||
};
|
29
build/webpack.unit.config.js
Normal file
29
build/webpack.unit.config.js
Normal file
@ -0,0 +1,29 @@
|
||||
const merge = require("webpack-merge");
|
||||
const jetpack = require("fs-jetpack");
|
||||
const base = require("./webpack.base.config");
|
||||
|
||||
// Test files are scattered through the whole project. Here we're searching
|
||||
// for them and generating entry file for webpack.
|
||||
|
||||
const srcDir = jetpack.cwd("src");
|
||||
const tempDir = jetpack.cwd("temp");
|
||||
const entryFilePath = tempDir.path("specs_entry.js");
|
||||
|
||||
const entryFileContent = srcDir
|
||||
.find({ matching: "*.spec.js" })
|
||||
.reduce((fileContent, path) => {
|
||||
const normalizedPath = path.replace(/\\/g, "/");
|
||||
return `${fileContent}import "../src/${normalizedPath}";\n`;
|
||||
}, "");
|
||||
|
||||
jetpack.write(entryFilePath, entryFileContent);
|
||||
|
||||
module.exports = env => {
|
||||
return merge(base(env), {
|
||||
entry: entryFilePath,
|
||||
output: {
|
||||
filename: "specs.js",
|
||||
path: tempDir.path()
|
||||
}
|
||||
});
|
||||
};
|
Reference in New Issue
Block a user