@autobest-ui/scripts 0.0.4 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,193 +1,218 @@
1
- const webpack = require('webpack');
2
- const MiniCssExtractPlugin = require('mini-css-extract-plugin');
3
- const HappyPack = require('happypack');
4
- const ESLintPlugin = require('eslint-webpack-plugin');
5
- const ProgressBarPlugin = require('progress-bar-webpack-plugin');
6
- const getCSSModuleLocalIdent = require('./getCSSModuleLocalIdent');
7
-
8
- const happyThreadPool = HappyPack.ThreadPool({ size: 5 });
9
- const sassRegex = /\.(scss|sass)$/;
10
- const sassModuleRegex = /\.module\.(scss|sass)$/;
11
-
12
- function getStyleLoaders({ isProd, isServer, isHotServer, isSass, moduleOption = {} }) {
13
- const result = [
14
- {
15
- loader: 'css-loader',
16
- options: {
17
- importLoaders: 1,
18
- ...moduleOption
19
- }
20
- },
21
- {
22
- loader: 'postcss-loader',
23
- options: {
24
- ident: 'postcss',
25
- plugins: () => [
26
- require('postcss-flexbugs-fixes'),
27
- require('postcss-preset-env')({
28
- autoprefixer: {
29
- flexbox: 'no-2009',
30
- grid: true
31
- },
32
- stage: 3
33
- })
34
- ],
35
- sourceMap: false
36
- }
37
- }
38
- ];
39
-
40
- if (isSass) {
41
- result.push({
42
- loader: 'sass-loader'
43
- });
44
- }
45
-
46
- if ((isProd || isHotServer) && !isServer) {
47
- result.unshift({
48
- loader: MiniCssExtractPlugin.loader,
49
- options: {
50
- hmr: false
51
- }
52
- });
53
- }
54
-
55
- if (!isProd && !isHotServer) {
56
- result.unshift({
57
- loader: 'style-loader'
58
- });
59
- }
60
-
61
- return result;
62
- }
63
-
64
- module.exports = (appConfig, extendEnv, { isProd, isServer, isHotServer }) => {
65
- const result = {
66
- // 原始源代码(仅限行)定位到原始代码问题,比source-map 快,但是没有列映射(column mapping)的 source-map
67
- devtool: isProd ? 'source-map' : 'cheap-module-source-map',
68
- // 会将 process.env.NODE_ENV 的值设为 development, 告知 webpack 使用相应模式的内置优化
69
- mode: isProd ? 'production' : 'development',
70
- // 打包的出口
71
- output: {
72
- publicPath: '/'
73
- },
74
- // 配置各种loader
75
- module: {
76
- // 警告替换为Error
77
- strictExportPresence: true,
78
- rules: [
79
- {
80
- oneOf: [
81
- {
82
- test: /\.(js|ts|tsx)$/,
83
- exclude: /node_modules/,
84
- use: 'happypack/loader?id=jsbabel'
85
- },
86
- {
87
- test: sassRegex,
88
- exclude: sassModuleRegex,
89
- use: getStyleLoaders({
90
- isProd,
91
- isServer,
92
- isHotServer,
93
- isSass: true
94
- })
95
- },
96
- {
97
- test: sassModuleRegex,
98
- use: getStyleLoaders({
99
- isProd,
100
- isServer,
101
- isHotServer,
102
- isSass: true,
103
- moduleOption: {
104
- getLocalIdent: getCSSModuleLocalIdent,
105
- importLoaders: 2,
106
- modules: true
107
- }
108
- })
109
- },
110
- {
111
- test: /\.(css)$/,
112
- use: getStyleLoaders({
113
- isProd,
114
- isServer,
115
- isHotServer
116
- })
117
- },
118
- {
119
- test: [/\.jpe?g$/, /\.png$/, /\.bmp$/, /\.gif$/],
120
- loader: 'url-loader',
121
- options: {
122
- limit: 2048,
123
- name: `media/[name].[ext]?v=${extendEnv.version}`
124
- }
125
- }
126
- ]
127
- }
128
- ]
129
- },
130
- resolve: {
131
- // 设置路径别名
132
- alias: appConfig.alias,
133
- // 文件后缀自动补全
134
- extensions: ['.tsx', '.ts', '.js', 'scss', 'css']
135
- },
136
- plugins: [
137
- new webpack.DefinePlugin(extendEnv.stringified),
138
- new ESLintPlugin({
139
- failOnError: false,
140
- extensions: ['ts', 'tsx', 'js']
141
- }),
142
- new HappyPack({
143
- id: 'jsbabel',
144
- verbose: false,
145
- threadPool: happyThreadPool,
146
- loaders: [
147
- {
148
- loader: 'babel-loader',
149
- options: {
150
- cacheDirectory: true,
151
- presets: [
152
- 'react-app',
153
- '@babel/preset-env',
154
- '@babel/preset-react',
155
- '@babel/typescript'
156
- ],
157
- plugins: [
158
- '@loadable/babel-plugin',
159
- '@babel/plugin-transform-object-assign',
160
- '@babel/plugin-transform-shorthand-properties',
161
- '@babel/plugin-transform-runtime',
162
- [
163
- '@babel/plugin-proposal-decorators',
164
- {
165
- legacy: true
166
- }
167
- ],
168
- [
169
- '@babel/plugin-proposal-class-properties',
170
- {
171
- loose: false
172
- }
173
- ]
174
- ]
175
- }
176
- }
177
- ]
178
- }),
179
- new ProgressBarPlugin({
180
- // eslint-disable-next-line no-useless-concat
181
- format: 'build [:bar] ' + ':percent' + ' (:elapsed seconds)',
182
- clear: false
183
- })
184
- ]
185
- };
186
- if (isProd && !isServer) {
187
- result.optimization = {
188
- minimize: true
189
- };
190
- }
191
-
192
- return result;
193
- };
1
+ const webpack = require('webpack');
2
+ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
3
+ const HappyPack = require('happypack');
4
+ const ESLintPlugin = require('eslint-webpack-plugin');
5
+ const ProgressBarPlugin = require('progress-bar-webpack-plugin');
6
+ const getCSSModuleLocalIdent = require('./getCSSModuleLocalIdent');
7
+ const { getProjectPath, isExistsSyncFile } = require('./utils');
8
+
9
+ const appWebpackConfigPath = getProjectPath('/config/app.webpack.js');
10
+
11
+ const happyThreadPool = HappyPack.ThreadPool({ size: 5 });
12
+ const sassRegex = /\.(scss|sass)$/;
13
+ const sassModuleRegex = /\.module\.(scss|sass)$/;
14
+
15
+ function getStyleLoaders({ isProd, isServer, isHotServer, isSass, moduleOption = {} }) {
16
+ const result = [
17
+ {
18
+ loader: 'css-loader',
19
+ options: {
20
+ importLoaders: 1,
21
+ ...moduleOption
22
+ }
23
+ },
24
+ {
25
+ loader: 'postcss-loader',
26
+ options: {
27
+ ident: 'postcss',
28
+ plugins: () => [
29
+ require('postcss-flexbugs-fixes'),
30
+ require('postcss-preset-env')({
31
+ autoprefixer: {
32
+ flexbox: 'no-2009',
33
+ remove: false,
34
+ grid: true
35
+ },
36
+ stage: 3
37
+ })
38
+ ],
39
+ sourceMap: false
40
+ }
41
+ }
42
+ ];
43
+
44
+ if (isSass) {
45
+ result.push({
46
+ loader: 'sass-loader'
47
+ });
48
+ }
49
+
50
+ if ((isProd || isHotServer) && !isServer) {
51
+ result.unshift({
52
+ loader: MiniCssExtractPlugin.loader,
53
+ options: {
54
+ hmr: false
55
+ }
56
+ });
57
+ }
58
+
59
+ if (!isProd && !isHotServer) {
60
+ result.unshift({
61
+ loader: 'style-loader'
62
+ });
63
+ }
64
+
65
+ return result;
66
+ }
67
+
68
+ module.exports = (appConfig, extendEnv, { isProd, isServer, isHotServer, isSetCommonAlias }) => {
69
+ const result = {
70
+ // 原始源代码(仅限行)定位到原始代码问题,比source-map 快,但是没有列映射(column mapping)的 source-map
71
+ devtool: isProd ? 'source-map' : 'cheap-module-source-map',
72
+ // 会将 process.env.NODE_ENV 的值设为 development, 告知 webpack 使用相应模式的内置优化
73
+ mode: isProd ? 'production' : 'development',
74
+ // 打包的出口
75
+ output: {
76
+ publicPath: '/'
77
+ },
78
+ // 配置各种loader
79
+ module: {
80
+ // 警告替换为Error
81
+ strictExportPresence: true,
82
+ rules: [
83
+ {
84
+ oneOf: [
85
+ {
86
+ test: /\.(js|ts|tsx)$/,
87
+ exclude: /node_modules/,
88
+ use: 'happypack/loader?id=jsbabel'
89
+ },
90
+ {
91
+ test: sassRegex,
92
+ exclude: sassModuleRegex,
93
+ use: getStyleLoaders({
94
+ isProd,
95
+ isServer,
96
+ isHotServer,
97
+ isSass: true
98
+ })
99
+ },
100
+ {
101
+ test: sassModuleRegex,
102
+ use: getStyleLoaders({
103
+ isProd,
104
+ isServer,
105
+ isHotServer,
106
+ isSass: true,
107
+ moduleOption: {
108
+ getLocalIdent: getCSSModuleLocalIdent,
109
+ importLoaders: 2,
110
+ modules: true
111
+ }
112
+ })
113
+ },
114
+ {
115
+ test: /\.(css)$/,
116
+ use: getStyleLoaders({
117
+ isProd,
118
+ isServer,
119
+ isHotServer
120
+ })
121
+ },
122
+ {
123
+ test: [/\.jpe?g$/, /\.png$/, /\.bmp$/, /\.gif$/],
124
+ loader: 'url-loader',
125
+ options: {
126
+ limit: 2048,
127
+ name: `static/[name].[contenthash:8].[ext]?v=${extendEnv.version}`
128
+ }
129
+ }
130
+ ]
131
+ }
132
+ ]
133
+ },
134
+ resolve: {
135
+ // 设置路径别名
136
+ alias: appConfig.alias,
137
+ // 文件后缀自动补全
138
+ extensions: ['.tsx', '.ts', '.js', 'scss', 'css']
139
+ },
140
+ plugins: [
141
+ new webpack.DefinePlugin(extendEnv.stringified),
142
+ new ESLintPlugin({
143
+ failOnError: false,
144
+ extensions: ['ts', 'tsx', 'js']
145
+ }),
146
+ new HappyPack({
147
+ id: 'jsbabel',
148
+ verbose: false,
149
+ threadPool: happyThreadPool,
150
+ loaders: [
151
+ {
152
+ loader: 'babel-loader',
153
+ options: {
154
+ cacheDirectory: true,
155
+ presets: [
156
+ 'react-app',
157
+ '@babel/preset-env',
158
+ '@babel/preset-react',
159
+ '@babel/typescript'
160
+ ],
161
+ plugins: [
162
+ '@loadable/babel-plugin',
163
+ '@babel/plugin-transform-object-assign',
164
+ '@babel/plugin-transform-shorthand-properties',
165
+ '@babel/plugin-transform-runtime',
166
+ [
167
+ '@babel/plugin-proposal-decorators',
168
+ {
169
+ legacy: true
170
+ }
171
+ ],
172
+ [
173
+ '@babel/plugin-proposal-class-properties',
174
+ {
175
+ loose: false
176
+ }
177
+ ]
178
+ ]
179
+ }
180
+ }
181
+ ]
182
+ }),
183
+ new ProgressBarPlugin({
184
+ // eslint-disable-next-line no-useless-concat
185
+ format: 'build [:bar] ' + ':percent' + ' (:elapsed seconds)',
186
+ clear: false
187
+ })
188
+ ]
189
+ };
190
+ if (isProd && !isServer) {
191
+ result.optimization = {
192
+ minimize: true
193
+ };
194
+ }
195
+
196
+ if (isExistsSyncFile(appWebpackConfigPath)) {
197
+ const extendConfig = require(appWebpackConfigPath);
198
+ if (typeof extendConfig !== 'function') {
199
+ throw Error(
200
+ `Extend webpack config file only functions are supported and return extend result! \n current type is ${typeof extendConfig} \n filename is ${appWebpackConfigPath}`
201
+ );
202
+ }
203
+ const extendResult = extendConfig(result, appConfig, extendEnv, {
204
+ isProd,
205
+ isServer,
206
+ isHotServer,
207
+ isSetCommonAlias
208
+ });
209
+ if (!extendResult) {
210
+ throw Error(
211
+ `Return extend result! \n current extendResult is ${extendResult} \n filename is ${appWebpackConfigPath}`
212
+ );
213
+ }
214
+ return extendResult;
215
+ }
216
+
217
+ return result;
218
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autobest-ui/scripts",
3
- "version": "0.0.4",
3
+ "version": "0.1.1",
4
4
  "private": false,
5
5
  "description": "utils for project tools",
6
6
  "bin": {
@@ -44,7 +44,6 @@
44
44
  },
45
45
  "homepage": "https://autobest.visualstudio.com/AutoBestChina/_git/AutobestFrontendCommon#readme",
46
46
  "dependencies": {
47
- "@autobest-ui/replace-loader": "^0.0.8",
48
47
  "@babel/core": "7.13.0",
49
48
  "@babel/plugin-proposal-class-properties": "7.12.13",
50
49
  "@babel/plugin-proposal-decorators": "7.14.2",
@@ -72,6 +71,7 @@
72
71
  "html-webpack-plugin": "4.3.0",
73
72
  "ignore-loader": "^0.1.2",
74
73
  "ip": "1.1.5",
74
+ "loader-utils": "2.0.0",
75
75
  "mini-css-extract-plugin": "^0.8.0",
76
76
  "node-sass": "4.12.0",
77
77
  "nodemon": "^1.19.1",
@@ -93,5 +93,5 @@
93
93
  "webpack-merge": "^4.2.1",
94
94
  "webpack-node-externals": "1.7.2"
95
95
  },
96
- "gitHead": "a2faeba0025ae27fbec8139138d156574ec694ae"
96
+ "gitHead": "18fb4398b00aa3322a548f8f87532945a4d51d1e"
97
97
  }
