|
| 1 | +/* |
| 2 | + * Generated by node-dev-server |
| 3 | + * |
| 4 | + * @author Develon (https://github.com/develon2015) |
| 5 | + */ |
| 6 | +const $babel_loader = require('./nds-babel.js'); // nds plugin |
| 7 | + |
| 8 | +const path = require('path'); |
| 9 | + |
| 10 | +const DIR_PROJECT = path.resolve(__dirname, '.'); |
| 11 | +const DIR_SRC = path.resolve(DIR_PROJECT, 'src'); |
| 12 | +const DIR_DIST = path.resolve(DIR_PROJECT, 'dist'); |
| 13 | + |
| 14 | +/** |
| 15 | + * @type {import('webpack').Configuration} |
| 16 | + */ |
| 17 | +const CONFIG = { |
| 18 | + // target: 'node', // 请本地安装开发依赖: @types/node |
| 19 | + target: 'electron-main', // electron主进程支持. 可以全局安装electron, 然后link到本地, 以提供相应版本的electron类型支持. |
| 20 | + // target: 'electron-renderer', // electron渲染进程不需要使用nds, 请使用: webpack-dev-server + webpack serve |
| 21 | + mode: 'none', // 开发时不建议使用默认值"production" |
| 22 | + // mode: 'development', // 开发模式 |
| 23 | + // devtool: 'source-map', // 生成main.js.map源码映射文件, 以支持.ts源码的断点调试。还可以使用inline-source-map |
| 24 | + entry: { |
| 25 | + main: path.resolve(DIR_SRC), |
| 26 | + preload: path.resolve(DIR_SRC, 'preload'), |
| 27 | + }, |
| 28 | + output: { |
| 29 | + filename: '[name].js', |
| 30 | + path: DIR_DIST, |
| 31 | + libraryTarget: 'commonjs2', |
| 32 | + chunkFilename: 'async/[id]-module-[name].js', // 此选项确定非入口块文件的名称 |
| 33 | + }, |
| 34 | + module: { |
| 35 | + rules: [ |
| 36 | + { test: /\.tsx?$/, exclude: /node_modules/, use: $babel_loader }, // @BABEL_LOADER及其预设由nds提供 |
| 37 | + ], |
| 38 | + }, |
| 39 | + resolve: { |
| 40 | + extensions: ['.ts', '.js', '.json', '.tsx'], |
| 41 | + alias: { |
| 42 | + '@': DIR_SRC, |
| 43 | + }, |
| 44 | + }, |
| 45 | +}; |
| 46 | + |
| 47 | +function config(env = {}, argv = {}) { |
| 48 | + if (env && (env.production || env.rebuild)) { |
| 49 | + console.log('Build production'); |
| 50 | + CONFIG.mode = 'production'; |
| 51 | + delete CONFIG.devtool; |
| 52 | + delete CONFIG.devServer; |
| 53 | + } |
| 54 | + if (env && env.rebuild) { |
| 55 | + console.log('Rebuild production'); |
| 56 | + console.log('OS:', process.platform); |
| 57 | + try { |
| 58 | + const child_process = require('child_process'); |
| 59 | + if (process.platform.match(/^win.*/)) { // Implement this on Windows OS |
| 60 | + child_process.execSync(`rmdir /S /Q "${DIR_DIST}"`); |
| 61 | + } else if (process.platform.match(/^linux.*/)) { // Implement this on Linux OS |
| 62 | + child_process.execSync(`rm -rf '${DIR_DIST}'`); |
| 63 | + } |
| 64 | + } catch (error) { } |
| 65 | + } |
| 66 | + return CONFIG; |
| 67 | +} |
| 68 | + |
| 69 | +module.exports = config; |
0 commit comments