wewechat++ init

仓库提交至星火社区作品集

Signed-off-by: Riceneeder <86492950+Riceneeder@users.noreply.github.com>
This commit is contained in:
Riceneeder
2022-09-01 20:38:13 +08:00
commit 58ce6cb67b
165 changed files with 58249 additions and 0 deletions

15
config/index.js Normal file
View File

@@ -0,0 +1,15 @@
import path from 'path';
const config = {
server: {
port: process.env.PORT || 3000,
host: 'localhost'
},
client: path.resolve(__dirname, '../src'),
assets: path.resolve(__dirname, '../src/assets'),
dist: path.resolve(__dirname, '../dist'),
};
export default config;

View File

@@ -0,0 +1,113 @@
import path from 'path';
import config from './index';
export default {
module: {
rules: [
{
test: /\.jsx?$/,
loader: ['babel-loader', 'eslint-loader'],
exclude: /node_modules/,
},
{
test: /\.css$/,
exclude: [/icomoon\/style.css$/, /icomoon\\style.css$/, /global.css$/],
use: [
'style-loader',
{
loader: 'css-loader',
options: {
// Note that weve set importLoaders: 1 on css-loader.
// Were setting this because we want PostCSS to git @import statements first
modules: true,
importLoaders: 1,
localIdentName: '[path][name]__[local]--[hash:base64:5]'
},
},
{
loader: 'postcss-loader',
options: {
plugins: (loader) => [
require('postcss-import')(),
require('postcss-cssnext')({
browsers: [
'last 2 Chrome versions',
'last 2 Edge versions',
'last 2 Safari versions',
'last 2 Firefox versions',
],
}),
]
}
}
],
},
{
test: /icomoon(\/|\\)style.css$/,
use: [
'style-loader',
'css-loader',
],
},
{
test: /global.css$/,
use: [
'style-loader',
'css-loader',
],
},
{
test: /\.html/,
loader: 'html-loader',
},
{
test: /\.woff(\?.*)?$/,
loader: 'url-loader?prefix=fonts/&name=[path][name].[ext]&limit=40000&mimetype=application/font-woff',
},
{
test: /\.woff2(\?.*)?$/,
loader: 'url-loader?prefix=fonts/&name=[path][name].[ext]&limit=40000&mimetype=application/font-woff2',
},
{
test: /\.otf(\?.*)?$/,
loader: 'url-loader?prefix=fonts/&name=[path][name].[ext]&limit=40000&mimetype=font/opentype',
},
{
test: /\.ttf(\?.*)?$/,
loader: 'url-loader?prefix=fonts/&name=[path][name].[ext]&limit=40000&mimetype=application/octet-stream',
},
{
test: /\.svg(\?.*)?$/,
loader: 'url-loader?prefix=fonts/&name=[path][name].[ext]&limit=40000&mimetype=image/svg+xml',
},
{
test: /\.eot(\?.*)?$/,
loader: 'url-loader?prefix=fonts/&name=[path][name].[ext]&limit=40000',
},
{
test: /\.(png|jpg|jpeg|gif)$/,
loader: 'url-loader'
},
]
},
output: {
path: config.dist,
filename: 'bundle.js',
// https://github.com/webpack/webpack/issues/1114
libraryTarget: 'commonjs2'
},
resolve: {
extensions: ['.js', '.jsx', '.json'],
alias: {
components: path.join(config.client, 'js/components/'),
utils: path.join(config.client, 'js/utils/'),
images: path.join(config.client, 'assets/images/'),
fonts: path.join(config.client, 'assets/fonts/'),
},
},
};

View File

@@ -0,0 +1,37 @@
import webpack from 'webpack';
import config from './index';
import baseConfig from './webpack.config.base';
const { host, port } = config.server;
export default {
...baseConfig,
mode: 'development',
devtool: 'cheap-module-eval-source-map',
entry: [
`webpack-hot-middleware/client?path=http://${host}:${port}/__webpack_hmr`,
'babel-polyfill',
`${config.client}/app.js`,
],
output: {
...baseConfig.output,
publicPath: `http://${host}:${port}/dist/`,
},
plugins: [
// “If you are using the CLI, the webpack process will not exit with an error code by enabling this plugin.”
// https://github.com/webpack/docs/wiki/list-of-plugins#noerrorsplugin
new webpack.NoEmitOnErrorsPlugin(),
// https://webpack.github.io/docs/hot-module-replacement-with-webpack.html
new webpack.HotModuleReplacementPlugin(),
],
// https://github.com/chentsulin/webpack-target-electron-renderer#how-this-module-works
target: 'electron-renderer'
};

View File

@@ -0,0 +1,40 @@
import MinifyPlugin from 'babel-minify-webpack-plugin';
import config from './index';
import baseConfig from './webpack.config.base';
export default {
...baseConfig,
mode: 'production',
devtool: false,
entry: [
'babel-polyfill',
`./main.js`,
],
output: {
path: config.dist,
filename: 'main.js'
},
plugins: [
// Minify the output
new MinifyPlugin(),
],
// https://github.com/chentsulin/webpack-target-electron-renderer#how-this-module-works
target: 'electron-main',
/**
* Disables webpack processing of __dirname and __filename.
* If you run the bundle in node.js it falls back to these values of node.js.
* https://github.com/webpack/webpack/issues/2010
*/
node: {
__dirname: false,
__filename: false
}
};

View File

@@ -0,0 +1,64 @@
import path from 'path';
import webpack from 'webpack';
import MinifyPlugin from 'babel-minify-webpack-plugin';
import config from './index';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import baseConfig from './webpack.config.base';
export default {
...baseConfig,
mode: 'production',
devtool: false,
entry: [
'babel-polyfill',
`${config.client}/app.js`,
],
output: {
path: config.dist,
filename: 'app.[hash].js'
},
plugins: [
// https://github.com/webpack/webpack/issues/2545
// Use babel-minify-webpack-plugin minify code
new MinifyPlugin(),
// https://webpack.github.io/docs/list-of-plugins.html#occurrenceorderplugin
// https://github.com/webpack/webpack/issues/864
new webpack.optimize.OccurrenceOrderPlugin(),
new CopyWebpackPlugin([
{
from: `${config.assets}/fonts/**/*`,
to: `${config.dist}/src`,
},
{
from: `${config.assets}/images/**/*`,
to: config.dist,
},
{
from: path.resolve(__dirname, '../package.json'),
to: config.dist,
},
]),
new HtmlWebpackPlugin({
filename: `${config.dist}/src/index.html`,
template: './src/index.html',
inject: 'body',
hash: true,
minify: {
collapseWhitespace: true
}
})
],
// https://github.com/chentsulin/webpack-target-electron-renderer#how-this-module-works
target: 'electron-renderer'
};