@@ -1,65 +1,65 @@
1
- const webpack = require('webpack');
2
- const chalk = require('chalk');
3
- const appConfig = require('../common/appConfig');
4
- const { runCallback } = require('../common/build');
5
- const getClientEnvironment = require('../common/extendEnv');
6
- const webpackFactory = require('./webpack.prod');
7
-
8
- process.env.BABEL_ENV = 'production';
9
- process.env.NODE_ENV = 'production';
10
-
11
- process.on('unhandledRejection', err => {
12
- // eslint-disable-next-line @typescript-eslint/no-throw-literal
13
- throw err;
14
- });
15
-
16
- const extendEnv = getClientEnvironment();
17
-
18
- function build() {
19
- const config = webpackFactory(appConfig, extendEnv);
20
- // eslint-disable-next-line no-console
21
- console.log(chalk.green('Creating an optimized production build...'));
22
- const compiler = webpack(config);
23
- return new Promise((resolve, reject) => {
24
- compiler.run(runCallback(resolve, reject));
25
- });
26
- }
27
-
28
- build()
29
- .then(
30
- ({ warnings }) => {
31
- if (warnings.length) {
32
- // eslint-disable-next-line no-console
33
- console.log(chalk.yellow('Compiled with warnings.\n'));
34
- // eslint-disable-next-line no-console
35
- console.log(warnings.join('\n\n'));
36
- // eslint-disable-next-line no-console
37
- console.log(
38
- `\nSearch for the ${chalk.underline(
39
- chalk.yellow('keywords')
40
- )} to learn more about each warning.`
41
- );
42
- // eslint-disable-next-line no-console
43
- console.log(
44
- `To ignore, add ${chalk.cyan('// eslint-disable-next-line')} to the line before.\n`
45
- );
46
- } else {
47
- // eslint-disable-next-line no-console
48
- console.log(chalk.green('Compiled successfully.\n'));
49
- }
50
- },
51
- err => {
52
- // eslint-disable-next-line no-console
53
- console.log(chalk.red('Failed to compile.\n'));
54
- // eslint-disable-next-line no-console
55
- console.log(err);
56
- process.exit(1);
57
- }
58
- )
59
- .catch(err => {
60
- // eslint-disable-next-line no-console
61
- console.log(chalk.red('Failed to compile.\n'));
62
- // eslint-disable-next-line no-console
63
- console.log(err);
64
- process.exit(1);
65
- });
1
+ const webpack = require('webpack');
2
+ const chalk = require('chalk');
3
+ const appConfig = require('../common/appConfig');
4
+ const { runCallback } = require('../common/build');
5
+ const getClientEnvironment = require('../common/extendEnv');
6
+ const webpackFactory = require('./webpack.prod');
7
+
8
+ process.env.BABEL_ENV = 'production';
9
+ process.env.NODE_ENV = 'production';
10
+
11
+ process.on('unhandledRejection', err => {
12
+ // eslint-disable-next-line @typescript-eslint/no-throw-literal
13
+ throw err;
14
+ });
15
+
16
+ const extendEnv = getClientEnvironment();
17
+
18
+ function build() {
19
+ const config = webpackFactory(appConfig, extendEnv);
20
+ // eslint-disable-next-line no-console
21
+ console.log(chalk.green('Creating an optimized production build...'));
22
+ const compiler = webpack(config);
23
+ return new Promise((resolve, reject) => {
24
+ compiler.run(runCallback(resolve, reject));
25
+ });
26
+ }
27
+
28
+ build()
29
+ .then(
30
+ ({ warnings }) => {
31
+ if (warnings.length) {
32
+ // eslint-disable-next-line no-console
33
+ console.log(chalk.yellow('Compiled with warnings.\n'));
34
+ // eslint-disable-next-line no-console
35
+ console.log(warnings.join('\n\n'));
36
+ // eslint-disable-next-line no-console
37
+ console.log(
38
+ `\nSearch for the ${chalk.underline(
39
+ chalk.yellow('keywords')
40
+ )} to learn more about each warning.`
41
+ );
42
+ // eslint-disable-next-line no-console
43
+ console.log(
44
+ `To ignore, add ${chalk.cyan('// eslint-disable-next-line')} to the line before.\n`
45
+ );
46
+ } else {
47
+ // eslint-disable-next-line no-console
48
+ console.log(chalk.green('Compiled successfully.\n'));
49
+ }
50
+ },
51
+ err => {
52
+ // eslint-disable-next-line no-console
53
+ console.log(chalk.red('Failed to compile.\n'));
54
+ // eslint-disable-next-line no-console
55
+ console.log(err);
56
+ process.exit(1);
57
+ }
58
+ )
59
+ .catch(err => {
60
+ // eslint-disable-next-line no-console
61
+ console.log(chalk.red('Failed to compile.\n'));
62
+ // eslint-disable-next-line no-console
63
+ console.log(err);
64
+ process.exit(1);
65
+ });
@@ -1,4 +1,4 @@
1
- const webpackFactory = require('./webpack.dev');
2
- const openStartRun = require('../common/start');
3
-
4
- openStartRun(webpackFactory);
1
+ const webpackFactory = require('./webpack.dev');
2
+ const openStartRun = require('../common/start');
3
+
4
+ openStartRun(webpackFactory);
@@ -1,28 +1,28 @@
1
- const merge = require('webpack-merge');
2
- const MiniCssExtractPlugin = require('mini-css-extract-plugin');
3
- const HtmlWebpackPlugin = require('html-webpack-plugin');
4
- const { getProjectPath } = require('../common/utils');
5
- const webpackCommon = require('../common/webpack.common');
6
-
7
- module.exports = (isProd, appConfig, extendEnv) => {
8
- const result = {
9
- plugins: [
10
- new HtmlWebpackPlugin({
11
- inject: true,
12
- template: getProjectPath(appConfig.htmlPluginTemplate)
13
- })
14
- ]
15
- };
16
-
17
- if (isProd) {
18
- result.plugins.push(
19
- new MiniCssExtractPlugin({
20
- filename: `css/[name].css?v=${extendEnv.version}`,
21
- allChunks: true,
22
- ignoreOrder: true
23
- })
24
- );
25
- }
26
-
27
- return merge(webpackCommon(appConfig, extendEnv, { isProd, isServer: false }), result);
28
- };
1
+ const merge = require('webpack-merge');
2
+ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
3
+ const HtmlWebpackPlugin = require('html-webpack-plugin');
4
+ const { getProjectPath } = require('../common/utils');
5
+ const webpackCommon = require('../common/webpack.common');
6
+
7
+ module.exports = (isProd, appConfig, extendEnv) => {
8
+ const result = {
9
+ plugins: [
10
+ new HtmlWebpackPlugin({
11
+ inject: true,
12
+ template: getProjectPath(appConfig.htmlPluginTemplate)
13
+ })
14
+ ]
15
+ };
16
+
17
+ if (isProd) {
18
+ result.plugins.push(
19
+ new MiniCssExtractPlugin({
20
+ filename: `css/[name].css?v=${extendEnv.version}`,
21
+ allChunks: true,
22
+ ignoreOrder: true
23
+ })
24
+ );
25
+ }
26
+
27
+ return merge(webpackCommon(appConfig, extendEnv, { isProd, isServer: false }), result);
28
+ };