-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
2,040 additions
and
2,295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const path = require('path'); | ||
const { genTranspileDepRegex } = require("./util"); | ||
|
||
exports.foldPath = path.resolve(__dirname, `..`); | ||
exports.input = path.resolve(exports.foldPath, "src/index.js"); | ||
|
||
exports.output = { | ||
path: path.resolve(exports.foldPath, './dist') | ||
} | ||
|
||
// 别名 | ||
exports.alias = {}; | ||
|
||
exports.vue = { | ||
root: 'Vue', | ||
commonjs: 'vue', | ||
commonjs2: 'vue', | ||
amd: 'vue' | ||
}; | ||
|
||
exports.jsexclude = function (filepath){ | ||
const transpileDependencies = []; | ||
const transpileDepRegex = genTranspileDepRegex(transpileDependencies); | ||
|
||
// always transpile js in vue files | ||
if (/\.vue\.jsx?$/.test(filepath)) { | ||
return false | ||
} | ||
|
||
// only include @babel/runtime when the @vue/babel-preset-app preset is used | ||
if ( | ||
process.env.VUE_CLI_TRANSPILE_BABEL_RUNTIME && | ||
filepath.includes(path.join('@babel', 'runtime')) | ||
) { | ||
return false | ||
} | ||
|
||
// check if this is something the user explicitly wants to transpile | ||
if (transpileDepRegex && transpileDepRegex.test(filepath)) { | ||
return false | ||
} | ||
// Don't transpile node_modules | ||
return /node_modules/.test(filepath) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const path = require("path"); | ||
|
||
exports.isWindows = process.platform === 'win32'; | ||
|
||
function genTranspileDepRegex (transpileDependencies) { | ||
const deps = transpileDependencies.map(dep => { | ||
if (typeof dep === 'string') { | ||
const depPath = path.join('node_modules', dep, '/') | ||
return exports.isWindows | ||
? depPath.replace(/\\/g, '\\\\') // double escape for windows style path | ||
: depPath | ||
} else if (dep instanceof RegExp) { | ||
return dep.source | ||
} | ||
}) | ||
return deps.length ? new RegExp(deps.join('|')) : null | ||
} | ||
|
||
exports.genTranspileDepRegex = genTranspileDepRegex; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
const path = require('path'); | ||
const { VueLoaderPlugin } = require('vue-loader'); | ||
const TerserPlugin = require('terser-webpack-plugin'); | ||
const config = require('./config'); | ||
const pkg = require('../package.json'); | ||
|
||
const arguments = process.argv.splice(2); | ||
const isDebug = arguments.includes('debug'); | ||
|
||
module.exports = { | ||
mode: 'production', | ||
entry: { | ||
[pkg.name]: config.input | ||
}, | ||
output: { | ||
filename: '[name].min.js', | ||
chunkFilename: '[id].js', | ||
libraryTarget: 'umd', | ||
globalObject: 'typeof self !== \'undefined\' ? self : this', | ||
...config.output | ||
}, | ||
devtool: 'source-map', | ||
resolve: { | ||
extensions: ['.js', '.vue', '.json'], | ||
alias: config.alias | ||
}, | ||
externals: { | ||
vue: config.vue | ||
}, | ||
optimization: isDebug ? { | ||
minimize: false, | ||
} : { | ||
minimizer: [ | ||
new TerserPlugin({ | ||
extractComments: false, | ||
}), | ||
], | ||
}, | ||
performance: { | ||
hints: false | ||
}, | ||
stats: { | ||
children: false | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.(jsx?|babel|es6)$/, | ||
include: process.cwd(), | ||
exclude: config.jsexclude, | ||
loader: 'babel-loader' | ||
}, | ||
{ | ||
test: /\.vue$/, | ||
loader: 'vue-loader', | ||
options: { | ||
compilerOptions: { | ||
preserveWhitespace: false | ||
} | ||
} | ||
}, | ||
] | ||
}, | ||
plugins: [ | ||
new VueLoaderPlugin() | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
"use strict"; | ||
|
||
const ora = require("ora"); | ||
const rm = require("rimraf"); | ||
const path = require("path"); | ||
const chalk = require("chalk"); | ||
const webpack = require("webpack"); | ||
const webpackConfig = require("./webpack.config.js"); | ||
const merge = require("webpack-merge"); | ||
const config = require("./config"); | ||
|
||
let isModern = false; | ||
let isOnly = false; | ||
|
||
process.argv.forEach(item => { | ||
if (item.includes("modern")) { | ||
isModern = true; | ||
} | ||
|
||
if (item.includes("only")) { | ||
isOnly = true; | ||
} | ||
}); | ||
|
||
let spinner; | ||
|
||
function logStart(str = "") { | ||
spinner = ora(`Building ${str}bundle for production...`); | ||
|
||
spinner.start(); | ||
} | ||
|
||
function build(webpackConfig, str) { | ||
return new Promise(function (resolve, reject) { | ||
logStart(str); | ||
|
||
webpack(webpackConfig, function (err, stats) { | ||
spinner.stop(); | ||
if (err) { | ||
process.exit(1); | ||
|
||
throw err; | ||
} | ||
|
||
if (stats.hasErrors()) { | ||
console.log(stats.toString({ | ||
colors: true | ||
})); | ||
|
||
console.log(chalk.red("\nBuild failed with errors.\n")); | ||
|
||
process.exit(1); | ||
} | ||
|
||
resolve(); | ||
}); | ||
}); | ||
} | ||
|
||
(async function () { | ||
rm( | ||
config.output.path, | ||
async err => { | ||
if (err) { | ||
spinner.stop(); | ||
|
||
process.exit(1); | ||
throw err; | ||
} | ||
let startTime = Date.now(); | ||
|
||
await build(webpackConfig); | ||
|
||
console.log( | ||
chalk.green("Build complete in " + (Date.now() - startTime) + "ms.\n") | ||
); | ||
} | ||
); | ||
})(); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.