Commit 962ea5a0c25e6774f2d05dd49f99d705aa4e7e41

Authored by 田强
1 parent 75128083

feat: build plugin

Too many changes to show.

To preserve performance only 3 of 6 files are displayed.

1 #!/usr/bin/env node 1 #!/usr/bin/env node
2 const execSync = require('child_process').execSync; 2 const execSync = require('child_process').execSync;
3 -const path = require('path'); 3 +const path = require('path')
  4 +const webpack = require('webpack')
  5 +
  6 +const config = require(path.resolve(__dirname, '../config/webpack.plugin.js'))
  7 +
  8 +webpack(config, (err) => {
  9 + if (err) {
  10 + console.log(err)
  11 + }
  12 +})
  13 + // execSync(`npx cross-env NODE_ENV=production webpack build --config ${path.resolve(__dirname, '../config/webpack.plugin.js')}`, { stdio: 'inherit' });
4 14
5 -execSync(`npx cross-env NODE_ENV=production webpack build --config ${path.resolve(__dirname, '../config/webpack.plugin.js')}`, { stdio: 'inherit' });  
1 #!/usr/bin/env node 1 #!/usr/bin/env node
2 const execSync = require('child_process').execSync; 2 const execSync = require('child_process').execSync;
3 const chalk = require('chalk'); 3 const chalk = require('chalk');
4 -  
5 const defaultEnv = ['dev', 'prod'] 4 const defaultEnv = ['dev', 'prod']
6 const env = process.argv.slice(2).join(' ') || 'prod' 5 const env = process.argv.slice(2).join(' ') || 'prod'
7 6
1 -const { merge } = require('webpack-merge');  
2 -const prodConfig = require('./webpack.prod'); 1 +const CopyPlugin = require("copy-webpack-plugin");
  2 +const { merge } = require("webpack-merge");
  3 +const prodConfig = require("./webpack.prod");
3 const WebpackBar = require("webpackbar"); 4 const WebpackBar = require("webpackbar");
4 const NodePolyfillPlugin = require("node-polyfill-webpack-plugin"); 5 const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
5 -const path = require('path')  
6 -const { cwd } = require('process') 6 +const path = require("path");
  7 +const fs = require("fs");
  8 +const { cwd } = require("process");
7 9
8 -delete prodConfig.plugins 10 +delete prodConfig.plugins;
  11 +
  12 +const extensions = ["ts", "tsx"];
  13 +
  14 +let extension;
  15 +
  16 +extensions.forEach((i) => {
  17 + if (fs.existsSync(path.resolve(cwd(), `index.${i}`))) {
  18 + extension = i;
  19 + }
  20 +});
  21 +
  22 +const name = cwd().split("/").reverse()[0];
9 23
10 module.exports = merge(prodConfig, { 24 module.exports = merge(prodConfig, {
11 output: { 25 output: {
12 - filename: 'index.js',  
13 - libraryTarget: 'system', 26 + filename: `../../../dist/${name}/index.js`,
  27 + libraryTarget: "system",
14 }, 28 },
15 - entry: path.resolve(cwd(), './index.ts'), 29 + entry: path.resolve(cwd(), `./index.${extension}`),
16 plugins: [ 30 plugins: [
  31 + new CopyPlugin({
  32 + patterns: [
  33 + {
  34 + from: path.resolve(cwd(), '../../plugin.json'),
  35 + to: path.resolve(cwd(), '../../dist/plugin.json'),
  36 + },
  37 + ],
  38 + }),
  39 + new CopyPlugin({
  40 + patterns: [
  41 + {
  42 + from: path.resolve(cwd(), '../../static'),
  43 + to: path.resolve(cwd(), '../../dist/static'),
  44 + },
  45 + ],
  46 + }),
17 new WebpackBar(), 47 new WebpackBar(),
18 - new NodePolyfillPlugin() 48 + new NodePolyfillPlugin(),
19 ], 49 ],
20 }); 50 });