Skip to content

Commit 2610aa1

Browse files
committed
chore: 插件使用 ES Module 形式解析
1 parent 9c875ab commit 2610aa1

File tree

5 files changed

+23
-12
lines changed

5 files changed

+23
-12
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "nfp-template-drawer",
33
"version": "1.0.0",
4+
"type": "module",
45
"plugin": {
56
"id": "template-drawer",
67
"namespace": "plugins.template-drawer",

scripts/commit.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import fs from 'fs'
55
import path from 'path'
66
import readline from 'readline'
77

8-
const packageJson = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../package.json'), 'utf8'))
9-
10-
const PROJECT_PATH = path.resolve(__dirname, '../')
8+
const PROJECT_PATH = process.cwd()
9+
const packageJson = JSON.parse(fs.readFileSync(path.join(PROJECT_PATH, 'package.json'), 'utf8'))
1110
const ACTIONS_URL = 'https://github.com/N-Flow/' + packageJson.name + '/actions'
1211

1312
function checkPackageJson(projectPath: string): void {

scripts/copy-file-to-all-plugins.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { execSync } from 'child_process'
22
import fs from 'fs'
33
import path from 'path'
4+
import { fileURLToPath } from 'url'
45

6+
const __filename = fileURLToPath(import.meta.url)
7+
const __dirname = path.dirname(__filename)
58

69
const GENERAL_FILE_LIST = [
710
'.github/workflows/deploy.yml',

scripts/update-packages-to-all-plugins.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import { execSync } from 'child_process'
22
import * as fs from 'fs'
33
import * as path from 'path'
44
import * as readline from 'readline'
5+
import { fileURLToPath } from 'url'
6+
7+
const __filename = fileURLToPath(import.meta.url)
8+
const __dirname = path.dirname(__filename)
59

610
// 配置项
711
const COMMIT_MESSAGE = 'chore: update package version'

webpack.config.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
const path = require('path')
2-
const fs = require('fs')
1+
import path from 'path'
2+
import fs from 'fs'
3+
import { fileURLToPath } from 'url'
34

4-
const webpack = require('webpack')
5-
const WebSocket = require('ws')
6-
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin')
7-
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
8-
const TerserPlugin = require('terser-webpack-plugin')
5+
import webpack from 'webpack'
6+
import WebSocket from 'ws'
7+
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin'
8+
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
9+
import TerserPlugin from 'terser-webpack-plugin'
910

10-
const packageJson = require('./package.json')
11+
const __filename = fileURLToPath(import.meta.url)
12+
const __dirname = path.dirname(__filename)
13+
14+
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'))
1115
const packageName = packageJson.name
1216

1317
class CompilationNotifierPlugin {
@@ -119,7 +123,7 @@ class MessagesProcessorPlugin {
119123
}
120124
}
121125

122-
module.exports = (env, argv) => {
126+
export default (env, argv) => {
123127
const isServe = argv.serve || process.env.WEBPACK_SERVE === 'true'
124128
const isDevelopment = isServe
125129

0 commit comments

Comments
 (0)