Skip to content

Commit

Permalink
Update from sfc template (#124)
Browse files Browse the repository at this point in the history
* Revert package update from 527e734

* Update from sfc template

---------

Co-authored-by: janniks <janniks@users.noreply.github.com>
  • Loading branch information
janniks and janniks committed Feb 19, 2023
1 parent b96cf12 commit 5208332
Show file tree
Hide file tree
Showing 8 changed files with 12,890 additions and 27,706 deletions.
17 changes: 14 additions & 3 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
const devPresets = ['@vue/babel-preset-app'];
const buildPresets = ['@babel/preset-env'];
const devPresets = ["@vue/babel-preset-app"];
const buildPresets = [
[
"@babel/preset-env",
// Config for @babel/preset-env
{
// Example: Always transpile optional chaining/nullish coalescing
// include: [
// /(optional-chaining|nullish-coalescing)/
// ],
},
],
];
module.exports = {
presets: (process.env.NODE_ENV === 'development' ? devPresets : buildPresets),
presets: process.env.NODE_ENV === "development" ? devPresets : buildPresets,
};
73 changes: 31 additions & 42 deletions build/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import path from "path";
import vue from "rollup-plugin-vue";
import alias from "@rollup/plugin-alias";
import commonjs from "@rollup/plugin-commonjs";
import resolve from "@rollup/plugin-node-resolve";
import replace from "@rollup/plugin-replace";
import babel from "rollup-plugin-babel";
import postcss from "rollup-plugin-postcss";
import babel from "@rollup/plugin-babel";
import { terser } from "rollup-plugin-terser";
import postcssLogical from "postcss-logical";
import minimist from "minimist";

// Get browserslist config and remove ie from es build targets
Expand All @@ -18,6 +17,11 @@ const esbrowserslist = fs
.split("\n")
.filter((entry) => entry && entry.substring(0, 2) !== "ie");

// Extract babel preset-env config, to combine with esbrowserslist
const babelPresetEnvConfig = require("../babel.config").presets.filter(
(entry) => entry[0] === "@babel/preset-env"
)[0][1];

const argv = minimist(process.argv.slice(2));

const projectRoot = path.resolve(__dirname, "..");
Expand All @@ -27,25 +31,35 @@ const baseConfig = {
plugins: {
preVue: [
alias({
resolve: [".js", ".jsx", ".ts", ".tsx", ".vue"],
entries: {
"@": path.resolve(projectRoot, "src"),
},
entries: [
{
find: "@",
replacement: `${path.resolve(projectRoot, "src")}`,
},
],
}),
],
replace: {
preventAssignment: true,
"process.env.NODE_ENV": JSON.stringify("production"),
"process.env.ES_BUILD": JSON.stringify("false"),
"process.env.ES_BUILD": JSON.stringify("true"),
},
vue: {
css: true,
template: {
isProduction: true,
},
},
postVue: [
resolve({
extensions: [".js", ".jsx", ".ts", ".tsx", ".vue"],
}),
commonjs(),
],
babel: {
exclude: "node_modules/**",
extensions: [".js", ".jsx", ".ts", ".tsx", ".vue"],
babelHelpers: "bundled",
},
},
};
Expand Down Expand Up @@ -74,28 +88,26 @@ if (!argv.format || argv.format === "es") {
external,
output: {
file: "dist/esm.js",
format: "es",
format: "esm",
exports: "named",
},
plugins: [
replace({
...baseConfig.plugins.replace,
"process.env.ES_BUILD": JSON.stringify("true"),
}),
replace(baseConfig.plugins.replace),
...baseConfig.plugins.preVue,
vue(baseConfig.plugins.vue),
...baseConfig.plugins.postVue,
babel({
...baseConfig.plugins.babel,
presets: [
[
"@babel/preset-env",
{
...babelPresetEnvConfig,
targets: esbrowserslist,
},
],
],
}),
commonjs(),
],
};
buildFormats.push(esConfig);
Expand All @@ -110,7 +122,7 @@ if (!argv.format || argv.format === "cjs") {
file: "dist/ssr.js",
format: "cjs",
name: "VueNotion",
exports: "named",
exports: "auto",
globals,
},
plugins: [
Expand All @@ -123,8 +135,8 @@ if (!argv.format || argv.format === "cjs") {
optimizeSSR: true,
},
}),
...baseConfig.plugins.postVue,
babel(baseConfig.plugins.babel),
commonjs(),
],
};
buildFormats.push(umdConfig);
Expand All @@ -138,16 +150,16 @@ if (!argv.format || argv.format === "iife") {
compact: true,
file: "dist/min.js",
format: "iife",
name: "VueNotion",
name: "VuteNotion",
exports: "named",
globals,
},
plugins: [
replace(baseConfig.plugins.replace),
...baseConfig.plugins.preVue,
vue(baseConfig.plugins.vue),
...baseConfig.plugins.postVue,
babel(baseConfig.plugins.babel),
commonjs(),
terser({
output: {
ecma: 5,
Expand All @@ -158,28 +170,5 @@ if (!argv.format || argv.format === "iife") {
buildFormats.push(unpkgConfig);
}

if (!argv.format || argv.format === "postcss") {
const postCssConfig = {
input: "build/postcss.js",
output: {
format: "es",
file: "dist/styles.ignore",
},
plugins: [
postcss({
extract: true,
minimize: true,
plugins: [postcssLogical()],
}),
],
};
buildFormats.push(postCssConfig);
}

// Export config
export default (commandLineArgs) => {
// Exporting a method enables command line args override
// https://rollupjs.org/guide/en/#configuration-files
delete commandLineArgs.format;
return buildFormats;
};
export default buildFormats;
Loading

1 comment on commit 5208332

@vercel
Copy link

@vercel vercel bot commented on 5208332 Feb 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.