Commit 56935e91 by 黑潮

update: cli

parent e3cba484
......@@ -14,28 +14,28 @@ const webpackConfig = require('./webpack.prod.conf')
const spinner = ora('building for production...')
spinner.start()
rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
// rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
// if (err) throw err
webpack(webpackConfig, (err, stats) => {
spinner.stop()
if (err) throw err
webpack(webpackConfig, (err, stats) => {
spinner.stop()
if (err) throw err
process.stdout.write(stats.toString({
colors: true,
modules: false,
children: false, // If you are using ts-loader, setting this to true will make TypeScript errors show up during build.
chunks: false,
chunkModules: false
}) + '\n\n')
process.stdout.write(stats.toString({
colors: true,
modules: false,
children: false, // If you are using ts-loader, setting this to true will make TypeScript errors show up during build.
chunks: false,
chunkModules: false
}) + '\n\n')
if (stats.hasErrors()) {
console.log(chalk.red(' Build failed with errors.\n'))
process.exit(1)
}
if (stats.hasErrors()) {
console.log(chalk.red(' Build failed with errors.\n'))
process.exit(1)
}
console.log(chalk.cyan(' Build complete.\n'))
console.log(chalk.yellow(
' Tip: built files are meant to be served over an HTTP server.\n' +
' Opening index.html over file:// won\'t work.\n'
))
})
console.log(chalk.cyan(' Build complete.\n'))
console.log(chalk.yellow(
' Tip: built files are meant to be served over an HTTP server.\n' +
' Opening index.html over file:// won\'t work.\n'
))
})
// })
'use strict';
const path = require('path');
module.exports = {
ouputDir: path.resolve(__dirname, '../dist'),
publicPath: '/marketing',
gzip: false,
devServerProxy: {
'/api-.*/': {
target: 'http://gicdev.demogic.com',
changeOrigin: true,
},
'/api-marketing/': {
target: 'http://gicdev.demogic.com',
changeOrigin: true,
}
}
}
/*
* @Author: luojie
* @Description:
* @Date: 2021-11-12 13:46:11
* @LastEditors: luojie
* @LastEditTime: 2021-11-12 13:46:12
* @FilePath: \marketing\build\dev-server.js
*/
'use strict';
const path = require('path');
const config = require('../config');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const packageConfig = require('../package.json');
exports.assetsPath = function(_path) {
const assetsSubDirectory = process.env.NODE_ENV === 'production' ? config.build.assetsSubDirectory : config.dev.assetsSubDirectory;
return path.posix.join(assetsSubDirectory, _path);
return path.posix.join('/static', _path);
};
exports.cssLoaders = function(options) {
options = options || {};
const cssLoaders = function() {
const sourceMap = process.env.NODE_ENV = 'production' ? false : true
const cssLoader = {
loader: 'css-loader',
options: {
sourceMap: options.sourceMap
sourceMap
}
};
const postcssLoader = {
loader: 'postcss-loader',
options: {
sourceMap: options.sourceMap
sourceMap
}
};
// generate loader string to be used with extract text plugin
function generateLoaders(loader, loaderOptions) {
const loaders = options.usePostCSS ? [cssLoader, postcssLoader] : [cssLoader];
const loaders = [cssLoader, postcssLoader]
if (loader) {
loaders.push({
loader: loader + '-loader',
options: Object.assign({}, loaderOptions, {
sourceMap: options.sourceMap
sourceMap
})
});
}
// Extract CSS when that option is specified
// (which is the case during production build)
if (options.extract) {
return ExtractTextPlugin.extract({
use: loaders,
// publicPath: '../../', //注意: 此处根据路径, 自动更改 解决css background img 找不到文件
fallback: 'vue-style-loader'
});
} else {
return ['vue-style-loader'].concat(loaders);
}
return [process.env.NODE_ENV === 'production' ? MiniCssExtractPlugin.loader : 'style-loader'].concat(loaders)
}
// https://vue-loader.vuejs.org/en/configurations/extract-css.html
return {
css: generateLoaders(),
postcss: generateLoaders(),
less: generateLoaders('less'),
sass: generateLoaders('sass', { indentedSyntax: true }),
sass: generateLoaders('sass', { sassOptions: { indentedSyntax: true } }),
scss: generateLoaders('sass'),
stylus: generateLoaders('stylus'),
styl: generateLoaders('stylus')
};
};
// Generate loaders for standalone style files (outside of .vue)
exports.styleLoaders = function(options) {
exports.styleLoaders = function() {
const output = [];
const loaders = exports.cssLoaders(options);
const loaders = cssLoaders();
for (const extension in loaders) {
const loader = loaders[extension];
......
'use strict';
const path = require('path');
const utils = require('./utils');
const config = require('../config');
const vueLoaderConfig = require('./vue-loader.conf');
const { VueLoaderPlugin } = require('vue-loader');
const ESLintPlugin = require('eslint-webpack-plugin');
const utils = require('./utils');
function resolve(dir) {
return path.join(__dirname, '..', dir);
}
const createLintingRule = () => ({
test: /\.(js|vue)$/,
loader: 'eslint-loader',
enforce: 'pre',
include: [resolve('src'), resolve('test')],
options: {
// fix: true,
formatter: require('eslint-friendly-formatter'),
emitWarning: !config.dev.showEslintErrorsInOverlay
}
});
module.exports = {
context: path.resolve(__dirname, '../'),
entry: ['babel-polyfill', './src/main.js'],
output: {
path: config.build.assetsRoot,
filename: '[name].js',
chunkFilename: utils.assetsPath('js/[id].[chunkhash].js'),
publicPath: process.env.NODE_ENV === 'production' ? config.build.assetsPublicPath : config.dev.assetsPublicPath
},
entry: ['./src/main.js'],
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
vue$: 'vue/dist/vue.esm.js',
'@': resolve('src')
'@': resolve('src'),
}
},
module: {
rules: [
...(config.dev.useEslint ? [createLintingRule()] : []),
{
test: /\.vue$/,
loader: 'vue-loader',
options: vueLoaderConfig
},
{
test: /\.(css|scss)$/,
loader: 'style!css!sass',
include: [resolve('src')]
loader: 'vue-loader'
},
{
test: /\.js$/,
loader: 'babel-loader',
include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
include: [resolve('src')]
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('img/[name].[hash:7].[ext]')
type: 'asset',
generator: {
filename: 'img/[name].[hash:7].[ext]'
},
dataUrlCondition: {
maxSize: 10000,
}
},
{
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('media/[name].[hash:7].[ext]')
type: 'asset',
generator: {
filename: 'media/[name].[hash:7].[ext]'
},
dataUrlCondition: {
maxSize: 10000,
}
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
type: 'asset',
generator: {
filename: 'fonts/[name].[hash:7].[ext]'
},
dataUrlCondition: {
maxSize: 10000,
}
}
},
...utils.styleLoaders(),
]
},
plugins: [
new VueLoaderPlugin(),
new ESLintPlugin({
extensions: ['js', 'vue'],
files: 'src',
fix: 'true'
}),
new HtmlWebpackPlugin({
template: 'index.html',
})
],
externals: {
vue: 'Vue',
'vue-router': 'VueRouter',
......@@ -87,16 +81,4 @@ module.exports = {
'axios': 'axios',
'element-ui': 'ELEMENT'
},
node: {
// prevent webpack from injecting useless setImmediate polyfill because Vue
// source contains it (although only uses it if it's native).
setImmediate: false,
// prevent webpack from injecting mocks to Node native modules
// that does not make sense for the client
dgram: 'empty',
fs: 'empty',
net: 'empty',
tls: 'empty',
child_process: 'empty'
}
};
'use strict';
const utils = require('./utils');
const webpack = require('webpack');
const config = require('../config');
const merge = require('webpack-merge');
const path = require('path');
const baseWebpackConfig = require('./webpack.base.conf');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
const FriendlyErrorsPlugin = require('@soda/friendly-errors-webpack-plugin');
const portfinder = require('portfinder');
const HOST = process.env.HOST;
const PORT = process.env.PORT && Number(process.env.PORT);
const PORT = '8080'
const devWebpackConfig = merge(baseWebpackConfig, {
module: {
rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap, usePostCSS: true })
},
// cheap-module-eval-source-map is faster for development
devtool: config.dev.devtool,
mode: 'development',
devtool: 'eval-source-map',
// these devServer options should be customized in /config/index.js
devServer: {
clientLogLevel: 'warning',
client: {
logging: 'warning',
overlay: true,
progress: true,
},
static: {
directory: path.join(__dirname, '../static'),
},
historyApiFallback: {
rewrites: [{ from: /.*/, to: path.posix.join(config.dev.assetsPublicPath, 'index.html') }]
},
hot: true,
contentBase: false, // since we use CopyWebpackPlugin.
compress: true,
host: HOST || config.dev.host,
port: PORT || config.dev.port,
open: config.dev.autoOpenBrowser,
overlay: config.dev.errorOverlay ? { warnings: false, errors: true } : false,
publicPath: config.dev.assetsPublicPath,
proxy: config.dev.proxyTable,
quiet: true, // necessary for FriendlyErrorsPlugin
watchOptions: {
poll: config.dev.poll
host: 'localhost',
port: PORT,
open: true,
proxy: config.devServerProxy,
watchFiles: {
options: {
usePolling: false,
},
}
},
plugins: [
new webpack.DefinePlugin({
'process.env': require('../config/dev.env')
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update.
new webpack.NoEmitOnErrorsPlugin(),
// new webpack.HotModuleReplacementPlugin(),
// https://github.com/ampedandwired/html-webpack-plugin
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.html',
inject: true
}),
// copy custom static assets
new CopyWebpackPlugin([
{
from: path.resolve(__dirname, '../static'),
to: config.dev.assetsSubDirectory,
ignore: ['.*']
}
])
]
});
module.exports = new Promise((resolve, reject) => {
portfinder.basePort = process.env.PORT || config.dev.port;
portfinder.basePort = PORT;
portfinder.getPort((err, port) => {
if (err) {
reject(err);
} else {
// publish the new Port, necessary for e2e tests
process.env.PORT = port;
// add port to devServer config
devWebpackConfig.devServer.port = port;
......
......@@ -6,128 +6,52 @@ const config = require('../config');
const merge = require('webpack-merge');
const baseWebpackConfig = require('./webpack.base.conf');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const env = require('../config/prod.env');
const webpackConfig = merge(baseWebpackConfig, {
module: {
rules: utils.styleLoaders({
sourceMap: config.build.productionSourceMap,
extract: true,
usePostCSS: true
})
},
devtool: config.build.productionSourceMap ? config.build.devtool : false,
mode: 'production',
devtool: false,
output: {
path: config.build.assetsRoot,
path: config.ouputDir,
filename: utils.assetsPath('js/[name].[chunkhash].js'),
chunkFilename: utils.assetsPath('js/[name].[chunkhash].js')
},
optimization: {
minimizer: [
`...`,
new CssMinimizerPlugin(),
],
},
plugins: [
// http://vuejs.github.io/vue-loader/en/workflow/production.html
new webpack.DefinePlugin({
'process.env': env
}),
new UglifyJsPlugin({
uglifyOptions: {
compress: {
// warnings: false
// drop_console: true // console
// pure_funcs: ['console.log'] // 移除console
}
},
sourceMap: config.build.productionSourceMap,
parallel: true
}),
// extract css into its own file
new ExtractTextPlugin({
new MiniCssExtractPlugin({
filename: utils.assetsPath('css/[name].[contenthash].css'),
// Setting the following option to `false` will not extract CSS from codesplit chunks.
// Their CSS will instead be inserted dynamically with style-loader when the codesplit chunk has been loaded by webpack.
// It's currently set to `true` because we are seeing that sourcemaps are included in the codesplit bundle as well when it's `false`,
// increasing file size: https://github.com/vuejs-templates/webpack/issues/1110
allChunks: true
}),
// Compress extracted CSS. We are using this plugin so that possible
// duplicated CSS from different components can be deduped.
new OptimizeCSSPlugin({
cssProcessorOptions: config.build.productionSourceMap ? { safe: true, map: { inline: false } } : { safe: true }
}),
// generate dist index.html with correct asset hash for caching.
// you can customize output by editing /index.html
// see https://github.com/ampedandwired/html-webpack-plugin
new HtmlWebpackPlugin({
filename: config.build.index,
template: 'index.html',
inject: true,
minify: {
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: true
// more options:
// https://github.com/kangax/html-minifier#options-quick-reference
},
// necessary to consistently work with multiple chunks via CommonsChunkPlugin
chunksSortMode: 'dependency'
}),
// keep module.id stable when vendor modules does not change
new webpack.HashedModuleIdsPlugin(),
// enable scope hoisting
new webpack.optimize.ModuleConcatenationPlugin(),
// split vendor js into its own file
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks(module) {
// any required modules inside node_modules are extracted to vendor
return module.resource && /\.js$/.test(module.resource) && module.resource.indexOf(path.join(__dirname, '../node_modules')) === 0;
}
}),
// extract webpack runtime and module manifest to its own file in order to
// prevent vendor hash from being updated whenever app bundle is updated
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest',
minChunks: Infinity
}),
// This instance extracts shared chunks from code splitted chunks and bundles them
// in a separate chunk, similar to the vendor chunk
// see: https://webpack.js.org/plugins/commons-chunk-plugin/#extra-async-commons-chunk
new webpack.optimize.CommonsChunkPlugin({
name: 'app',
async: 'vendor-async',
children: true,
minChunks: 3
}),
// copy custom static assets
new CopyWebpackPlugin([
{
from: path.resolve(__dirname, '../static'),
to: config.build.assetsSubDirectory,
to: config.outputDir,
ignore: ['.*']
}
])
]
});
if (config.build.productionGzip) {
if (config.productionGzip) {
const CompressionWebpackPlugin = require('compression-webpack-plugin');
webpackConfig.plugins.push(
new CompressionWebpackPlugin({
asset: '[path].gz[query]',
filename: '[path].gz[query]',
algorithm: 'gzip',
test: new RegExp('\\.(' + config.build.productionGzipExtensions.join('|') + ')$'),
test: new RegExp('\\.(' + ['js', 'css'].join('|') + ')$'),
threshold: 10240,
minRatio: 0.8
})
);
}
if (config.build.bundleAnalyzerReport) {
if (process.env.npm_config_report) {
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
webpackConfig.plugins.push(new BundleAnalyzerPlugin());
}
......
......@@ -33,68 +33,67 @@
"vue-ueditor-wrap": "^1.3.4",
"vue2-editor": "^2.5.0",
"vuedraggable": "^2.24.0",
"vue-lazyload": "^1.2.6",
"vuex": "^3.5.1"
},
"devDependencies": {
"ansi-html": "^0.0.7",
"autoprefixer": "^7.1.2",
"babel-cli": "^6.26.0",
"babel-core": "^6.22.1",
"babel-eslint": "^9.0.0",
"babel-helper-vue-jsx-merge-props": "^2.0.3",
"babel-loader": "^7.1.1",
"babel-plugin-syntax-jsx": "^6.18.0",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-plugin-transform-vue-jsx": "^3.5.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.3.2",
"babel-preset-flow": "^6.23.0",
"babel-preset-stage-2": "^6.22.0",
"chalk": "^2.0.1",
"copy-webpack-plugin": "^4.0.1",
"css-loader": "^0.28.0",
"element-theme-chalk": "^2.13.2",
"eslint": "^5.6.0",
"eslint-config-prettier": "^4.0.0",
"eslint-config-standard": "^12.0.0",
"eslint-friendly-formatter": "^4.0.1",
"eslint-loader": "^2.1.1",
"eslint-plugin-html": "^5.0.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-node": "^7.0.1",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"eslint-plugin-vue": "^4.7.1",
"extract-text-webpack-plugin": "^3.0.0",
"file-loader": "^1.1.4",
"friendly-errors-webpack-plugin": "^1.6.1",
"html-webpack-plugin": "^2.30.1",
"localforage": "^1.8.0",
"node-notifier": "^5.1.2",
"node-sass": "^4.14.1",
"onchange": "^5.2.0",
"optimize-css-assets-webpack-plugin": "^3.2.0",
"ora": "^1.2.0",
"autoprefixer": "10.4.0",
"@babel/core": "7.16.0",
"@babel/eslint-parser": "7.16.3",
"babel-loader": "8.2.3",
// "babel-plugin-syntax-jsx": "^6.18.0",
// "babel-plugin-transform-runtime": "^6.22.0",
// "babel-plugin-transform-vue-jsx": "^3.5.0",
// "babel-polyfill": "^6.26.0",
"@babel/preset-env": "7.16.0",
// "babel-preset-flow": "^6.23.0",
// "babel-preset-stage-2": "^6.22.0",
"chalk": "4.1.2",
"copy-webpack-plugin": "9.0.1",
"css-loader": "6.5.1",
"eslint": "8.2.0",
// "eslint-config-prettier": "^4.0.0",
// "eslint-config-standard": "^12.0.0",
// "eslint-friendly-formatter": "^4.0.1",
// "eslint-loader": "^2.1.1",
// "eslint-plugin-html": "^5.0.0",
// "eslint-plugin-import": "^2.22.0",
// "eslint-plugin-node": "^7.0.1",
// "eslint-plugin-prettier": "^3.1.4",
// "eslint-plugin-promise": "^4.0.1",
// "eslint-plugin-standard": "^4.0.0",
// "eslint-plugin-vue": "^4.7.1",
// "extract-text-webpack-plugin": "^3.0.0",
"css-minimizer-webpack-plugin": "3.1.3",
// "file-loader": "^1.1.4",
// "friendly-errors-webpack-plugin": "^1.6.1",
"@soda/friendly-errors-webpack-plugin": "^1.8.0",
"html-webpack-plugin": "5.5.0",
"mini-css-extract-plugin": "2.4.4",
"node-notifier": "10.0.0",
"sass": "1.43.4",
// "onchange": "^5.2.0",
// "optimize-css-assets-webpack-plugin": "^3.2.0",
"ora": "6.0.1",
"portfinder": "^1.0.27",
"postcss-import": "^11.0.0",
"postcss-loader": "^2.0.8",
"postcss-url": "^7.2.1",
"prettier": "^1.16.4",
"rimraf": "^2.6.0",
"sass-loader": "^7.0.3",
"semver": "^5.3.0",
"shelljs": "^0.7.6",
"uglifyjs-webpack-plugin": "^1.1.1",
"url-loader": "^0.5.8",
"vue-lazyload": "^1.2.6",
"vue-loader": "^13.3.0",
"vue-style-loader": "^3.0.1",
"vue-template-compiler": "^2.6.12",
"webpack": "^3.6.0",
"webpack-bundle-analyzer": "^2.9.0",
"webpack-dev-server": "^2.11.3",
"webpack-merge": "^4.1.0"
// "postcss-import": "^11.0.0",
"postcss": "8.3.11",
"postcss-loader": "6.2.0",
// "postcss-url": "^7.2.1",
// "prettier": "^1.16.4",
// "rimraf": "^2.6.0",
"sass-loader": "12.3.0",
"semver": "7.3.5",
"shelljs": "0.8.4",
"vue-loader": "15.9.8",
"style-loader": "3.3.1",
"vue-template-compiler": "^2.6.6",
"webpack": "5.56.0",
"webpack-bundle-analyzer": "4.5.0",
"webpack-cli":"4.9.1",
"webpack-dev-server": "^3.11.2",
"webpack-merge": "5.8.0"
},
"engines": {
"node": ">= 6.0.0",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment